![]() | ![]() | ![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]()
|
Castor XML - Tips & TricksLogging and Tracing Indentation XML:Marshal validation NoClassDefFoundError Mapping: auto-complete Create method MarshalListener and UnmarshalListener Logging and TracingWhen developing using Castor, we recommend that you use the various setLogWriter methods to get detailed information and error messages. Using a logger with Using a logger with Using a logger with A simple trace logger can be obtained from
Interested in integratating Castor's logging with Log4J? Then see this question in the JDO FAQ. IndentationBy default the marshaler writes XML documents without indentation. When developing using Castor or when debugging an application that uses Castor, it might be desireable to use indentation to make the XML documents human-readable. To turn indentation on, modify the Castor properties file, or create a new properties file in the classpath (named castor.properties) with the following content: org.exolab.castor.indent=true Indentation inflates the size of the generated XML documents, and also consumes more CPU. It is recommended not to use indentation in a production environment. XML:Marshal validationIt is possible to disable the validation in the marshaling framework by modifying the Castor properties file or by creating a new properties file in the classpath (named castor.properties) with the following content: org.exolab.castor.marshalling.validation=false NoClassDefFoundErrorCheck your CLASSPATH, check it often, there is no reason not to! Mapping: auto-completeNote: this only works with Castor-XML. To save time when writing your mappings, try using the auto-complete attribute of class. When using auto-complete, Castor will introspect your class and automatically fill in any missing fields.
Example:
This is also compatible with generated descriptor files. You can use a mapping file to override some of the behavior of a compiled descriptor by using auto-complete. **Note: Be careful to make sure you use the exact field name as specified in the generated descriptor file in order to modify the behavior of the field descriptor! Otherwise, you'll probably end up with two fields being marshaled! Create methodCastor requires that classes have a public, no-argument constructor in order to provide the ability to marshal & unmarshal objects of that type. create-method is an optional attribute to the <field> mapping element that can be used to overcome this restriction in cases where you have an existing object model that consists of, say, singleton classes where public, no-argument constructors must not be present by definition. Assume for example that a class "A" that you want to be able to unmarshal uses a singleton class as one of its properties. When attempting to unmarshal class "A", you should get an exception because the singleton property has no public no-arg constructor. Assuming that a reference to the singleton can be obtained via a static getInstance() method, you can add a "create method" to class A like this: public MySingleton getSingletonProperty() { return MySingleton.getInstance(); } and in the mapping file for class A, you can define the singleton property like this: <field name="mySingletonProperty" type="com.u2d.MySingleton" create-method="getSingletonProperty"> <bind-xml name="my-singleton-property" node="element" /> </field> This illustrates how the create-method attribute is quite a useful mechanism for dealing with exceptional situations where you might want to take advantage of marshaling even when some classes do not have no-argument public constructors. Note: As of this writing, the specified create-method must exist as a method in the current class (i.e. the class being described by the current <class> element). In the future it may be possible to use external static factory methods. MarshalListener and UnmarshalListenerCastor allows control on the object being marshaled or unmarshaled by a set of two listener interfaces: MarshalListener and UnmarshalListener.
The MarshalListener interface located in
The UnmarshalListener located also in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() ![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |