com.yworks.yfiles.server.graphml.flexio.serializer
Class ReflectionBasedSerializer

java.lang.Object
  extended byy.io.graphml.output.AbstractSerializer
      extended bycom.yworks.yfiles.server.graphml.flexio.serializer.ReflectionBasedSerializer
All Implemented Interfaces:
java.util.EventListener, SerializationHandler
Direct Known Subclasses:
ExtensionBasedSerializer

public class ReflectionBasedSerializer
extends AbstractSerializer

This serializer can be used to serialize complex objects based on reflection.

The package of a class whose 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.

This serializer also handles serialization of IEnum implementations.

Only public read- and writable properties are serialized.

See Also:
SymbolicPackageNameRegistry

Constructor Summary
ReflectionBasedSerializer()
           
 
Method Summary
 boolean canHandle(SerializationEvent e)
          Predicate member method to determine whether this instance should react to a given SerializationEvent.
protected  java.lang.String getNamespace(GraphMLWriteContext context, java.lang.Object object)
           
protected  java.lang.String getPropertyName(GraphMLWriteContext context, java.beans.PropertyDescriptor property)
          Returns the string that should be used for the attribute or child element when a property is serialized.
protected  java.lang.String getTagName(GraphMLWriteContext context, java.lang.Object object)
           
protected  boolean isCollectionProperty(GraphMLWriteContext context, java.lang.Object subject, java.beans.PropertyDescriptor property)
          Returns true if the property is a collection property that needs to be handled specially.
protected  void serializeContent(GraphMLWriteContext context, java.lang.Object object, XmlWriter writer, java.lang.String symbolicPackageName, java.lang.String tagName)
          Writes the actual content of the GraphML element that corresponds to the serialization of object.
 void serializeItem(java.lang.Object object, XmlWriter writer, GraphMLWriteContext context)
          The namespace for the serialized object consists of the symbolic package name as registered in the SymbolicPackageNameRegistry for the package of this object's class.
 
Methods inherited from class y.io.graphml.output.AbstractSerializer
onHandleSerialization
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionBasedSerializer

public ReflectionBasedSerializer()
Method Detail

canHandle

public boolean canHandle(SerializationEvent e)
Predicate member method to determine whether this instance should react to a given SerializationEvent. Checks if the package of the class of the item in the event is registered in the SymbolicPackageNameRegistry.

Parameters:
e - The event data.
Returns:
true iff this instance should handle the event.

serializeItem

public void serializeItem(java.lang.Object object,
                          XmlWriter writer,
                          GraphMLWriteContext context)
                   throws GraphMLWriteException

The namespace for the serialized object consists of the symbolic package name as registered in the SymbolicPackageNameRegistry for the package of this object's class.

The name of the serialized object maps the name of the object's class. If there is a ITypeConverter for the object's type registered in TypeConverters which can convert the object into a String, this String representation is written as text child node.

Otherwise all public read- and writable properties of the object are added to the xml node. If an appropriate ITypeConverter can be found via TypeConverters.getTypeConverter which can convert a property into a String, this property is written as an attributes of the resulting xml node. Otherwise it is written as a child node of the resulting xml node using an appropriate looked up serializer.

Throws:
GraphMLWriteException
See Also:
TypeConverters, ITypeConverter, SymbolicPackageNameRegistry

serializeContent

protected void serializeContent(GraphMLWriteContext context,
                                java.lang.Object object,
                                XmlWriter writer,
                                java.lang.String symbolicPackageName,
                                java.lang.String tagName)
                         throws GraphMLWriteException
Writes the actual content of the GraphML element that corresponds to the serialization of object.

Simply said: writes the XML between the start element and the end element.

Parameters:
context - The current write context.
object - The current object to be serialized.
writer - The XML writer.
symbolicPackageName - The symbolic package name, i.e. the XML namespace.
tagName - The tag name.
Throws:
GraphMLWriteException

getNamespace

protected java.lang.String getNamespace(GraphMLWriteContext context,
                                        java.lang.Object object)

getPropertyName

protected java.lang.String getPropertyName(GraphMLWriteContext context,
                                           java.beans.PropertyDescriptor property)
Returns the string that should be used for the attribute or child element when a property is serialized.

Parameters:
context - The current write context
property - A property of the object that is currently being serialized.
Returns:
The string that should be used for the attribute or child element

isCollectionProperty

protected boolean isCollectionProperty(GraphMLWriteContext context,
                                       java.lang.Object subject,
                                       java.beans.PropertyDescriptor property)
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 YList.

Parameters:
context - The current write context
subject - The object that is to be serialized
property - The descriptor of the property
Returns:
Whether the property is a collection property

getTagName

protected java.lang.String getTagName(GraphMLWriteContext context,
                                      java.lang.Object object)


Copyright © 2000-2013 yWorks GmbH. All rights reserved