org.jboss.xb.binding
Class MappingObjectModelFactory

java.lang.Object
  extended by org.jboss.xb.binding.MappingObjectModelFactory
All Implemented Interfaces:
GenericObjectModelFactory, ObjectModelFactory

public class MappingObjectModelFactory
extends Object
implements GenericObjectModelFactory

An ObjectModelFactory that uses mappings

Version:
$Revision: 1.1.2.4 $
Author:
Alexey Loubyansky, Adrian Brock

Constructor Summary
MappingObjectModelFactory()
           
 
Method Summary
 void addChild(Object parent, Object child, UnmarshallingContext ctx, String namespaceURI, String localName)
          This method is called when parsing of a not top-level XML element completed.
 Object completeRoot(Object root, UnmarshallingContext navigator, String namespaceURI, String localName)
          This method is called by the framework when unmarshalling of the object graph completed.
 void mapElementToClass(String element, Class cls)
          Map an element to a class
 void mapElementToField(String element, Class cls, String field, TypeBinding converter)
          Map an element to a field
 Object newChild(Object o, UnmarshallingContext ctx, String namespaceURI, String localName, Attributes attrs)
          This method is called when parsing of a new not top-level XML element started.
 Object newRoot(Object root, UnmarshallingContext ctx, String namespaceURI, String localName, Attributes attrs)
          This method is called by the framework and returns the root of the object graph.
 void setValue(Object o, UnmarshallingContext ctx, String namespaceURI, String localName, String value)
          This method is called when a new not top-level simple XML element (with text content) was parsed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MappingObjectModelFactory

public MappingObjectModelFactory()
Method Detail

mapElementToClass

public void mapElementToClass(String element,
                              Class cls)
Map an element to a class

Parameters:
element - the element name
cls - the class

mapElementToField

public void mapElementToField(String element,
                              Class cls,
                              String field,
                              TypeBinding converter)
Map an element to a field

Parameters:
element - the element name
cls - the class
field - the field name
converter - the type convertor

newRoot

public Object newRoot(Object root,
                      UnmarshallingContext ctx,
                      String namespaceURI,
                      String localName,
                      Attributes attrs)
Description copied from interface: ObjectModelFactory
This method is called by the framework and returns the root of the object graph.

If root argument is null, the factory is supposed to create and return a new one that is going to be the real root object of the graph or an object that will represent the root object during unmarshalling and which will be used to create the real root object when unmarshalling is complete in completeRoot if the real root object can't be created while its children are not available, e.g. no no-arg constructor or other reasons.

If root argument is not null (i.e. a user provided the root object through the org.jboss.xml.binding.Unmarshaller) then the factory could just return it as is or extract the real root from the root argument based on the namespace URI and local name if root argument wraps/contains the real root.

Specified by:
newRoot in interface ObjectModelFactory
Parameters:
root - an object that is the root or which contains the root of the object graph
ctx - unmarshalling context
namespaceURI - namespace URI of the root
localName - local name of the root
attrs - attributes of the root object
Returns:
the root of the object graph

newChild

public Object newChild(Object o,
                       UnmarshallingContext ctx,
                       String namespaceURI,
                       String localName,
                       Attributes attrs)
Description copied from interface: GenericObjectModelFactory
This method is called when parsing of a new not top-level XML element started. The method should either return an object that represents this XML element in the Java object model or null if this XML element is not represented in the Java object model.

Specified by:
newChild in interface GenericObjectModelFactory
Parameters:
o - an object that represents the parent XML element in the object model
ctx - unmarshalling context
namespaceURI - namespace URI of the XML element
localName - local name of the XML element
attrs - attributes of the XML element
Returns:
an object that represents the XML element in the Java object model or null

addChild

public void addChild(Object parent,
                     Object child,
                     UnmarshallingContext ctx,
                     String namespaceURI,
                     String localName)
Description copied from interface: GenericObjectModelFactory
This method is called when parsing of a not top-level XML element completed. The object that represents this XML element in the Java model should now be completely initialized. An implementation of this method could validate the object that represents the XML element in the Java object model and add it to the parent.

Specified by:
addChild in interface GenericObjectModelFactory
Parameters:
parent - an object that represents the parent XML element in the object model
child - an object that was returned by the newChild method that was called when parsing of this XML element started
ctx - unmarshalling context
namespaceURI - namespace URI of the XML element
localName - local name of the XML element

setValue

public void setValue(Object o,
                     UnmarshallingContext ctx,
                     String namespaceURI,
                     String localName,
                     String value)
Description copied from interface: GenericObjectModelFactory
This method is called when a new not top-level simple XML element (with text content) was parsed. Such elements are usually mapped to fields in Java classes. So, usually, an implementation of this method will set the field the XML element is bound to in the parent object to the parsed value possibly applying some unmarshalling rule for it.

Specified by:
setValue in interface GenericObjectModelFactory
Parameters:
o - an object that represents the parent XML element in the Java object model
ctx - unmarshalling context
namespaceURI - namespace URI of the XML element
localName - local name of the XML element
value - value of the XML element as it appears in the XML content

completeRoot

public Object completeRoot(Object root,
                           UnmarshallingContext navigator,
                           String namespaceURI,
                           String localName)
Description copied from interface: ObjectModelFactory
This method is called by the framework when unmarshalling of the object graph completed. The method returns the root object of the object graph. If at the beginning of unmarshalling newRoot returned not the real root object but an object that represented the root during unmarshalling, the real root object should be created and returned.

Specified by:
completeRoot in interface ObjectModelFactory
Parameters:
root - the object returned by newRoot at the beginning of unmarshalling
navigator - unmarshalling context
namespaceURI - namespace URI that corresponds to the root
localName - local element name the root of the object graph is bound to
Returns:
the root of the object graph


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.