Skip to main content

substitutionGroup with imported schema

17 replies [Last post]
greghmerrill
Offline
Joined: 2006-10-27

I'm having an issue unmarshalling members of a substitutionGroup which are in a separate schema & namespace. (The JAXBContext constructed was provided with the ObjectFactory for each namespace.)

model name

Encountered Error:
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element ' ConcreteModel '. {" http://www.foo.com/base":Model} is expected.

But ConcreteModel is declared as a member of the Model substitionGroup, so it's unclear to me why this is happening. Here are the relevant schemas.

Model.xsd:

ModelList.xsd:

ConcreteModel.xsd:

Any tips on getting this to work?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
orangeing
Offline
Joined: 2009-06-24

Do we have a solution for this issue. I am facing the same problem.
I am using the below maven-jaxb plugin.
org.jvnet.jaxb2.maven2
maven-jaxb2-plugin

XML/schema
2.0

orangeing
Offline
Joined: 2009-06-24

Do we have a solution for this issue. I am facing the same problem.
I am using the below maven-jaxb plugin.
org.jvnet.jaxb2.maven2
maven-jaxb2-plugin

XML/schema
2.0

kohsuke
Offline
Joined: 2003-06-09

Sounds like you are enabling validation (presumably by setting a Schema object to Unmarshaller that you created.)

I think you created the Schema object incorrectly.

greghmerrill
Offline
Joined: 2006-10-27

Thanks. We got around this issue. Now we face a different issue related with unmashalling. The generated ObjectFactory class for ConcreteModel also have a createModel method:
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Model }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://www.foo.com/base", name = "Model")
public JAXBElement createModel(Model value) {
return new JAXBElement(_Model_QNAME, Model.class, null, value);
}

This cause unmashalling to fail with following error:
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
The element name {http://www.foo.com/base}Model has more than one mapping. this problem is related to the following location: at public javax.xml.bind.JAXBElement com.bar.model.ObjectFactory.createModel(com.foo.base.Model)
at com.bar.model.ObjectFactory
this problem is related to the following location:
at public javax.xml.bind.JAXBElement com.foo.base.ObjectFactory.createModel(com.foo.base.Model)
at com.foo.base.ObjectFactory

If I manually change the
com.bar.model.ObjectFactory to comment out the createModel method, the unmarshalling works fine.

Could you please suggest a proper workaround or fix for this?

kohsuke
Offline
Joined: 2003-06-09

The question is why there are two createModel methods on different ObjectFactory.

Are there indeed two different declarations? Or is it because you compiled two schemas separately? I think we need a test case.

greghmerrill
Offline
Joined: 2006-10-27

Yes, we do compile the base Model schema and the ConcreteModel schema separately. We compile the base Model schema and generates an episode file, then compile the ConcreteModel schema against the episode file.
Is there a way that we can prevent xjc to generate the createModel method during the ConcreteModel jaxb generation?

kohsuke
Offline
Joined: 2003-06-09

Hmm. Maybe this is a bug in the RI, then.

Can you file an issue and provide us a test case?

kohsuke
Offline
Joined: 2003-06-09
greghmerrill
Offline
Joined: 2006-10-27

Saw the solution posted on the bug ... I tried to execute that against 2.1.1 but I'm getting this error:

[xjc] [ERROR] compiler was unable to honor this substitutable customization. It is attached to a wrong place, or its inconsistent with other bindings.

I saw that the date on 2.1.1 was Jan 22, and the bug solution was posted Jan 17, so I thought it would be available there? Do I need to get a nightly build instead, or is there perhaps an issue with my schema?

xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns="http://www.foo.com/base" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified" jxb:version="2.1" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jxb:extensionBindingPrefixes="xjc">













kohsuke
Offline
Joined: 2003-06-09

The change did make it to the 2.1.1 release. If XJC didn't understand that customization, then it would have said "unrecognized element " or something.

I guess the problem is related to the fact that your model element is local, not global.

Maybe I'm already forgetting the details, but wasn't this about substitution groups? Then you surely can't have local element declarations as substitution group heads, right? So how come your model elements are local?

greghmerrill
Offline
Joined: 2006-10-27

What do you mean about global/local? My understanding is that the element is global if the element is not defined inside of a ComplexType. Based on that, the Model element defined in the xsd is a global element.

kohsuke
Offline
Joined: 2003-06-09

Hmm. I just copied your schema, pasted into an empty file, and compiled it with the -extension switch.

It worked just fine.

Can you double-check that you are running the up-to-date version?

greghmerrill
Offline
Joined: 2006-10-27

It actually failed when compiling the ConcreteModel.xml that extends Model:

xs:schema targetNamespace="http://www.bar.com/model" attributeFormDefault="unqualified"
jxb:version="2.1" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:base="http://www.foo.com/base" xmlns="http://www.bar.com/model" elementFormDefault="qualified">












Errors:
[xjc] Compiling file:/C:/dev/SDK/testcase/schema/xsd/ext/ConcreteModel.xsd
[xjc] [ERROR] compiler was unable to honor this substitutable customization. It is attached to a wrong place, or i
ts inconsistent with other bindings.
[xjc] line 10 of file:///C:/dev/SDK/testcase/schema/xsd/base/Model.xsd

[xjc] [ERROR] (the above customization is attached to the following location in the schema)
[xjc] line 8 of file:///C:/dev/SDK/testcase/schema/xsd/base/Model.xsd

[xjc] failure in the XJC task. Use the Ant -verbose switch for more details

kohsuke
Offline
Joined: 2003-06-09

Please show me the exact invocation syntax just so I know that I'm doing the exact same thing as you did.

androidgalaxyman
Offline
Joined: 2014-06-02

kohsuke wrote:
Please show me the exact invocation syntax just so I know that I'm doing the exact same thing as you did.
Can you please help on the issue which quoted above. My application consists multiple schema having same element name, but when i try to compile it will generate two ObjectFactory with same method name. when try to deploy the application in to appserver , throws the exception

at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:333)
... 13 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
The element name {}row has more than one mapping.
this problem is related to the following location:
at public javax.xml.bind.JAXBElement com.xxxx.tws.pojo.SECTOR.ObjectFactory.createRow(com.xxxx.tws.pojo.SECTOR.SECTORType)
at com.xxxx.tws.pojo.SECTOR.ObjectFactory
this problem is related to the following location:
at public javax.xml.bind.JAXBElement com.xxxx.tws.pojo.SECTORSECTVERSION.ObjectFactory.createRow(com.xxxx.tws.pojo.SECTORSECTVERSION.SECTORSECTVERSIONType)
at com.xxxx.tws.pojo.SECTORSECTVERSION.ObjectFactory

please look in to the below thread

https://community.jboss.org/thread/241553

greghmerrill
Offline
Joined: 2006-10-27

Please use the testcase that attached to issue 289.
Change the Model.xsd as the previous post.

Run : ant jaxb-generate-ext

androidgalaxyman
Offline
Joined: 2014-06-02

Dear greg,
Have you got fixed this issue. i am having same situation. we are having two schema, which is having same element name, it has been compiled by XJC as individually. Once i have created those JAXB classed, when deploy that in to jboss EAP 6.1 Final, reports the problem of illegalAnnoatationException, which is not in to the lower jboss releases.

at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:333)
... 13 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
The element name {}row has more than one mapping.
this problem is related to the following location:
at public javax.xml.bind.JAXBElement com.xxxx.tws.pojo.SECTOR.ObjectFactory.createRow(com.xxxx.tws.pojo.SECTOR.SECTORType)
at com.xxxx.tws.pojo.SECTOR.ObjectFactory
this problem is related to the following location:
at public javax.xml.bind.JAXBElement com.xxxx.tws.pojo.SECTORSECTVERSION.ObjectFactory.createRow(com.xxxx.tws.pojo.SECTORSECTVERSION.SECTORSECTVERSIONType)
at com.xxxx.tws.pojo.SECTORSECTVERSION.ObjectFactory