Java Reference
In-Depth Information
So JAXB generates the Category.javafile to match. Category happens to be a schema enu-
meration, and the mapping from a schema enum to a Java enum is very straightforward:
@XmlType(name = "Category")
@XmlEnum
public enum Category {
COOKING,
LITERATURE,
PHILOSOPHY,
PROGRAMMING;
public String value() {
return name();
}
public static Category fromValue(String v) {
return valueOf(v);
}
}
You can then compile and use these classes as you would any other regular Java class. The
ObjectFactory class that is generated here is only for backward compatibility with earlier
versions of JAXB. So you could use this code in conjunction with code written in JAXB 1.0,
and it would still work together.
You can see that simpleType string constraints are lost in generation. This is perhaps not what
you would expect, but if you are using JAXB for web service model generation, you will still
be able to validate your user input into these types using the schema itself at runtime.
For SOA, you might consider starting from XML schemas for entity types, generating sources
from them, and then packaging your schemas with your WSDL on the client, which can then
validate against any pattern constraints you might have defined.
To see additional options for use with XJC, you can simply invoke xjc from the command
line with no arguments, and it will print usage information.
WARNING
Be careful treating generated files as first-class citizens in your project. While the schemas used to
generate them may be of primary importance, you should not build on generated Java sources. In
general, do not commit generated code to your CVS or SVN repository.
Search WWH ::




Custom Search