y.util
Class BeanSerializer

java.lang.Object
  |
  +--y.util.BeanSerializer
All Implemented Interfaces:
ObjectStore

public class BeanSerializer
extends 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.


Constructor Summary
BeanSerializer(Class type)
          Creates a new instance of BeanSerialization for the given classtype.
 
Method Summary
 void addSerializedField(String propertyName, String mappedName)
          Adds an attribute to the list of attributes which will be serialized by this instance.
 PropertyChangeListener createPropertyAdapter(Object object, Map properties, ObjectStringConverter osc)
          constructs a PropertyChangeListener which can be registered with an instance that fires property change events, if one of the propertynames equals one of the keys, this listener will automatically store the value in the given object as the new attribute.
 void restore(Object object, 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(Object object, 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(Class type)
Creates a new instance of BeanSerialization for the given classtype. In order to make this class useful, calls to BeanSerializer.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(String propertyName,
                               String mappedName)
                        throws IntrospectionException
Adds an attribute to the list of attributes which will be serialized by this instance.

Throws:
IntrospectionException - if this method was unable to find the corresponding bean setters and getters for the attribute
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.

store

public void store(Object object,
                  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(Object object,
                    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 PropertyChangeListener createPropertyAdapter(Object object,
                                                    Map properties,
                                                    ObjectStringConverter osc)
constructs a PropertyChangeListener which can be registered with an instance that fires property change events, if one of the propertynames 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 preconfigured PropertyChangelistener which can be registered to the source

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

2003