Hello,
I tried change my castorbuilder.properties and generate complex
type, but without success.
There is no problem with the choice as such - it work (or even
generate code) fine. But what I exactly need is a SEQUENCE inside the
CHOICE statement. Look at this:
<xs:complexType name="T_CH">
<xs:choice>
<xs:element name="obsdigit" type="T_S"/>
<xs:sequence>
<xs:element name="lac" type="xs:string" />
<xs:element name="dn" type="xs:string" />
</xs:sequence>
</xs:choice>
</xs:complexType>
Value can be either obsdigit or THE SEQUENCE of LAC and DN. (for closer
look it's about phone number: It could be specified by one number or by
the combination of LAC (local area code) and DN (directory number) -
using the combination both values have to be present!)
The code generated from such a schema will include methods *setObsdigit*
and (what is not wanted) *setT_CHSequence*.
_*It creates new element with the name **T_CHSequence!*_ It's the same
solution as if I created following schema:
<xs:complexType name="T_S">
<xs:sequence>
<xs:element name="lac" type="xs:string"/>
<xs:element name="dn" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="T_CH2">
<xs:choice>
<xs:element name="obsdigit" type="xs:string"/>
<xs:element name="lac_dn" type="T_S"/>
</xs:choice>
</xs:complexType>
The only difference is in the name of element; Using the second schema
the name will be *lac_dn *and the generated methods are *setLac_DN
(Lac_dn) * and the same getter.
I don't think it's a correct code. At least I would expected something
different.
regards, Stefan
Robert Ollila wrote:
>Stefan,
>
>I am using a choice just like yours and the source generator DID produce set
>and get methods for the choices. The only difference is that I defined a
>global complexType (not an element). I am also using the "type" method in
>my castor.properties.
>
>For choices I was also curious why no error checking code is supplied. For
>example, if I set the choice by calling setLac(), there is nothing from
>preventing me from also calling setDn() later, and therefore having two
>choices set. Maybe that is what the EntrObsCallChoice class is for? But
>I'm not sure why your code made that class and mine did not.
>
>Bob.
>
>-----Original Message-----
>From: Dobrovolny Stefan [mailto:[EMAIL PROTECTED]]
>Sent: Thursday, January 17, 2002 8:25 AM
>To: [EMAIL PROTECTED]
>Subject: [castor-dev] Generate the get/set methods for elements
>restricted in XML schema via xs:choice - xs: sequence construct.
>
>
>Hello,
>
> I have to write a validation framework for quite complex structure,
>and I decided to use XML-schema and Castor for it's undoubting beauty.
>
> However, the structure includes mutual exclusion of some elements
>and/or its combinations. I've tried to solve this problem using
>xs:chioce and xs:sequence constructs. For example:
>
> <xs:element name="EntrObsCall">
> <xs:complexType>
> <xs:sequence>
> <xs:choice>
> <xs:element name="obsdigit" type="T_OBSDIGIT"/>
> <xs:sequence>
> <xs:element name="lac" type="T_LAC"/>
> <xs:element name="dn" type="T_DN"/>
> </xs:sequence>
> </xs:choice>
> <xs:element name="obsgrp" type="T_OBSGRP"/>
> <xs:element name="intercom" type="YES_NO" minOccurs="0"/>
> ...
>
>Castor source generator generates classes, but the main class
>EntrObsCall doesn't contain method like setDn or setLac. Instead of that
>it contains classes called EntrObsCallChoice, but this not suitable for
>me. I am reading data from some strange source and I need the data
>insert into this object (for example) using java reflection api.
>(Application should be as simple as possible - new data type <==> new
>schema, new generated class)
>
>Q1: Is there some way how to generate such a class from such an XMLschema?
>Q2: The second approach could be: I'll generate 2 schemas. First as
>complex as I described above and second one simpler "flat" schema (which
>should produce all needed setters). I'll the "flat" object with the data
>-> marshal it into String and then unmarshal into "complex" object and
>validate against the "complex" schema. Is it possible to do a simple
>marshalling into "complex" object (using Castor)? (Simple = call a
>framework method without need to create additional classes (because
>intent is to handle all changes and new forms of incoming data without
>need to write java code - just a new XML schema)
>
>Thank you in advance,
>
>Yours faithfully Stefan
>
>-----------------------------------------------------------
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
>-----------------------------------------------------------
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev