| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Castor XML - Code generator properties
Documentation Author(s): Overview Customization - Lookup mechanism Detailed descriptions Source generation & Java 5.0 SimpleType Enumerations Bound Properties Class Creation/Mapping Setting a super class Mapping XML namespaces to Java packages Generate equals()/hashCode() method Maps java primitive types to wrapper object Automatic class name conflict resolution Extra collection methods Class printing Extra documentation methods OverviewPlease find below a list of properties that can be configured through the builder configuration properties, as defined in either the default or a custom XML code generator configuration file. These properties allow you to control various advanced options of the XML source generator.
Customization - Lookup mechanismBy default, the Castor XML code generator will look for such a property file in the following places:
Detailed descriptionsSource generation & Java 5.0As of Castor 1.0.2, the Castor source generator now supports the
generation of Java 5.0 compliant code. The generated code - with the
new feature enabled - will make use of the following Java 5.0-specific
artifacts:
To enable this feature (off by default), please uncomment the following property in your custom castorbuilder.properties file:
SimpleType EnumerationsIn previous versions, castor only supported (un)marshalling of "simple" java5 enums, meaning enums where all facet values are valid java identifiers. In these cases, every enum constant name can be mapped directly to the xml value. See the following example:
So if there is at least ONE facet that cannot be mapped directly to a valid java identifier, we need to extend the enum pattern. Examples for these cases are value="5" or value="-s". Castor now introduces an extended pattern, similar to the jaxb2 enum handling. The actual value of the enumeration facet is stored in a private String property, the name of the enum constant is translated into a valid identifier. Additionally, some convenience methods are introduced, details about these methods are described after the following example:
Unmarshalling of complex enumsCastor uses the static void fromValue(String value) method to retrieve the correct instance from the value in the xml input file. In our example, the input is "5", fromValue returns CompositeType.VALUE_5 Marshalling of complex enumsCurrently, we have to distinguish between enums with a class descriptor and the ones without. If you are using class descriptors, the EnumerationHandler uses the value() method to write the xml output. If no descriptor classes are available, castor uses per default the toString() method to marshall the value. In this case, the override of the java.lang.Enum.toString() method is mandatory, because java.lang.Enum.toString returns the NAME of the facet instead of the VALUE. So in our example, "VALUE_10" would be returned instead of "10". To avoid this, castor expects an implementation of toString that returns "this.value". Source Generation of complex enumsIf the java version is set to "5.0", the new default behavior of castor is to generate complex java5 enums for simpleType enumerations, as described above. In java 1.4 mode, nothing has changed and the old style enumeration classes using a HashMap are created. Users, who are in java5 mode and still want to use the old style java 1.4 classes, can force this by setting the new "org.exolab.castor.builder.forceJava4Enums" property to true.
Bound PropertiesBound properties are "properties" of a class, which when
updated the class will send out a To enable bound properties, please add the following property definition to your custom builder configuration file:
When enabled, all properties will be treated as bound properties. For each class that is generated a setPropertyChangeListener method is created as follows:
Whenever a property of the class is changed, a
Class Creation/MappingThe source generator can treat the XML Schema structures such as <complexType> and element in two main ways. The first, and current default method is called the "element" method. The other is called the "type" method.
To change the "method" of class creation, please add the following property definition to your custom builder configuration file:
Setting a super classThe source generator enables the user to set a super class to all the generated classes (of course, class descriptors are not affected by this option). Pleae note that, though the binding file, it is possible to define a super class for individual classes To set the global super class, please add the following property definition to your custom builder configuration file:
Mapping XML namespaces to Java packagesAn XML Schema instance is identified by a namespace. For data-binding purposes, especially code generation it may be necessary to map namespaces to Java packages. This is needed for imported schema in order for Castor to generate the correct imports during code generation for the primary schema. To allow the mapping between namespaces and Java packages , edit the castorbuilder.properties file :
Generate equals()/hashCode() methodSince version: 0.9.1 The Source Generator can override the equals() and hashCode() method for the generated objects. To have equals() and hashCode() methods generated, override the following property in your custom castorbuilder.properties file:
Maps java primitive types to wrapper objectSince version 0.9.4
It may be convenient to use java objects instead of primitives,
the Source Generator provides a way to do it. Thus the following mapping can be used:
To enable this property, edit the castor builder.properties file:
Automatic class name conflict resolutionSince version 1.1.1 With this property enabled, the XML code generator will use a new automatic class name resolution mode that has special logic implemented to automatically resolve class name conflicts. This new mode deals with various class name conflicts where previously a binding file had to be used to resolve these conflicts manually. To enable this feature (turned off by default), please add the following property definitio to your custom castorbuilder.properties file:
Extra collection methodsSpecifies whether extra (additional) methods should be created for collection-style fields. Set this to true if you want your code to be more compatible with Castor JDO (or other persistence frameworks). Adds additional getter/setter methods for the field in question, such as get/set by reference and set as copy methods. Class printingAs of release 1.2, Castor supports the use of Velocity-based code templates for code generation. For the time being, Castor will support two modes for code generation, i.e. the new Velocity-based and an old legacy mode. Default will be the legacy mode; this will be changed with a later release of Castor. In order to use the new Velocity-based code generation, please call the setJCLassPrinterType(String) method on the SourceGenerator class with a value of velocity. As we consider the code stable enough for a major release, we do encourage users to use the new Velocity-based mode and to provide us with (valuable) feedback. Please note that we have changed the mechanics of changing the JClass printing type between releases 1.2 and 1.2.1. Extra documentation methods
As of release 1.2, the Castor XML code generator - if configured as shown below - now
supports generation of additional methods to allow programmatic access to
<xs:documentation> elements for top-level type/element definitions as
follows:
In order to have these additional methods generated as shown above,
please override the following code generator property in a custom
castorbuilder.properties as shown:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||