4

I do have the following annotation in a JAXB generated class

@XmlType(name = "MessageInfoType", propOrder = {
    "debugTraceBoolean",
    "clientHostnameString",
    "endUserIPAddress"
})

Need to produce the following annotation in JAXB class with custom binding..i.e is need to edit the above annotation and add a namespace using annox as below type.

        @XmlType(name = "MessageInfoType", propOrder = {
            "debugTraceBoolean",
            "clientHostnameString",
            "endUserIPAddress"
        }, namespace="urn:expedia:e3:data:messagetypes:defn:v4")

my xjb file is:

  <jaxb:bindings schemaLocation="../../serviceDescription/atlantis/common/com.expedia.e3.data.messagetypes.v4.xsd">

    <jaxb:bindings node="//xs:complexType[@name='MessageInfoType']">
        <annox:annotate target="field">
            <annox:annotate annox:class="javax.xml.bind.annotation.XmlType" 
                   namespace="urn:expedia:e3:data:messagetypes:defn:v4"/>
        </annox:annotate>
    </jaxb:bindings>
  </jaxb:bindings>
lexicore
  • 42,748
  • 17
  • 132
  • 221
user1631733
  • 111
  • 1
  • 3
  • 6
  • need to override an exisiting annotation in the JAXB generated class or either remove it with help of annox in the custom binding file.Please help me out – user1631733 Aug 30 '12 at 23:06

1 Answers1

5

Affiliation disclaimer: I am the author of the Annotate Plugin.

If you try to add an annotation which already exists (same location, same annotation class), this will modify an existing annotation rather than add a second one. I am not sure at the moment, if this will override all the attributes or merge new ones, but it's definitely worth trying.

Update:

I've rechecked this. Indeed, it is implemented (should be of version 0.6.4, I've just checked with 0.6.5-SNAPSHOT).

Check this sample:

https://svn.java.net/svn/jaxb2-commons~svn/basics/trunk/tests/annotate/src/main/resources/bindings.xjb

Here's the binding:

    <jaxb:bindings node="xs:complexType[@name='issueJIIB39CType']/xs:attribute[@name='test']">
        <annox:annotate target="field">
            <annox:annotate annox:class="javax.xml.bind.annotation.XmlAttribute" required="false"/>
        </annox:annotate>
    </jaxb:bindings>

If this binding is present, you'll get:

@XmlAttribute(name = "test", required = false)
protected String test;

If not it will be like this:

@XmlAttribute(name = "test", required = true)
protected String test;

So, as I said if you add an annotation at the very same place and the very same class, they will be merged.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • 1
    I have installed JAXB2-basics-annotate 0.6.4, JAXB2-basics-ant 0.6.4, JAXB2-basics-tools 0.6.4 and rest of them are jaxb-api, jaxb-impl and jaxb-xjc jar(dont know what is the version of these jars). I am getting the below bold error after using 0.6.4 version jar and guessing this is because of some version mismatch. I am using JDK 1.6.0.29 and does 0.6.4 goes only with JDK 1.7 please confirm? Can you tell me what is the version of all other jars I need to use..because I am getting the below error java.lang.NoSuchMethodError: com.sun.codemodel.JAnnotatable.annotations()Ljava/util/Collection; – user1631733 Sep 03 '12 at 00:08
  • Hi lexicore - any idea why the links to the Annotate Plugin docs you pasted above is broken? Is this a temporary problem, or has the project been discontinued? – DeejUK Aug 05 '13 at 12:07
  • The server goes down time after time. Back online now. – lexicore Aug 06 '13 at 19:35