Search this API

y.util
Class BeanSerializer

java.lang.Object
  extended by y.util.BeanSerializer
All Implemented Interfaces:
ObjectStore

public class BeanSerializer
extends java.lang.Object
implements ObjectStore

This class is a simple implementation for automatic object string conversion. It implements the ObjectStore interface and performs attribute string conversion using reflection mechanisms.

 
Your browser does not support SVG content.

Constructor Summary
BeanSerializer(java.lang.Class type)
          Creates a new instance of BeanSerialization for the given class type.
 
Method Summary
 void addSerializedField(java.lang.String propertyName, java.lang.String mappedName)
          Adds an attribute to the list of attributes which will be serialized by this instance.
 java.beans.PropertyChangeListener createPropertyAdapter(java.lang.Object object, java.util.Map properties, ObjectStringConverter osc)
          constructs a PropertyChangeListener which can be registered with an instance that fires property change events, if one of the property names equals one of the keys, this listener will automatically store the value in the given object as the new attribute.
 void restore(java.lang.Object object, java.util.Map properties, ObjectStringConverter conversion)
          This method takes an object, uses the supplied converter to restore its attributes stored in the propertyMap using the converter to do the string to object conversion.
 void store(java.lang.Object object, java.util.Map properties, ObjectStringConverter conversion)
          This method takes an object, uses the supplied converter to transform the attributes of the object into string values and puts the attribute-name string-value pairs in the supplied propertyMap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanSerializer

public BeanSerializer(java.lang.Class type)
Creates a new instance of BeanSerialization for the given class type. In order to make this class useful, calls to addSerializedField(String, String) have to be made after the object has been instantiated.

Parameters:
type - the class type this object can handle
Method Detail

addSerializedField

public void addSerializedField(java.lang.String propertyName,
                               java.lang.String mappedName)
                        throws java.beans.IntrospectionException
Adds an attribute to the list of attributes which will be serialized by this instance.

Parameters:
propertyName - the bean name of the property
mappedName - the name or path which will be used in the map as a key to store the property to.
Throws:
java.beans.IntrospectionException - if this method was unable to find the corresponding bean setters and getters for the attribute

store

public void store(java.lang.Object object,
                  java.util.Map properties,
                  ObjectStringConverter conversion)
Description copied from interface: ObjectStore
This method takes an object, uses the supplied converter to transform the attributes of the object into string values and puts the attribute-name string-value pairs in the supplied propertyMap.

Specified by:
store in interface ObjectStore
Parameters:
object - the object whose attributes will be stored in the propertyMap
properties - the map, which contains the key value pairs, both keys and values must be Strings.
conversion - the converter, which must be used to convert simple objects to corresponding String forms

restore

public void restore(java.lang.Object object,
                    java.util.Map properties,
                    ObjectStringConverter conversion)
Description copied from interface: ObjectStore
This method takes an object, uses the supplied converter to restore its attributes stored in the propertyMap using the converter to do the string to object conversion. supplied propertyMap.

Specified by:
restore in interface ObjectStore
Parameters:
object - the object whose attributes will be restored from the propertyMap
properties - the map, which contains the key value pairs, both keys and values are Strings.
conversion - the converter, which should be used to convert the string representations to the object's attributes.

createPropertyAdapter

public java.beans.PropertyChangeListener createPropertyAdapter(java.lang.Object object,
                                                               java.util.Map properties,
                                                               ObjectStringConverter osc)
constructs a PropertyChangeListener which can be registered with an instance that fires property change events, if one of the property names equals one of the keys, this listener will automatically store the value in the given object as the new attribute.

Parameters:
object - the instance which will be used to write the attribute changes to
properties - unused for now
osc - the string to object conversion which should be used to for the conversion
Returns:
a pre-configured PropertyChangeListener which can be registered to the source

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.