In a project I'm working on, we generate classes from multiple xsd. Some of my classes need a public static final String EXTENSION_CODE = "NAMEOFTHEEXTENSION";
. The xsd of my class looks something like :
<xsd:complexType name="SomeExtension">
<xsd:sequence>
<xsd:element name="ID" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="element1" type="Class" minOccurs="0" maxOccurs="1" />
<xsd:element name="element2" type="Class" minOccurs="0" maxOccurs="1" />
<xsd:element name="element3" type="Class" minOccurs="0" maxOccurs="1" />
<xsd:element name="element4" type="Class" minOccurs="0" maxOccurs="1" />
<xsd:element name="otherID" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="element5" type="xsd:string" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
This will generate a class that will look like :
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SomeExtension", propOrder = {
"ID",
"element1",
"element2",
"element3",
"element4",
"otherID",
"element5"
})
public class SomeExtension
implements Serializable, Cloneable, CopyTo
{
private final static long serialVersionUID = 1L;
@XmlElement(required = true)
protected String iD;
protected Element1 element1;
protected Element2 element2;
protected Element3 element3;
protected Element4 element4;
@XmlElement(required = true)
protected String otherID;
protected String element5;
What I need is :
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SomeExtension", propOrder = {
"ID",
"element1",
"element2",
"element3",
"element4",
"otherID",
"element5"
})
public class SomeExtension
implements Serializable, Cloneable, CopyTo
{
public static final String EXTENSION_CODE = "NAMEOFTHEEXTENSION";
private final static long serialVersionUID = 1L;
@XmlElement(required = true)
protected String iD;
protected Element1 element1;
protected Element2 element2;
protected Element3 element3;
protected Element4 element4;
@XmlElement(required = true)
protected String otherID;
protected String element5;
I searched on Google with the following keyword : java generate static variable from xsd, and didn't find something usefull. Is there a way I could do this or is my need of a public static String
weird in the first place ?