Packagecom.yworks.io.graphml.writer.serializer
Classpublic class ReflectionBasedSerializer
InheritanceReflectionBasedSerializer Inheritance Object
Implements ISerializer
Subclasses ExtensionBasedSerializer

This ISerializer can be used to serialize objects of different class type based on reflection.

The package of a class of which instances shall be serialized this way has to be added to the SymbolicPackageNameRegistry together with the symbolic package name that should be used during the serialization.

If the given object implements the IMarkupExtensionFactory interface, the markup extension of the object will be serialized instead of the object itself.

This serializer also handles the serialization of com.yworks.support.IEnum implementations.

Only public read- and writeable properties are serialized.

See also

com.yworks.support.IEnum
com.yworks.io.SymbolicPackageNameRegistry
com.yworks.io.graphml.reader.deserializer.ReflectionBasedDeserializer


Public Properties
 PropertyDefined By
  elementName : String
[read-only] The element name of the toplevel XmlElement for the serialized representation of this object.
ReflectionBasedSerializer
  instance : ReflectionBasedSerializer
[static] [read-only] The shared instance of this serializer
ReflectionBasedSerializer
  xmlNamespace : Namespace
[read-only]
ReflectionBasedSerializer
Public Methods
 MethodDefined By
  
canHandle(context:GraphMLWriteContext, object:Object):Boolean
Checks if the package of the class of the given object is registered in the SymbolicPackageNameRegistry.
ReflectionBasedSerializer
  
serialize(context:GraphMLWriteContext, subject:Object, writer:IXmlWriter):void
Serialize the given style to a IXmlWriter.
ReflectionBasedSerializer
Protected Methods
 MethodDefined By
  
getMemberSerializer(context:GraphMLWriteContext, subject:Object, currentValue:Object, propertyDesc:XML):ISerializer
ReflectionBasedSerializer
  
getProperties(context:GraphMLWriteContext, subject:Object):XMLList
Returns a list of all properties that should be serialized.
ReflectionBasedSerializer
  
getTagName(context:GraphMLWriteContext, subject:Object):String
ReflectionBasedSerializer
  
getXmlNamespace(context:GraphMLWriteContext, subject:Object):Namespace
ReflectionBasedSerializer
  
hasDefaultValue(context:GraphMLWriteContext, subject:Object, property:XML):Boolean
Returns true if a property has a default value and therefore should not be written at all.
ReflectionBasedSerializer
  
isCollectionProperty(context:GraphMLWriteContext, subject:Object, property:XML):Boolean
Returns true if the property is a collection property that needs to be handled specially.
ReflectionBasedSerializer
  
serializeContent(context:GraphMLWriteContext, subject:Object, writer:IXmlWriter):void
Write the content of the graphml element that corresponds to the serialization of subject.
ReflectionBasedSerializer
  
shouldSerialize(context:GraphMLWriteContext, subject:Object, property:XML):Boolean
Returns true if property should be serialized.
ReflectionBasedSerializer
  
shouldWriteMemberAsAttribute(context:GraphMLWriteContext, subject:Object, property:XML):Boolean
Determines whether property should be written as attribute value or as complete element.
ReflectionBasedSerializer
Property Detail
elementNameproperty
elementName:String  [read-only]

The element name of the toplevel XmlElement for the serialized representation of this object.


Implementation
    public function get elementName():String
instanceproperty 
instance:ReflectionBasedSerializer  [read-only]

The shared instance of this serializer


Implementation
    public static function get instance():ReflectionBasedSerializer
xmlNamespaceproperty 
xmlNamespace:Namespace  [read-only]


Implementation
    public function get xmlNamespace():Namespace
Method Detail
canHandle()method
public function canHandle(context:GraphMLWriteContext, object:Object):Boolean

Checks if the package of the class of the given object is registered in the SymbolicPackageNameRegistry.

Parameters

context:GraphMLWriteContext — The GraphMLWriteContext of the serialization.
 
object:Object — The object to serialize.

Returns
Booleantrue if the package is registered, false otherwise.
getMemberSerializer()method 
protected function getMemberSerializer(context:GraphMLWriteContext, subject:Object, currentValue:Object, propertyDesc:XML):ISerializer

Parameters

context:GraphMLWriteContext
 
subject:Object
 
currentValue:Object
 
propertyDesc:XML

Returns
ISerializer
getProperties()method 
protected function getProperties(context:GraphMLWriteContext, subject:Object):XMLList

Returns a list of all properties that should be serialized.

This implementation returns all public properties that are read/write, filtered using shouldSerialize().

Parameters

context:GraphMLWriteContext — The current write context
 
subject:Object — The object that should be serialized.

Returns
XMLList — A list of all properties that should be serialized

See also

getTagName()method 
protected function getTagName(context:GraphMLWriteContext, subject:Object):String

Parameters

context:GraphMLWriteContext
 
subject:Object

Returns
String
getXmlNamespace()method 
protected function getXmlNamespace(context:GraphMLWriteContext, subject:Object):Namespace

Parameters

context:GraphMLWriteContext
 
subject:Object

Returns
Namespace
hasDefaultValue()method 
protected function hasDefaultValue(context:GraphMLWriteContext, subject:Object, property:XML):Boolean

Returns true if a property has a default value and therefore should not be written at all.

This implementation just checks if the current property value is equal to the default value specified using an optional [DefaultValue] meta attribute

Parameters

context:GraphMLWriteContext — The current write context
 
subject:Object — The object that should be serialized.
 
property:XML — The XML description of the property.

Returns
Booleantrue if the property has a default value.

See also

DefaultValueAttribute
isCollectionProperty()method 
protected function isCollectionProperty(context:GraphMLWriteContext, subject:Object, property:XML):Boolean

Returns true if the property is a collection property that needs to be handled specially.

This implementations returns true, if the property is assignable to com.yworks.support.List and to com.yworks.support.Iterable.

Parameters

context:GraphMLWriteContext — The current write context
 
subject:Object — The object that is to be serialized
 
property:XML — The XML description of the property

Returns
Boolean — Whether the property is a collection property

See also

flash.utils.describeType()
serialize()method 
public function serialize(context:GraphMLWriteContext, subject:Object, writer:IXmlWriter):void

Serialize the given style to a IXmlWriter.

Parameters

context:GraphMLWriteContext — The current write context
 
subject:Object — The actual object
 
writer:IXmlWriter — An IXmlWriter instance where the output is written

See also


Example
The following xml fragments shows how a serialized object of type MyObject may look like: The given object has two properties:
  • an int property with name 'myIntProperty' and value 100
  • a property of a complex type with name 'myComplexTypeProperty'
The symbolic package name 'mySymbolicPackage' has been registered for this package using br/> SymbolicPackageNameRegistry.add('myPackage', 'mySymbolicPackage'); br/> The resulting xml looks like:
     <aaa:MyObject myIntProperty="100" xmlns:aaa="mySymbolicPackage">
       <aaa:MyObject.myComplexTypeProperty>
        ... serialization of this property
       </aaa:MyObject.myComplexTypeProperty>
     </aaa:MyObject>
     
serializeContent()method 
protected function serializeContent(context:GraphMLWriteContext, subject:Object, writer:IXmlWriter):void

Write the content of the graphml element that corresponds to the serialization of subject.

Parameters

context:GraphMLWriteContext — The current write context.
 
subject:Object — The current object to be serialized.
 
writer:IXmlWriter — The xml writer.

shouldSerialize()method 
protected function shouldSerialize(context:GraphMLWriteContext, subject:Object, property:XML):Boolean

Returns true if property should be serialized.

This implementation returns true if it is a collection property (see isCollectionProperty()), or if all of the following are true:

Parameters

context:GraphMLWriteContext — The current write context
 
subject:Object — The object that should be serialized.
 
property:XML — The XML descriptor of the property.

Returns
Booleantrue if the property should be serialized.

See also

shouldWriteMemberAsAttribute()method 
protected function shouldWriteMemberAsAttribute(context:GraphMLWriteContext, subject:Object, property:XML):Boolean

Determines whether property should be written as attribute value or as complete element.

Parameters

context:GraphMLWriteContext — The current write context.
 
subject:Object — The object that should be serialized.
 
property:XML — The XML description of the property.

Returns
Booleantrue iff the member should be written as an XML attribute value.