org.progeeks.util.xml
Class ObjectXmlReader

java.lang.Object
  extended by org.progeeks.util.xml.XmlReader
      extended by org.progeeks.util.xml.ObjectXmlReader
Direct Known Subclasses:
ObjectTransformingXmlReader

public class ObjectXmlReader
extends XmlReader

A general XML-based object reader. Handlers can be plugged in that support different object creation schemes. For example, a bean handler could create beans and set their properties, a MetaObject handler could do the same. Special handlers could even be registered that read specific attributes to construct an object. Internally, there are some directives that this reader supports that will be handled for the handlers. This includes things like the object referencing and such.

Version:
$Revision: 1.41 $
Author:
Paul Speed

Nested Class Summary
protected  class ObjectXmlReader.ObjectTagReader
          Handler that will dynamically deal with all of the different tags.
 
Nested classes/interfaces inherited from class org.progeeks.util.xml.XmlReader
XmlReader.XmlHandler
 
Field Summary
static java.lang.String COLLECTION_VALUES_DIRECTIVE
           
static java.lang.String CONFIG_DIRECTIVE
           
static java.lang.String DIRECTIVE_PREFIX
           
static java.lang.String EXISTING_VALUE_DIRECTIVE
           
static java.lang.String FIELD_TYPE_DIRECTIVE
           
static java.lang.String OID_DIRECTIVE
           
static java.lang.String PRELOAD_DIRECTIVE
           
static java.lang.String REFERENCE_DIRECTIVE
           
 
Constructor Summary
ObjectXmlReader()
          Creates an ObjectXmlReader that will read an object from an XML file based on the handler plug-ins that are later registered with it.
ObjectXmlReader(boolean addStandardHandlers)
          Creates an ObjectXmlReader that will read an object from an XML file based on the handler plug-ins that are later registered with it.
ObjectXmlReader(java.lang.String rootTag)
          Creates an ObjectXmlReader that will read a list of objects from an XML file based on the handler plug-ins that are later registered with it.
ObjectXmlReader(java.lang.String rootTag, boolean addStandardHandlers)
          Creates an ObjectXmlReader that will read a list of objects from an XML file based on the handler plug-ins that are later registered with it.
 
Method Summary
 void addObjectHandler(ObjectHandler handler)
          Adds an object handler to the list of handlers.
 void addObjectTagAlias(java.lang.String objectTag, java.lang.String alias)
          Adds an alias that will be used to replace any matching object-level tag with the specified alias.
 void addStandardObjectHandlers()
          Automatically registers a set of commonly used object handlers.
protected  void configureHandlers(org.xml.sax.Attributes atts)
          Sends configuration properties to all handlers.
protected  ObjectHandler getHandler(java.lang.String tag)
          Locates the appropriate handler for the given object tag.
 java.util.List getObjectHandlers()
          Returns the list of handler plug-ins that this reader will use to resolve its object tags.
 java.lang.Object getReferenceObject(java.lang.String id)
          Returns an object for the specified ID if one exists.
 boolean ignoreAttribute(java.lang.String name)
          Returns true if the specified attribute should be ignored for regular object-level property processing.
 java.lang.Object readObject(org.w3c.dom.Document in)
          Reads the XML from a DOM tree as an object and returns it.
 java.lang.Object readObject(org.w3c.dom.Document in, javax.xml.transform.Transformer transformer)
          Reads the XML from a DOM tree as object, applying the given transformation.
 java.lang.Object readObject(java.io.Reader in)
          Reads the XML as a meta-object and returns it.
protected  void reset()
          Resets the internal data structures before reading another object.
 void setObjectHandlers(java.util.List handlers)
          Sets the list of handler plug-ins that this reader will use to resolve its object tags.
 
Methods inherited from class org.progeeks.util.xml.XmlReader
addTagText, createXmlException, createXmlException, endTag, getAttributesAsMap, getCurrentObject, getDocumentLocator, getIgnoreTagCase, getLocation, getPreviousObject, getRootObject, getStackSize, getTagReader, readXml, readXml, readXml, registerHandler, replaceCurrentObject, resolveEntity, setDefaultHandler, setIgnoreTagCase, startTag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECTIVE_PREFIX

public static final java.lang.String DIRECTIVE_PREFIX
See Also:
Constant Field Values

OID_DIRECTIVE

public static final java.lang.String OID_DIRECTIVE
See Also:
Constant Field Values

REFERENCE_DIRECTIVE

public static final java.lang.String REFERENCE_DIRECTIVE
See Also:
Constant Field Values

FIELD_TYPE_DIRECTIVE

public static final java.lang.String FIELD_TYPE_DIRECTIVE
See Also:
Constant Field Values

COLLECTION_VALUES_DIRECTIVE

public static final java.lang.String COLLECTION_VALUES_DIRECTIVE
See Also:
Constant Field Values

CONFIG_DIRECTIVE

public static final java.lang.String CONFIG_DIRECTIVE
See Also:
Constant Field Values

PRELOAD_DIRECTIVE

public static final java.lang.String PRELOAD_DIRECTIVE
See Also:
Constant Field Values

EXISTING_VALUE_DIRECTIVE

public static final java.lang.String EXISTING_VALUE_DIRECTIVE
See Also:
Constant Field Values
Constructor Detail

ObjectXmlReader

public ObjectXmlReader()
Creates an ObjectXmlReader that will read an object from an XML file based on the handler plug-ins that are later registered with it. This constructor will automatically register and standard handlers as defined in addStanderObjectHandlers().


ObjectXmlReader

public ObjectXmlReader(boolean addStandardHandlers)
Creates an ObjectXmlReader that will read an object from an XML file based on the handler plug-ins that are later registered with it.


ObjectXmlReader

public ObjectXmlReader(java.lang.String rootTag)
Creates an ObjectXmlReader that will read a list of objects from an XML file based on the handler plug-ins that are later registered with it. The root-level tag must match the specified rootTag. This constructor will automatically register and standard handlers as defined in addStanderObjectHandlers().


ObjectXmlReader

public ObjectXmlReader(java.lang.String rootTag,
                       boolean addStandardHandlers)
Creates an ObjectXmlReader that will read a list of objects from an XML file based on the handler plug-ins that are later registered with it. The root-level tag must match the specified rootTag.

Method Detail

addStandardObjectHandlers

public void addStandardObjectHandlers()
Automatically registers a set of commonly used object handlers. Right now this is just the StringObjectHandler.


setObjectHandlers

public void setObjectHandlers(java.util.List handlers)
Sets the list of handler plug-ins that this reader will use to resolve its object tags. Object handlers are checked in order to see which one can handle a give object tag.


addObjectHandler

public void addObjectHandler(ObjectHandler handler)
Adds an object handler to the list of handlers. Object handlers are checked in order to see which one can handle a give object tag.


getObjectHandlers

public java.util.List getObjectHandlers()
Returns the list of handler plug-ins that this reader will use to resolve its object tags. Object handlers are checked in order to see which one can handle a give object tag.


addObjectTagAlias

public void addObjectTagAlias(java.lang.String objectTag,
                              java.lang.String alias)
Adds an alias that will be used to replace any matching object-level tag with the specified alias.


readObject

public java.lang.Object readObject(java.io.Reader in)
                            throws java.io.IOException
Reads the XML as a meta-object and returns it.

Overrides:
readObject in class XmlReader
Throws:
java.io.IOException

readObject

public java.lang.Object readObject(org.w3c.dom.Document in)
                            throws XmlException
Reads the XML from a DOM tree as an object and returns it.

Throws:
XmlException

readObject

public java.lang.Object readObject(org.w3c.dom.Document in,
                                   javax.xml.transform.Transformer transformer)
                            throws XmlException
Reads the XML from a DOM tree as object, applying the given transformation.

Throws:
XmlException

ignoreAttribute

public boolean ignoreAttribute(java.lang.String name)
Returns true if the specified attribute should be ignored for regular object-level property processing. This can be called by handlers that want to ignore the attribute values of internal directives.


getReferenceObject

public java.lang.Object getReferenceObject(java.lang.String id)
Returns an object for the specified ID if one exists. This can be used by handlers to retrieve objects from the reference cache.


reset

protected void reset()
Resets the internal data structures before reading another object. This is called by readObject().

Overrides:
reset in class XmlReader

getHandler

protected ObjectHandler getHandler(java.lang.String tag)
Locates the appropriate handler for the given object tag.


configureHandlers

protected void configureHandlers(org.xml.sax.Attributes atts)
Sends configuration properties to all handlers.



Copyright © 2002-2003 Paul Speed. All Rights Reserved.