Packagecom.yworks.io.graphml.reader.deserializer
Classpublic class ReflectionBasedDeserializer
InheritanceReflectionBasedDeserializer Inheritance AbstractDeserializer Inheritance Object

This IDeserializer can be used to deserialize complex objects based on reflection.

A target class to which an XML node shall be deserialized this way has to:

If there exists a MarkupExtension in the same package which is named like the XML but with 'Extension' attached (e.g. MyClassExtension) it is tried to deserialize the XML node into an instance of this markup extension and return the result of it's provideValue method.

This class also handles deserialization of .com.yworks.support.IEnum instances.

See also

com.yworks.io.graphml.writer.serializer.ReflectionBasedSerializer
com.yworks.io.SymbolicPackageNameRegistry
com.yworks.support.IEnum


Public Properties
 PropertyDefined By
  elementName : String
[override] [read-only] The local tag name that this Deserializer can claim to handle
ReflectionBasedDeserializer
  instance : ReflectionBasedDeserializer
[static] [read-only] The shared instance of this deserializer
ReflectionBasedDeserializer
  xmlNamespace : Namespace
[override] [read-only] The XmlNamespace that this Deserializer can claim to handle.
ReflectionBasedDeserializer
Public Methods
 MethodDefined By
  
canHandle(context:GraphMLParseContext, element:XML):Boolean
[override] Returns whether a deserializer can handle a specific xml element.
ReflectionBasedDeserializer
  
deserialize(context:GraphMLParseContext, element:XML):Object
[override] Create a new instance from the xml element
ReflectionBasedDeserializer
Protected Methods
 MethodDefined By
  
assignListValues(context:GraphMLParseContext, collectionContent:XMLList, list:List):void
Parses and assigns the single element values in collectionContent to list
ReflectionBasedDeserializer
  
getTargetClass(symbolicPackageName:String, className:String):Class
Tries to lookup the given symbolicPackageName in the SymbolicPackageNameRegistry and to resolve the resulting package name with the given className to a Class object.
ReflectionBasedDeserializer
  
isCollectionProperty(context:GraphMLParseContext, instance:Object, propertyClass:Class):Boolean
Returns true, if the property is assignable to com.yworks.support.List.
ReflectionBasedDeserializer
  
parseCollectionProperty(context:GraphMLParseContext, instance:Object, collectionChildren:XMLList, propertyName:String):void
Parses and applies collectionContent to a list property.
ReflectionBasedDeserializer
Property Detail
elementNameproperty
elementName:String  [read-only] [override]

The local tag name that this Deserializer can claim to handle


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

The shared instance of this deserializer


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

The XmlNamespace that this Deserializer can claim to handle.

This method needs to be overridden by subclass implementations.


Implementation
    public function get xmlNamespace():Namespace
Method Detail
assignListValues()method
protected function assignListValues(context:GraphMLParseContext, collectionContent:XMLList, list:List):void

Parses and assigns the single element values in collectionContent to list

Parameters

context:GraphMLParseContext — The target list.
 
collectionContent:XMLList — List of XML nodes forming the collection content.
 
list:List — The current parse context.

canHandle()method 
override public function canHandle(context:GraphMLParseContext, element:XML):Boolean

Returns whether a deserializer can handle a specific xml element. This implementation returns true, if

Parameters

context:GraphMLParseContext — The current parse context
 
element:XML — The xml node to be parsed

Returns
Booleantrue if this deserializer can handle the given xml node.
deserialize()method 
override public function deserialize(context:GraphMLParseContext, element:XML):Object

Create a new instance from the xml element

Parameters

context:GraphMLParseContext — The current parse context
 
element:XML — The current xml element

Returns
Object — A new instance

See also


Example
Deserialization of an xml fragment to an object:
     The xml fragment may look like:
     
     <aaa:MyObject myIntProperty="100" xmlns:aaa="mySymbolicPackageName">
       <aaa:MyObject.myComplexTypeProperty>
        ... serialization of this property
       </aaa:MyObject.myComplexTypeProperty>
     </aaa:MyObject>
     
     Therefore if 'mySymbolicPackageName' would be mapped to 'myClientPackage', an instance of
     myClientPackage.MyObject is initialized which has to have the
     following properties:
     - an int property with name 'myIntProperty'
     - a property of some complex type with name 'myComplexTypeProperty' for which a deserializer is registered
     
     The xml attribute 'myIntProperty' is read via an ITypeConverter and set in the new object.
     The xml child node 'MyObject.myComplexTypeProperty' is deserialized via the looked up deserializer and set
     as value of the property 'myComplexTypeProperty' of the new object.
     
getTargetClass()method 
protected function getTargetClass(symbolicPackageName:String, className:String):Class

Tries to lookup the given symbolicPackageName in the SymbolicPackageNameRegistry and to resolve the resulting package name with the given className to a Class object.

If an extension class exists with 'Extension' appended to the given className, the extension class is returned instead of the class itself.

Parameters

symbolicPackageName:String — The symbolic package name to look up in the SymbolicPackageNameRegistry.
 
className:String — The class name to resolve.

Returns
Class — A resolved class object or an extension class object or null if no class could be resolved.
isCollectionProperty()method 
protected function isCollectionProperty(context:GraphMLParseContext, instance:Object, propertyClass:Class):Boolean

Returns true, if the property is assignable to com.yworks.support.List.

Parameters

context:GraphMLParseContext — The current parse context
 
instance:Object — The target instance
 
propertyClass:Class — the property type

Returns
Booleantrue if the property is a collection property.
parseCollectionProperty()method 
protected function parseCollectionProperty(context:GraphMLParseContext, instance:Object, collectionChildren:XMLList, propertyName:String):void

Parses and applies collectionContent to a list property.

Parameters

context:GraphMLParseContext — The current parse context.
 
instance:Object — A list of child content that is inserted in the collection as single elements.
 
collectionChildren:XMLList — The target instance.
 
propertyName:String — the name of the list property

See also