users@jaxb.java.net

Re: jaxb code generation issue

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Sun, 5 Oct 2008 19:45:27 +0200

If your tFromExtension (which I see now, at least in the generated
comment) is supposed to have both content and the sub-element
<literal>, then it must be a complexType/complexContent and have
mixed="true". . This means that you'll have to have mixed="true" on
the derived type tFrom as well. Also, if you derive from the schema
type anyType, you'll imply mixed content. And, as you have
experienced, JAXB somehow fails to unmarshal the elements in the
choice group. I think this is a bug in JAXB.

But do you really need the <from> element to have content? If you
remove the mixed="true" and declare

<complexType name="tFromExtension">
    <sequence>
       <element
ref="{http://www.zzzz.com/xmlns/xxxxx/xxxxxxxxxx/6.0.0/}literal"
minOccurs="0"/>
     </sequence>
</complexType>

Then, tFrom will have getters for query and the other choices.
-W

On Sat, Oct 4, 2008 at 10:15 PM, oxg1123 <oxg1123_at_yahoo.com> wrote:
>
> Thanks for a quick response. I've removed mixed=true and regenerated code. However during marshalling process I'm getting the following exception:
>
> Exception from Validator:
> Message is unexpected element (uri:"http://schemas.xmlsoap.org/ws/2004/03/business-process/", local:"query"). Expected elements are <{
> Column is 84 at line number 38
> Message is unexpected element (uri:"http://schemas.xmlsoap.org/ws/2004/03/business-process/", local:"query"). Expected elements are <{
> Column is 84 at line number 44
>
>
> Any ideas ?
>
>
> XML
> <bpwc:assign name="Initiallize" wpc:displayName="Initiallize" wpc:id="9">
> <bpwc:copy>
> <bpwc:from variable="service">
> <bpwc:query queryLanguage="http://www.w3.org/TR/1999/REC-xpath-19991116"><![CDATA[ServiceName]]></bpwc:query> <===================== line number 38
> </bpwc:from>
> <bpwc:to variable="serviceName"/>
> </bpwc:copy>
> <bpwc:copy>
> <bpwc:from variable="service">
> <bpwc:query queryLanguage="http://www.w3.org/TR/1999/REC-xpath-19991116"><![CDATA[PreStartUpCmds]]></bpwc:query> <==================== line number 44
> </bpwc:from>
>
>
>
>
>
> Marshalling code:
> JAXBContext jc = JAXBContext.newInstance(TProcess.class);
> Unmarshaller u = jc.createUnmarshaller();
> u.setEventHandler(new ValidationEventHandlerImpl());
>
> JAXBElement<?> bpelElement = (JAXBElement<?>)u.unmarshal(new File("/home/olegg/workspaces/bpelTranslation/jaxBpel.test/src/RepresentativeEF.bpel"));
> TProcess process = (TProcess)bpelElement.getValue();
> System.out.println(process.toString());
>
>
>
> Generated code:
>
> TFrom.java
>
> * <p>Java class for tFrom complex type.
> *
> * <p>The following schema fragment specifies the expected content contained within this class.
> *
> * <pre>
> * <complexType name="tFrom">
> * <complexContent>
> * <extension base="http://www.zzzz.com/xmlns/xxxxx/xxxxxxxxxx/6.0.0/}tFromExtension">
> * <sequence>
> * <any/>
> * <choice minOccurs="0">
> * <element ref="{http://schemas.xmlsoap.org/ws/2004/03/business-process/}query"/>
> * <element ref="{http://schemas.xmlsoap.org/ws/2004/03/business-process/}expression"/>
> * <element ref="{http://schemas.xmlsoap.org/ws/2004/03/business-process/}service-ref"/>
> * </choice>
> * </sequence>
> * <attribute name="variable" type="{http://www.w3.org/2001/XMLSchema}NCName" />
> * <attribute name="part" type="{http://www.w3.org/2001/XMLSchema}NCName" />
> * <attribute name="property" type="{http://www.w3.org/2001/XMLSchema}QName" />
> * <attribute name="partnerLink" type="{http://www.w3.org/2001/XMLSchema}NCName" />
> * <attribute name="endpointReference" type="{http://schemas.xmlsoap.org/ws/2004/03/business-process/}tRoles" />
> * <attribute name="opaque" type="{http://schemas.xmlsoap.org/ws/2004/03/business-process/}tBoolean" />
> * </extension>
> * </complexContent>
> * </complexType>
> * </pre>
> *
> *
> */
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "tFrom")
> public class TFrom
> extends TFromExtension
> {
>
> @XmlAttribute
> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
> @XmlSchemaType(name = "NCName")
> protected String variable;
> @XmlAttribute
> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
> @XmlSchemaType(name = "NCName")
> protected String part;
> @XmlAttribute
> protected QName property;
> @XmlAttribute
> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
> @XmlSchemaType(name = "NCName")
> protected String partnerLink;
> @XmlAttribute
> protected TRoles endpointReference;
> @XmlAttribute
> protected TBoolean opaque;
>
> /**
> * Gets the value of the variable property.
> *
> * @return
> * possible object is
> * {_at_link String }
> *
> */
> public String getVariable() {
> return variable;
> }
>
> /**
> * Sets the value of the variable property.
> *
> * @param value
> * allowed object is
> * {_at_link String }
> *
> */
> public void setVariable(String value) {
> this.variable = value;
> }
>
>
>
>
>
> TFromExtension.java
>
> * <pre>
> * <complexType name="tFromExtension">
> * <complexContent>
> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
> * <sequence>
> * <element ref="{http://www.zzzz.com/xmlns/xxxxx/xxxxxxxxxx/6.0.0/}literal" minOccurs="0"/>
> * </sequence>
> * </restriction>
> * </complexContent>
> * </complexType>
> * </pre>
> *
> *
> */
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "tFromExtension", propOrder = {
> "content"
> })
> @XmlSeeAlso({
> TFrom.class
> })
> public class TFromExtension {
>
> @XmlElementRef(name = "literal", namespace = "http://www.zzzz.com/xmlns/xxxxx/xxxxxxxxxx/6.0.0/", type = JAXBElement.class)
> @XmlMixed
> protected List<Serializable> content;
>
> /**
> *
> * BPEL Extensions extension base type for BPEL complexType tFrom.
> * Gets the value of the content property.
> *
> * <p>
> * This accessor method returns a reference to the live list,
> * not a snapshot. Therefore any modification you make to the
> * returned list will be present inside the JAXB object.
> * This is why there is not a <CODE>set</CODE> method for the content property.
> *
> * <p>
> * For example, to add a new item, do as follows:
> * <pre>
> * getContent().add(newItem);
> * </pre>
> *
> *
> * <p>
> * Objects of the following type(s) are allowed in the list
> * {_at_link String }
> * {_at_link JAXBElement }{_at_code <}{_at_link TLiteral }{_at_code >}
> *
> *
> */
> public List<Serializable> getContent() {
> if (content == null) {
> content = new ArrayList<Serializable>();
> }
> return this.content;
> }
>
>
>
> Thanks a lot
>
>
>
>
> ----- Original Message ----
> From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
> To: users_at_jaxb.dev.java.net
> Sent: Saturday, October 4, 2008 10:19:55 AM
> Subject: Re: jaxb code generation issue
>
> The base type wpc:tFromExtension has mixed="true", too.
> Look for a field List<JAXBElement<?>> content in that class.
> That's where your <xs:choice> elements will be after unmarshalling.
>
> You might consider avoiding mixed="true".
>
> -W
>
>
> On Sat, Oct 4, 2008 at 6:13 PM, oxg1123 <oxg1123_at_yahoo.com> wrote:
>> It looks like jaxb2 is ignoring xsd:choice within the xsd:extension. The code generation simply ignores it, not sure why.
>>
>> Any ideas?
>>
>>
>> Please advice.
>>
>>
>> XSD:
>> <complexType name="tFrom" mixed="true">
>> <complexContent>
>> <extension base="wpc:tFromExtension">
>> <sequence>
>> <any namespace="##other" processContents="skip" minOccurs="0"/>
>> <choice minOccurs="0">
>> <element ref="bpws:query"/>
>> <element ref="bpws:expression"/>
>> <element ref="bpws:service-ref"/>
>> </choice>
>> </sequence>
>> <attribute name="variable" type="NCName"/>
>> <attribute name="part" type="NCName"/>
>> <attribute name="property" type="QName"/>
>> <attribute name="partnerLink" type="NCName"/>
>> <attribute name="endpointReference" type="bpws:tRoles"/>
>> <attribute name="opaque" type="bpws:tBoolean"/>
>> </extension>
>> </complexContent>
>> </complexType>
>>
>>
>>
>> Generated code:
>>
>> @XmlAccessorType(XmlAccessType.FIELD)
>> @XmlType(name = "tFrom")
>> @XmlRootElement(name = "from")
>> public class TFrom
>> extends TFromExtension
>> {
>> @XmlAttribute
>> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
>> @XmlSchemaType(name = "NCName")
>> protected String variable;
>> @XmlAttribute
>> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
>> @XmlSchemaType(name = "NCName")
>> protected String part;
>> @XmlAttribute
>> protected QName property;
>> @XmlAttribute
>> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
>> @XmlSchemaType(name = "NCName")
>> protected String partnerLink;
>> @XmlAttribute
>> protected TRoles endpointReference;
>> @XmlAttribute
>> protected TBoolean opaque;
>>
>> /**
>> * Gets the value of the variable property.
>> *
>> * @return
>>
>>
>> Thanks a lot
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>