Class DefaultObjectSerializationDelegate
- java.lang.Object
-
- com.inductiveautomation.ignition.common.xmlserialization.serialization.AbstractSerializationDelegate<java.lang.Object>
-
- com.inductiveautomation.ignition.common.xmlserialization.serialization.DefaultObjectSerializationDelegate
-
- All Implemented Interfaces:
SerializationDelegate<java.lang.Object>
- Direct Known Subclasses:
BasicTranslationPackageDelegate
,BorderUIResourceDelegate
,DefaultComponentDelegate
,InteractionDescriptorDelegate
,ListDelegate
,LocaleDelegate
,MapDelegate
,ProjectTagDelegate
,PyStringDelegate
,SetDelegate
,ShapeComponentDelegate
,TagEventScriptsDelegate
,WindowDelegate
public class DefaultObjectSerializationDelegate extends AbstractSerializationDelegate<java.lang.Object>
An implementation of SerializationDelegate that uses reflection and the JavaBean standard to try and serialize any arbitrary object
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
elementName
protected static java.util.Map<java.lang.Class,com.inductiveautomation.ignition.common.xmlserialization.serialization.DefaultObjectSerializationDelegate.EqualityDelegate>
equalityDelegates
protected static DescriptorComparator
propertyComparator
protected boolean
skipReferenceTracking
static java.lang.String
TRANSIENT_KEY
Key for a PropertyDescriptor to mark itself transient.
-
Constructor Summary
Constructors Constructor Description DefaultObjectSerializationDelegate()
Creates an object serializer that uses the default no-arg constructorDefaultObjectSerializationDelegate(boolean ctorOnly, java.lang.String... properties)
DefaultObjectSerializationDelegate(java.lang.Class[] types, java.lang.String[] properties)
Uses the constructor that accepts the given properties as arguments.DefaultObjectSerializationDelegate(java.lang.String... properties)
Uses the constructor that accepts the given properties as arguments.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doProperty(XMLSerializationContext context, Element elm, java.beans.PropertyDescriptor pd, java.lang.Object obj, java.lang.Object clean)
Serializes the given property to the streamprotected void
initConstructorTypes(java.lang.Class clazz)
boolean
isConstructorOnly()
boolean
isSkipReferenceTracking()
protected boolean
isTransient(java.beans.PropertyDescriptor pd)
static boolean
safeArrayEquals(java.lang.Object[] a, java.lang.Object[] a2)
static boolean
safeEquals(java.lang.Object foo, java.lang.Object bar)
equals that uses null-safe equality (null==null: true) and the delegates to the equalityDelegates if there is one registered for the argument class.Element
serialize(XMLSerializationContext context, java.lang.Object obj)
protected Element
serializeConstructor(XMLSerializationContext context, java.lang.Object obj)
Gathers up the values for the properties named for an explicit constructor call, and then writes the call to the constructorprotected void
serializeProperties(XMLSerializationContext context, Element elm, java.lang.Object obj)
Runs through the javabean properties of the given object, and comares the values of each property to the value that a clean copy of the object would have.void
setConstructorOnly(boolean constructorOnly)
void
setSkipReferenceTracking(boolean skipReferenceTracking)
protected Element
startObject(XMLSerializationContext context, java.lang.Object obj)
Creates an Element with this delegate's element name and with the "cls" attribute set to the object's class.protected Element
writeCall(XMLSerializationContext context, java.lang.reflect.Method method, java.lang.Object... args)
protected Element
writeCall(XMLSerializationContext context, java.lang.String methodName, java.lang.Class[] argTypes, java.lang.Object... args)
Writes an <o:c> element, which represents a call to a method.protected Element
writeConstructor(XMLSerializationContext context, java.lang.Class[] types, java.lang.Object[] args)
-
-
-
Field Detail
-
TRANSIENT_KEY
public static final java.lang.String TRANSIENT_KEY
Key for a PropertyDescriptor to mark itself transient. Value should be Boolean.TRUE- See Also:
- Constant Field Values
-
propertyComparator
protected static DescriptorComparator propertyComparator
-
elementName
protected java.lang.String elementName
-
skipReferenceTracking
protected boolean skipReferenceTracking
-
equalityDelegates
protected static java.util.Map<java.lang.Class,com.inductiveautomation.ignition.common.xmlserialization.serialization.DefaultObjectSerializationDelegate.EqualityDelegate> equalityDelegates
-
-
Constructor Detail
-
DefaultObjectSerializationDelegate
public DefaultObjectSerializationDelegate()
Creates an object serializer that uses the default no-arg constructor
-
DefaultObjectSerializationDelegate
public DefaultObjectSerializationDelegate(java.lang.String... properties)
Uses the constructor that accepts the given properties as arguments. This version creates a constructor-only serialization delegate.
-
DefaultObjectSerializationDelegate
public DefaultObjectSerializationDelegate(boolean ctorOnly, java.lang.String... properties)
-
DefaultObjectSerializationDelegate
public DefaultObjectSerializationDelegate(java.lang.Class[] types, java.lang.String[] properties)
Uses the constructor that accepts the given properties as arguments. This constructor explicitly defines the types of the arguments accepted by the constructor in cases where it might be ambiguous.
-
-
Method Detail
-
safeEquals
public static boolean safeEquals(java.lang.Object foo, java.lang.Object bar)
equals that uses null-safe equality (null==null: true) and the delegates to the equalityDelegates if there is one registered for the argument class.
-
safeArrayEquals
public static boolean safeArrayEquals(java.lang.Object[] a, java.lang.Object[] a2)
-
writeCall
protected Element writeCall(XMLSerializationContext context, java.lang.reflect.Method method, java.lang.Object... args) throws SerializationException
- Throws:
SerializationException
-
writeCall
protected Element writeCall(XMLSerializationContext context, java.lang.String methodName, java.lang.Class[] argTypes, java.lang.Object... args) throws SerializationException
Writes an <o:c> element, which represents a call to a method.- Throws:
SerializationException
-
isTransient
protected boolean isTransient(java.beans.PropertyDescriptor pd)
-
doProperty
protected void doProperty(XMLSerializationContext context, Element elm, java.beans.PropertyDescriptor pd, java.lang.Object obj, java.lang.Object clean) throws java.lang.Exception
Serializes the given property to the stream- Throws:
java.lang.Exception
-
serializeProperties
protected void serializeProperties(XMLSerializationContext context, Element elm, java.lang.Object obj) throws SerializationException
Runs through the javabean properties of the given object, and comares the values of each property to the value that a clean copy of the object would have. Serializes all properties that have a dirty value.- Throws:
SerializationException
-
startObject
protected Element startObject(XMLSerializationContext context, java.lang.Object obj) throws SerializationException
Creates an Element with this delegate's element name and with the "cls" attribute set to the object's class.- Throws:
SerializationException
-
serialize
public Element serialize(XMLSerializationContext context, java.lang.Object obj) throws SerializationException
- Throws:
SerializationException
-
serializeConstructor
protected Element serializeConstructor(XMLSerializationContext context, java.lang.Object obj) throws SerializationException
Gathers up the values for the properties named for an explicit constructor call, and then writes the call to the constructor- Throws:
SerializationException
-
writeConstructor
protected Element writeConstructor(XMLSerializationContext context, java.lang.Class[] types, java.lang.Object[] args) throws SerializationException
- Throws:
SerializationException
-
initConstructorTypes
protected void initConstructorTypes(java.lang.Class clazz) throws SerializationException
- Throws:
SerializationException
-
isConstructorOnly
public boolean isConstructorOnly()
-
setConstructorOnly
public void setConstructorOnly(boolean constructorOnly)
-
isSkipReferenceTracking
public boolean isSkipReferenceTracking()
- Specified by:
isSkipReferenceTracking
in interfaceSerializationDelegate<java.lang.Object>
- Overrides:
isSkipReferenceTracking
in classAbstractSerializationDelegate<java.lang.Object>
-
setSkipReferenceTracking
public void setSkipReferenceTracking(boolean skipReferenceTracking)
-
-