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

Add annotations to xs:element #68

Closed
manstis opened this issue May 24, 2021 · 1 comment
Closed

Add annotations to xs:element #68

manstis opened this issue May 24, 2021 · 1 comment

Comments

@manstis
Copy link

manstis commented May 24, 2021

Similarly to #66 I find I am unable to add (or remove, I assume) annotations to xsd:element items within a schema; as shown below, with the latest SNAPSHOTs of both org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.14.1-SNAPSHOT and org.jvnet.jaxb2_commons:jaxb2-basics-annotate:1.1.1-SNAPSHOT built locally.

Schema

<xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    jaxb:version="2.1"
    xmlns:annox="http://annox.dev.java.net"
    jaxb:extensionBindingPrefixes="annox">

  <xsd:element name="Simple">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="child1" type="xsd:string"/>
        <xsd:element name="child2" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:complexType name="Complex">
    <xsd:sequence>
      <xsd:element name="child1" type="xsd:string"/>
      <xsd:element name="child2" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>

</xsd:schema>

Bindings

<jaxb:bindings
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
		xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:annox="http://annox.dev.java.net"
    xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
    jaxb:extensionBindingPrefixes="annox"
    version="2.1">

  <jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">

    <jaxb:bindings node="xs:element[@name='Simple']">
      <annox:annotateClass>@java.lang.Deprecated</annox:annotateClass>
    </jaxb:bindings>

    <jaxb:bindings node="xs:complexType[@name='Complex']">
      <annox:annotateClass>@java.lang.Deprecated</annox:annotateClass>
    </jaxb:bindings>

  </jaxb:bindings>

</jaxb:bindings>

Generated code (snippets)
Simple

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "child1",
    "child2"
})
@XmlRootElement(name = "Simple")
public class Simple {
...
}

Complex

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Complex", propOrder = {
    "child1",
    "child2"
})
@Deprecated
public class Complex {
...
}
@manstis
Copy link
Author

manstis commented May 24, 2021

... and no sooner had I created this issue, I did a little more debugging:

Sun's XJC is not reporting an "customisations" for the outer "simple element" which are used to drive the annotation plugin.

However it does report "customisations" for the inner "complex type".

So, changing my binding to the following fixed my problem:

<jaxb:bindings node="xs:element[@name='Simple']\xs:complexType">
  <annox:annotateClass>@java.lang.Deprecated</annox:annotateClass>
</jaxb:bindings>

@manstis manstis closed this as completed May 24, 2021
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

1 participant