public class XMap extends Object
The mapping is described by annotations on java objects.
The following annotations are supported:
XObject Mark the object as being mappable to an XML node
 XNode Map an XML node to a field of a mappable object
 XNodeList Map an list of XML nodes to a field of a mappable object
 XNodeMap Map an map of XML nodes to a field of a mappable object
 XContent Map an XML node content to a field of a mappable object
 XParent Map a field of the current mappable object to the parent object if any exists The parent object
 is the mappable object containing the current object as a field
 | Constructor and Description | 
|---|
XMap()
Creates a new XMap object. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
protected static Annotation | 
checkMemberAnnotation(AnnotatedElement ae)  | 
protected static XObject | 
checkObjectAnnotation(AnnotatedElement ae)  | 
XAnnotatedMember | 
createFieldMember(Field field,
                 Annotation annotation)  | 
XAnnotatedMember | 
createMethodMember(Method method,
                  Annotation annotation,
                  Class<?> klass)  | 
static DocumentBuilderFactory | 
getFactory()  | 
Collection<XAnnotatedObject> | 
getRootObjects()
Gets the root objects. 
 | 
Collection<XAnnotatedObject> | 
getScannedObjects()
Gets a list of scanned objects. 
 | 
XValueFactory | 
getValueFactory(Class<?> type)
Gets the value factory used for objects of the given class. 
 | 
Object | 
load(Context ctx,
    Element root)
Processes the given DOM element and return the first mappable object found in the element. 
 | 
Object | 
load(Context ctx,
    InputStream in)
Processes the XML content from the given input stream using the given context. 
 | 
Object | 
load(Context ctx,
    URL url)
Processes the XML file at the given URL and using the given contexts. 
 | 
Object | 
load(Element root)
Processes the given DOM element and return the first mappable object found in the element. 
 | 
Object | 
load(InputStream in)
Processes the XML content from the given input stream using a default context. 
 | 
Object | 
load(URL url)
Processes the XML file at the given URL using a default context. 
 | 
Object[] | 
loadAll(Context ctx,
       Element root)
Processes the given DOM element and return a list with all top-level mappable objects found in the element. 
 | 
void | 
loadAll(Context ctx,
       Element root,
       Collection<Object> result)
Same as  
loadAll(Context, Element) but put collected objects in the given collection. | 
Object[] | 
loadAll(Context ctx,
       InputStream in)
Processes the XML from the given input stream using the given context. 
 | 
Object[] | 
loadAll(Context ctx,
       URL url)
Processes the XML file at the given URL using the given context 
 | 
Object[] | 
loadAll(Element root)
Processes the given DOM element and return a list with all top-level mappable objects found in the element. 
 | 
void | 
loadAll(Element root,
       Collection<Object> result)
Same as  
loadAll(Element) but put collected objects in the given collection. | 
Object[] | 
loadAll(InputStream in)
Processes the XML from the given input stream using the given context. 
 | 
Object[] | 
loadAll(URL url)
Processes the XML file at the given URL using a default context. 
 | 
XAnnotatedObject | 
register(Class<?> klass)
Registers a mappable object class. 
 | 
void | 
setValueFactory(Class<?> type,
               XValueFactory factory)
Sets a custom value factory for the given class. 
 | 
String | 
toXML(Object object)  | 
void | 
toXML(Object object,
     Element root)  | 
void | 
toXML(Object object,
     File file)  | 
void | 
toXML(Object object,
     OutputStream os)  | 
public XMap()
public static DocumentBuilderFactory getFactory()
public XValueFactory getValueFactory(Class<?> type)
Value factories are used to decode values from XML strings.
type - the object typepublic void setValueFactory(Class<?> type, XValueFactory factory)
Value factories are used to decode values from XML strings.
type - the object typefactory - the value factory to use for the given typepublic Collection<XAnnotatedObject> getScannedObjects()
Scanned objects are annotated objects that were registered by this XMap instance.
public Collection<XAnnotatedObject> getRootObjects()
Root objects are scanned objects that can be mapped to XML elements that are not part from other objects.
public XAnnotatedObject register(Class<?> klass)
The class will be scanned for XMap annotations and a mapping description is created.
klass - the object classpublic Object load(URL url) throws IOException
url - the XML file urlIOExceptionpublic Object load(Context ctx, URL url) throws IOException
ctx - the context to useurl - the XML file urlIOExceptionpublic Object load(InputStream in) throws IOException
in - the XML input sourceIOExceptionpublic Object load(Context ctx, InputStream in) throws IOException
ctx - the context to usein - the input streamIOExceptionpublic Object[] loadAll(URL url) throws IOException
Returns a list with all registered top level objects that are found in the file.
If not objects are found, an empty list is returned.
url - the XML file urlIOExceptionpublic Object[] loadAll(Context ctx, URL url) throws IOException
Return a list with all registered top level objects that are found in the file.
If not objects are found an empty list is retoruned.
ctx - the context to useurl - the XML file urlIOExceptionpublic Object[] loadAll(InputStream in) throws IOException
Returns a list with all registered top level objects that are found in the file.
If not objects are found, an empty list is returned.
in - the XML input streamIOExceptionpublic Object[] loadAll(Context ctx, InputStream in) throws IOException
Returns a list with all registered top level objects that are found in the file.
If not objects are found, an empty list is returned.
ctx - the context to usein - the XML input streamIOExceptionpublic Object load(Element root)
A default context is used.
root - the element to processpublic Object load(Context ctx, Element root)
The given context is used.
ctx - the context to useroot - the element to processpublic Object[] loadAll(Context ctx, Element root)
The given context is used.
ctx - the context to useroot - the element to processpublic Object[] loadAll(Element root)
The default context is used.
root - the element to processpublic void loadAll(Element root, Collection<Object> result)
loadAll(Element) but put collected objects in the given collection.root - the element to processresult - the collection where to collect objectspublic void loadAll(Context ctx, Element root, Collection<Object> result)
loadAll(Context, Element) but put collected objects in the given collection.ctx - the context to useroot - the element to processresult - the collection where to collect objectsprotected static Annotation checkMemberAnnotation(AnnotatedElement ae)
protected static XObject checkObjectAnnotation(AnnotatedElement ae)
public final XAnnotatedMember createFieldMember(Field field, Annotation annotation)
public final XAnnotatedMember createMethodMember(Method method, Annotation annotation, Class<?> klass)
public String toXML(Object object) throws IOException
IOExceptionpublic void toXML(Object object, OutputStream os) throws IOException
IOExceptionpublic void toXML(Object object, File file) throws IOException
IOExceptionCopyright © 2016 Nuxeo SA. All rights reserved.