1. Castor XML - XML data binding ...................................................................................................1
1.1. XML framework ................................................................................................................1
1.1.1. Introduction ............................................................................................................1
1.1.2. Castor XML - The XML data binding framework ......................................................1
1.1.3. Sources and destinations ..........................................................................................5
1.1.4. XMLContext - A consolidated way to bootstrap Castor ..............................................7
1.1.5. Using existing Classes/Objects ................................................................................. 7
1.1.6. Class Descriptors ..................................................................................................... 8
1.2. XML Mapping ................................................................................................................... 8
1.2.1. Introduction ............................................................................................................8
1.2.2. Overview ................................................................................................................9
1.2.3. The Mapping File .................................................................................................. 10
1.2.4. Usage Pattern ........................................................................................................ 23
1.2.5. xsi:type ................................................................................................................. 27
1.2.6. Location attribute .................................................................................................. 28
1.2.7. Tips ...................................................................................................................... 29
1.3. Configuring Castor XML (Un)Marshaller .......................................................................... 30
1.3.1. Introduction .......................................................................................................... 30
1.3.2. Configuring the Marshaller .................................................................................... 30
1.3.3. Configuring the Unmarshaller ................................................................................ 31
1.4. Usage of Castor and XML parsers ..................................................................................... 31
1.4.1. SAX/DOM ............................................................................................................ 31
1.4.2. StAX .................................................................................................................... 32
1.5. XML configuration file ..................................................................................................... 32
1.5.1. News .................................................................................................................... 32
1.5.2. Introduction .......................................................................................................... 32
1.5.3. Accessing the properties from within code .............................................................. 36
1.6. Castor XML - Tips & Tricks ............................................................................................. 36
1.6.1. Logging and Tracing ............................................................................................. 36
1.6.2. Indentation ............................................................................................................ 36
1.6.3. XML:Marshal validation ........................................................................................ 37
1.6.4. NoClassDefFoundError ......................................................................................... 37
1.6.5. Mapping: auto-complete ........................................................................................ 37
1.6.6. Create method ....................................................................................................... 37
1.6.7. MarshalListener and UnmarshalListener ................................................................. 38
1.7. Castor XML: Writing Custom FieldHandlers ..................................................................... 39
1.7.1. Introduction .......................................................................................................... 39
1.7.2. Writing a simple FieldHandler ................................................................................ 39
1.7.3. Writing a GeneralizedFieldHandler ........................................................................ 42
1.7.4. Use ConfigurableFieldHandler for more flexibility .................................................. 44
1.7.5. Reuse a ConfigurableFieldHandler for more than one field definition .................... 46
1.7.6. No Constructor, No Problem! ................................................................................. 47
1.7.7. Collections and FieldHandlers ................................................................................ 50
1.8. Best practice .................................................................................................................... 51
1.8.1. General ................................................................................................................. 51
1.8.2. Performance Considerations ................................................................................... 51
1.9. Castor XML - HOW-TO's ................................................................................................. 54
1.9.1. Introduction .......................................................................................................... 54
1.9.2. Documentation ...................................................................................................... 54
1.9.3. Contribution .......................................................................................................... 54
1.9.4. Mapping ............................................................................................................... 55
1.9.5. Validation ............................................................................................................. 55
ii