org.pojava.persistence.serial
Class XmlDefs

java.lang.Object
  extended by org.pojava.persistence.serial.XmlDefs

public class XmlDefs
extends Object

XmlDefs holds configuration settings for serialization.

Author:
John Pile

Field Summary
 Map<Class<?>,SerialFactory<?>> factories
          Factories define how objects are constructed.
 
Constructor Summary
XmlDefs()
          Initialize XmlDefs with known factory mappings.
 
Method Summary
 void addAccessors(org.pojava.lang.Accessors accessor)
          Cache accessors for a class.
 void addOmission(Class<?> type, String property)
          Useful for omitting objects from the XML stream.
 Object construct(Class<?> type, Object[] params)
          Construct an object matching the given params using a custom constructor
 Object construct(Class type, Map params)
          Construct an object using named parameters.
 SerialFactory<?> factory(Class<?> type)
          Return a registered factory (or null if unregistered)
 org.pojava.lang.Accessors getAccessors(Class<?> type)
          Retrieve the cached accessors for this class.
 Map<String,Class<?>> getProperties(Class<?> type)
          Generate (or retrieve from cache) properties for a given class.
 Integer getReferenceId(Object obj)
          Get the numeric serial ID of the reference object.
 boolean hasAccessors(Class<? extends Object> type)
          Return true if Accessors have been cached for this class.
 String indent(int depth)
          Indent to the given depth.
 boolean isIgnoringIllegalAccessException()
          If true, then fields that throw IllegalAccessException are quietly ignored.
 boolean isIgnoringInvocationTargetException()
          If true, then fields that throw InvocationTargetException are quietly ignored.
 boolean isOmission(Class<?> type, String property)
          Determine if a given property should be omitted.
 boolean isOmittingNulls()
          True if null values are omitted from serialized document.
 boolean isReferenced(Object obj)
          Determine if object was reference by another object.
 boolean isSerialized(Object obj)
          Determine if object has been serialized earlier in the stream.
 boolean isValue(Class<?> type)
          True if type is supported by a factory.
 Integer register(Object obj)
           Null = Serialize 0 = getReferenceId 1+ = referenceId
 void registerFactory(Class<?> type, SerialFactory<?> factory)
          You can add or override your own custom factory for each type.
 void rename(Class<?> type, String property, String xmlName)
          Rename registration
 String renamedJava(Class<?> type, String name)
          Keeps track of properties to rename in XML tags.
 String renamedXml(Class<?> type, String name)
          Renamed version of tag
 void resetRegistry()
          Reset this registry for a new parse.
 void setIgnoringIllegalAccessException(boolean ignoringIllegalAccessException)
          If true, then fields that throw IllegalAccessException are quietly ignored.
 void setIgnoringInvocationTargetException(boolean ignoringInvocationTargetException)
          If true, then fields that throw InvocationTargetException are quietly ignored.
 void setOmittingNulls(boolean omittingNulls)
          Set false to include null values explicitly in the output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factories

public Map<Class<?>,SerialFactory<?>> factories
Factories define how objects are constructed.

Constructor Detail

XmlDefs

public XmlDefs()
Initialize XmlDefs with known factory mappings.

Method Detail

registerFactory

public void registerFactory(Class<?> type,
                            SerialFactory<?> factory)
You can add or override your own custom factory for each type.

Parameters:
type -
factory -

factory

public SerialFactory<?> factory(Class<?> type)
Return a registered factory (or null if unregistered)

Parameters:
type -
Returns:
SerialFactory for given type

construct

public Object construct(Class<?> type,
                        Object[] params)
Construct an object matching the given params using a custom constructor

Parameters:
type -
params -
Returns:
constructed Object

construct

public Object construct(Class type,
                        Map params)
Construct an object using named parameters.

Parameters:
type -
params -
Returns:
constructed Object

isValue

public boolean isValue(Class<?> type)
True if type is supported by a factory.

Parameters:
type -
Returns:
true if supported

isReferenced

public boolean isReferenced(Object obj)
Determine if object was reference by another object.

Parameters:
obj -
Returns:
true if object is referenced

getReferenceId

public Integer getReferenceId(Object obj)
Get the numeric serial ID of the reference object.

Parameters:
obj -
Returns:
serial ID assigned by the serializer for this object

isSerialized

public boolean isSerialized(Object obj)
Determine if object has been serialized earlier in the stream.

Parameters:
obj -
Returns:
true if object has already been serialized in the stream

register

public Integer register(Object obj)
 Null = Serialize
    0 = getReferenceId
   1+ = referenceId
 

Parameters:
obj -
Returns:
null if serializing, 0 if needing reference ID, or 1+ if providing reference ID

resetRegistry

public void resetRegistry()
Reset this registry for a new parse.


rename

public void rename(Class<?> type,
                   String property,
                   String xmlName)
Rename registration

Parameters:
type - class containing property
property - java property to rename
xmlName - xml tag representing property

renamedXml

public String renamedXml(Class<?> type,
                         String name)
Renamed version of tag

Parameters:
type -
name -
Returns:
java name from tag after renaming

renamedJava

public String renamedJava(Class<?> type,
                          String name)
Keeps track of properties to rename in XML tags.

Parameters:
type -
name -
Returns:
java property renamed from xml tag

indent

public String indent(int depth)
Indent to the given depth.

Parameters:
depth -
Returns:
pad characters meeting the given depth

addOmission

public void addOmission(Class<?> type,
                        String property)
Useful for omitting objects from the XML stream.

Parameters:
type -
property -

isOmission

public boolean isOmission(Class<?> type,
                          String property)
Determine if a given property should be omitted.

Parameters:
type -
property -
Returns:
true if a property was designated for omission from output

getProperties

public Map<String,Class<?>> getProperties(Class<?> type)
Generate (or retrieve from cache) properties for a given class.

Parameters:
type -
Returns:
a map of getters and setters for this class

hasAccessors

public boolean hasAccessors(Class<? extends Object> type)
Return true if Accessors have been cached for this class.

Parameters:
type -
Returns:
true if Accessors have been cached for this class.

getAccessors

public org.pojava.lang.Accessors getAccessors(Class<?> type)
Retrieve the cached accessors for this class.

Parameters:
type -
Returns:
cached accessors for this type

addAccessors

public void addAccessors(org.pojava.lang.Accessors accessor)
Cache accessors for a class.

Parameters:
accessor -

isOmittingNulls

public boolean isOmittingNulls()
True if null values are omitted from serialized document.

Returns:
true if null values are omitted from xml document

setOmittingNulls

public void setOmittingNulls(boolean omittingNulls)
Set false to include null values explicitly in the output.

Parameters:
omittingNulls -

isIgnoringInvocationTargetException

public boolean isIgnoringInvocationTargetException()
If true, then fields that throw InvocationTargetException are quietly ignored.

Returns:
true or false

setIgnoringInvocationTargetException

public void setIgnoringInvocationTargetException(boolean ignoringInvocationTargetException)
If true, then fields that throw InvocationTargetException are quietly ignored.


isIgnoringIllegalAccessException

public boolean isIgnoringIllegalAccessException()
If true, then fields that throw IllegalAccessException are quietly ignored.

Returns:
true or false

setIgnoringIllegalAccessException

public void setIgnoringIllegalAccessException(boolean ignoringIllegalAccessException)
If true, then fields that throw IllegalAccessException are quietly ignored.

Parameters:
ignoringIllegalAccessException - true to quietly ignore exception.


Copyright © 2011. All Rights Reserved.