Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed IDREF(S) properties lead to Compile Errors #12

Closed
wildsau opened this issue Feb 21, 2018 · 0 comments
Closed

Typed IDREF(S) properties lead to Compile Errors #12

wildsau opened this issue Feb 21, 2018 · 0 comments

Comments

@wildsau
Copy link

wildsau commented Feb 21, 2018

Thanks for your great plugin!

We currently have a problem with using it in one of our project. We have an object model with a lot of cross referencing between the objects, that is seralized to XML. The cross referencing is implemented by IDREF(S) elements.

see http://ecad-wiki.prostep.org/doku.php?id=specifications:vec:start for XSD and model documentation.

Per default JAXB is generating IDREF(S) elements as properties with type Object or List<Object>. In our case this is not convenient, since there are model constraints that define specific types for specific IDREFS. To avoid programming errors during serialization and to avoid unnecessary type checks and cast during deserialization, we have to customize the IDREF properties to specific types.

The only way to this (at least the one we found) is to create custom binding like this one:

   <jxb:bindings node="//xs:complexType[@name='CompatibilityStatement']">
      <jxb:bindings node=".//xs:element[@name='Slot']">
         <jxb:property>
            <jxb:baseType name="......VecAbstractSlot"/>
         </jxb:property>
      </jxb:bindings>
   </jxb:bindings>

And here starts the problem. The VecAbstractSlot itself is included in the schema and is generated by XJC, but at the time of parsing the Schema (and the Binding) XJC does not know that it generates the class. So FieldOutline.getRawType() is initialized with a com.sun.codemodel.JDirectClass .

In the plugin, this leads to duplicate methods in the Visitor interface, because one method is created for the generated class, and one method is created for the com.sun.codemodel.JDirectClass which actually point to the same class. Same applies to the Traverser.

Additionally, the DepthFirstTraverserImpl generates traversal for the IDREF(S) properties as well, which will result in endless looping.

From my point of view, there are two possible solutions:

  1. Exclude the IDREF(S) properties from com.massfords.jaxb.ClassDiscoverer.discoverDirectClasses(Outline, Set<ClassOutline>). (I tried it and it works).
  2. Double check, that there is no JDefinedClass with the same name as the JDirectClass.

I will try the second approach, as it seems more elegant and does not require interpretation of the CPropertyInfo.getSchemaComponent() and submit a pull request for either the first or the second approach.

THX in advance

massfords added a commit that referenced this issue Mar 17, 2018
Fix typed IDREF(S) elements compilation error #12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants