org.progeeks.util.xml
Class StringObjectHandler

java.lang.Object
  extended by org.progeeks.util.xml.AbstractObjectHandler
      extended by org.progeeks.util.xml.StringObjectHandler
All Implemented Interfaces:
ObjectHandler

public class StringObjectHandler
extends AbstractObjectHandler

ObjectHandler implementation for handling strings. While strings can be constructed using the full <java.lang.String _ctor="foo" /> syntax and can also be included in any <foo></foo> set for properties that can take strings these methods fall short in some cases. A general method of specifying multi-line strings is necessary that can also support being including in lists, etc.. The problem with the _ctor version is that the string must all be in an attribute which means it has to be on the same line.

This handler supports a <string>foo<string> syntax which will allow multi-line strings even in lists. For easy legacy use, the handler also supports a _ctor attribute and the full java.langString tag.

Version:
$Revision: 1.1 $
Author:
Paul Speed

Field Summary
static StringObjectHandler DEFAULT_STRING_HANDLER
           
static java.util.Set handledTags
           
 
Constructor Summary
StringObjectHandler()
           
 
Method Summary
 boolean canHandle(java.lang.String tag)
          Returns true if this handler applies to the specified object tag.
 java.lang.Object createObject(java.lang.String tag, org.xml.sax.Attributes atts, ObjectXmlReader reader)
          Creates and returns an object based on the specified parameters.
 java.lang.Object getProperty(java.lang.Object obj, java.lang.String field, ObjectXmlReader reader)
          Returns the current value of the specified property in the specified object.
 java.lang.Class getPropertyClass(java.lang.Object obj, java.lang.String field, ObjectXmlReader reader)
          Returns the base type for the specified field.
 java.util.Collection getPropertyCollection(java.lang.Object obj, java.lang.String field, ObjectXmlReader reader)
          Returns the a collection for the specified field that can be used to accumulate multiple object values.
 java.lang.Object resolveObject(java.lang.String tag, java.lang.Object obj, ObjectXmlReader reader)
          Converts a handler-specific internal representation of an object to a standard representation.
 void setContainedText(java.lang.String tag, java.lang.Object obj, java.lang.String text, ObjectXmlReader reader)
          Called to apply any body text found during tag processing.
 void setProperty(java.lang.Object obj, java.lang.String field, java.lang.Object value, ObjectXmlReader reader)
          Sets a property on the specified object.
 void setTextProperty(java.lang.Object obj, java.lang.String field, java.lang.String value, ObjectXmlReader reader)
          Sets a text-value property on the specified object.
 
Methods inherited from class org.progeeks.util.xml.AbstractObjectHandler
setConfigurationProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STRING_HANDLER

public static final StringObjectHandler DEFAULT_STRING_HANDLER

handledTags

public static java.util.Set handledTags
Constructor Detail

StringObjectHandler

public StringObjectHandler()
Method Detail

canHandle

public boolean canHandle(java.lang.String tag)
Returns true if this handler applies to the specified object tag.

Specified by:
canHandle in interface ObjectHandler
Specified by:
canHandle in class AbstractObjectHandler

setProperty

public void setProperty(java.lang.Object obj,
                        java.lang.String field,
                        java.lang.Object value,
                        ObjectXmlReader reader)
Sets a property on the specified object.

Specified by:
setProperty in interface ObjectHandler
Specified by:
setProperty in class AbstractObjectHandler

setTextProperty

public void setTextProperty(java.lang.Object obj,
                            java.lang.String field,
                            java.lang.String value,
                            ObjectXmlReader reader)
Sets a text-value property on the specified object. The handler may do some internal conversions to translate into an appropriate type.

Specified by:
setTextProperty in interface ObjectHandler
Specified by:
setTextProperty in class AbstractObjectHandler

getPropertyClass

public java.lang.Class getPropertyClass(java.lang.Object obj,
                                        java.lang.String field,
                                        ObjectXmlReader reader)
Returns the base type for the specified field. This is used to determine whether or not to accumulate field values in a collection.

Specified by:
getPropertyClass in interface ObjectHandler
Specified by:
getPropertyClass in class AbstractObjectHandler

getPropertyCollection

public java.util.Collection getPropertyCollection(java.lang.Object obj,
                                                  java.lang.String field,
                                                  ObjectXmlReader reader)
Returns the a collection for the specified field that can be used to accumulate multiple object values. This is used when the XML field declaration specifies the progressive attribute.

Specified by:
getPropertyCollection in interface ObjectHandler
Specified by:
getPropertyCollection in class AbstractObjectHandler

getProperty

public java.lang.Object getProperty(java.lang.Object obj,
                                    java.lang.String field,
                                    ObjectXmlReader reader)
Returns the current value of the specified property in the specified object. This is used by the xml.existingValue directive and may eventually replace getPropertyCollection() as well.

Specified by:
getProperty in interface ObjectHandler
Specified by:
getProperty in class AbstractObjectHandler

createObject

public java.lang.Object createObject(java.lang.String tag,
                                     org.xml.sax.Attributes atts,
                                     ObjectXmlReader reader)
Creates and returns an object based on the specified parameters.

Specified by:
createObject in interface ObjectHandler
Specified by:
createObject in class AbstractObjectHandler

setContainedText

public void setContainedText(java.lang.String tag,
                             java.lang.Object obj,
                             java.lang.String text,
                             ObjectXmlReader reader)
Description copied from class: AbstractObjectHandler
Called to apply any body text found during tag processing.

Specified by:
setContainedText in interface ObjectHandler
Overrides:
setContainedText in class AbstractObjectHandler

resolveObject

public java.lang.Object resolveObject(java.lang.String tag,
                                      java.lang.Object obj,
                                      ObjectXmlReader reader)
Converts a handler-specific internal representation of an object to a standard representation. This is an implementation specific thing since some handlers will collect attributes/properties in an intermediate object. When the end of the tag is reached, the ObjectXmlReader will call this method to perform and necessary translations. Handlers that don't require resolution should just return the passed object. Default implementation returns obj.

Specified by:
resolveObject in interface ObjectHandler
Overrides:
resolveObject in class AbstractObjectHandler


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