- A Framework for Java/XML binding based on SAX2 -Customizing the generated classesIt is not unusual that the generated classes do not satisfy all your needs. A possible workaround is using manually derived subclasses, but that's sometimes not very convenient. A more comfortable solution might be to extend the generated classes by adding your own methods. Before going on, remember that the various generators can create a lot of classes for you. So the first thing to decide is: Which class to you actually want to extend? The element class (for example ClsMyDocument)? The handler class (for example ClsMyDocumentHandler)? A bean class (for example ClsMyDocumentBean? You can extend all! Let's take a look at an example, taken from implements.xsd: <xs:element name="ObserverDemo"> <xs:annotation> <xs:appinfo> <jm:implements class="ClsObserverDemo" interface="java.util.Observer"/> <jm:javasource class="ClsObserverDemo"> public void update(java.util.Observable o, Object arg) { if (arg instanceof Integer) { if (eObservedNumbers == null) { eObservedNumbers = new java.util.ArrayList(); } eObservedNumbers.add(arg); } } </jm:javasource> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:sequence> <xs:element name="ObservedNumbers" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> This example generates an element class which is implementing the Java interface java.util.Observer. An Observer must have a method update(Observable, Object), so we add it here. The extended class is the element class, so both the jm:implements and jm:javasource sections take an attribute class specifying the element class name. You may use an arbitrary number of jm:implements and jm:javasource sections, with varying class names or not. |