Difference between revisions of "EclipseLink/Release/2.4.0/JAXB RI Extensions"
(→XML Accessor Factory)
|Line 34:||Line 34:|
Revision as of 10:22, 19 June 2012
JAXB RI Extensions Support
In the current JAXB RI, developed by Sun, there is a series of "proprietary" JAXB extensions which provide advanced functionality outside of the JAXB specification (these extension classes and properties reside in the com.sun.xml.bind and com.sun.internal.xml.bind packages). This document outlines the new EclipseLink MOXy support for these extensions.
XML Accessor Factory
Allows the user to write their own logic to be used when setting and getting property values.
- Implement com.sun.xml.bind.AccessorFactory interface - Implement com.sun.xml.bind.v2.runtime.reflect.Accessors for field/property access - Add com.sun.xml.bind.XmlAccessorFactory annotation at Class or Package level
Namespace Prefix Mapper
Allows the user to customize the way namespace prefixes are assigned to namespaces by extending the NamespacePrefixMapper class.
marshaller.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, new MyPrefixMapper()); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new MyPrefixMapper());
Allows the user to write their own logic to be used when object cycles are detected during marshal operations.
Implement the com.sun.xml.bind.CycleRecoverable interface on JAXB domain class
Object Identitity Cycle Detection
Used to configure the strategy EclipseLink will use to detect an Object cycle. By default, EclipseLink will use Object identity to determine if a cycle exists; setting this property to false will tell EclipseLink to use the equals() method instead.
Allows the user to omit the XML processing instruction from marshalled documents. This property is the opposite of Marshaller.JAXB_FRAGMENT, and is included for backwards compatibility only.
Allows the user to supply a header string, which will appear after the XML processing instruction (<?xml ...>), but before the start of the document's data.
Allows the user to override the indent string that is used when marshalling objects.
marshaller.setProperty("com.sun.xml.bind.indentString", indentString); marshaller.setProperty(MarshallerProperties.INDENT_STRING, indentString);
Character Escape Handler
Allows the user to provide their own character-escaping logic by supplying their own implementation of the CharacterEscapeHandler interface.
marshaller.setProperty("com.sun.xml.bind.marshaller.CharacterEscapeHandler", new MyCharHandler()); marshaller.setProperty(MarshallerProperties.CHARACTER_ESCAPE_HANDLER, new MyCharHandler());
Allows the user to provide their own logic for resolving XML IDs/IDREFs by supplying their own implementation of the IDResolver interface.
unmarshaller.setProperty("com.sun.xml.bind.IDResolver", new MyIdResolver()); unmarshaller.setProperty(UnmarshallerProperties.ID_RESOLVER, new MyIdResolver());
Allows the user to specify a property on the JAXB object that will be updated (upon unmarshalling) with that object's XML location information (i.e. the line number, column number, and system ID that points to this object's location in the XML input).
Annotate a property with @XmlLocation