net.infonode.properties.propertymap
Class PropertyMapImpl

java.lang.Object
  extended by net.infonode.properties.propertymap.PropertyMapImpl
All Implemented Interfaces:
PropertyMap, Readable, ReadWritable, Writable

public class PropertyMapImpl
extends java.lang.Object
implements PropertyMap

Version:
$Revision: 1.28 $
Author:
$Author: jesper $

Nested Class Summary
private  class PropertyMapImpl.PropertyObjectMap
           
 
Field Summary
private  MapAdapter childMaps
           
private  java.util.ArrayList listeners
           
private  PropertyMapImpl.PropertyObjectMap map
           
private  SignalListener mapListener
           
private  PropertyMapImpl parent
           
private  PropertyMapProperty property
           
private  java.util.HashMap propertyChangeListeners
           
private  PropertyMapGroup propertyGroup
           
private static int SERIALIZE_VERSION
           
private  ConstChangeNotifyVectorMap superMap
           
private  java.util.ArrayList superMaps
           
private  java.util.ArrayList treeListeners
           
private  ChangeNotifyMapWrapper values
           
private  ConstVectorMap vectorMap
           
 
Constructor Summary
PropertyMapImpl(PropertyMapGroup propertyGroup)
           
PropertyMapImpl(PropertyMapGroup propertyGroup, PropertyMapImpl superObject)
           
PropertyMapImpl(PropertyMapGroup propertyGroup, PropertyMapImpl parent, PropertyMapProperty property)
           
PropertyMapImpl(PropertyMapImpl inheritFrom)
           
PropertyMapImpl(PropertyMapImpl parent, PropertyMapProperty property)
           
 
Method Summary
 void addListener(PropertyMapListener listener)
          Adds a listener that listens for value changes in this PropertyMap.
private  void addParentSuperMap(PropertyMapImpl propertyObjectImpl, int parentIndex)
           
 void addPropertyChangeListener(Property property, PropertyChangeListener listener)
          Adds a property listener that listens for value changes for a specific property.
private  void addSuperMap(int index, PropertyMapImpl propertyObjectImpl)
           
 void addSuperMap(PropertyMap superMap)
          Adds a super map to this map.
private  void addSuperMap(PropertyMapImpl propertyObjectImpl)
           
 void addTreeListener(PropertyMapTreeListener listener)
          Adds a tree listener that listens for value changes in this PropertyMap or any child maps.
private  boolean checkListeners(java.util.Set visited)
           
private  void checkProperty(Property property)
           
 void clear(boolean recursive)
          Removes all property values in this property map.
 PropertyMap copy(boolean copySuperMaps, boolean recursive)
          Creates a copy of this map.
 java.lang.Object createRelativeRef(Property fromProperty, PropertyMap toObject, Property toProperty)
          Creates a relative reference from one property value to another property value.
private  void doClear(boolean recursive)
           
private  void doCopy(PropertyMapImpl map, boolean copySuperMaps, boolean recursive, boolean topMap)
           
private  void doRead(java.io.ObjectInputStream in)
           
private static void doSkip(java.io.ObjectInputStream in)
           
private  boolean doValuesEqual(PropertyMapImpl propertyObject, boolean recursive)
           
private  void doWrite(java.io.ObjectOutputStream out, boolean recursive)
           
 void dump()
           
 void dump(Printer printer, java.util.Set printed)
           
 void dumpSuperMaps(Printer printer)
           
protected  void firePropertyTreeValuesChanged(java.util.Map changes)
           
 void firePropertyValueChanged(Property property, ValueChange change)
           
(package private)  void firePropertyValuesChanged(java.util.Map changes)
           
 PropertyMap getChildMap(PropertyMapProperty property)
           
 PropertyMapImpl getChildMapImpl(PropertyMapProperty property)
           
 ConstChangeNotifyMap getMap()
           
 PropertyMapImpl getParent()
           
private  PropertyValue getParentDefaultValue(PropertyPath path)
           
private  PropertyMapRef getPathFrom(PropertyMapImpl parentObject)
           
 PropertyMapProperty getProperty()
           
 PropertyMapGroup getPropertyGroup()
           
private  PropertyMapRef getRelativePathTo(PropertyMapImpl propertyObject)
           
 PropertyMap getSuperMap()
          Returns the most recently added super map.
 int getSuperMapCount()
           
 PropertyValue getValue(Property property)
           
private  PropertyValue getValue(PropertyPath propertyPath)
           
 PropertyValue getValueWithDefault(Property property)
           
private  boolean hasListener()
           
private  boolean hasTreeListener()
           
private  PropertyValue internalSetValue(Property property, PropertyValue value)
           
 boolean isEmpty(boolean recursive)
          Returns true if this property map doesn't contain any property values.
 void read(java.io.ObjectInputStream in)
          Reads property values from a stream and sets them in this map.
 void removeListener(PropertyMapListener listener)
          Removes a listener which was previously added with PropertyMap.addListener(PropertyMapListener).
private  void removeParentSuperMap(int parentIndex)
           
 void removePropertyChangeListener(Property property, PropertyChangeListener listener)
          Removes a previously added property listener.
 PropertyMap removeSuperMap()
          Removes the most recently added super map.
private  void removeSuperMap(int index)
           
 boolean removeSuperMap(PropertyMap superMap)
          Removes a super map that has previously been added using PropertyMap.addSuperMap(PropertyMap).
 void removeTreeListener(PropertyMapTreeListener listener)
          Removes a previously added tree listener.
 java.lang.Object removeValue(Property property)
          Removes a property value.
 boolean replaceSuperMap(PropertyMap oldSuperMap, PropertyMap newSuperMap)
          Replaces a super map that has previously been added using PropertyMap.addSuperMap(PropertyMap).
 PropertyValue setValue(Property property, PropertyValue value)
           
static void skip(java.io.ObjectInputStream in)
           
private  void updateListener()
           
private  void updateListenerRecursive()
           
 boolean valueIsSet(Property property)
           
 boolean valuesEqualTo(PropertyMap propertyObject, boolean recursive)
          Returns true if all the values in this property map is equal to the values in the given map.
 void write(java.io.ObjectOutputStream out)
           Serializes the serializable values of this property map.
 void write(java.io.ObjectOutputStream out, boolean recursive)
          Serializes the serializable values of this property map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERIALIZE_VERSION

private static final int SERIALIZE_VERSION
See Also:
Constant Field Values

propertyGroup

private PropertyMapGroup propertyGroup

parent

private PropertyMapImpl parent

property

private PropertyMapProperty property

values

private ChangeNotifyMapWrapper values

superMap

private ConstChangeNotifyVectorMap superMap

vectorMap

private ConstVectorMap vectorMap

map

private PropertyMapImpl.PropertyObjectMap map

superMaps

private java.util.ArrayList superMaps

childMaps

private MapAdapter childMaps

propertyChangeListeners

private java.util.HashMap propertyChangeListeners

listeners

private java.util.ArrayList listeners

treeListeners

private java.util.ArrayList treeListeners

mapListener

private SignalListener mapListener
Constructor Detail

PropertyMapImpl

public PropertyMapImpl(PropertyMapGroup propertyGroup)

PropertyMapImpl

public PropertyMapImpl(PropertyMapImpl inheritFrom)

PropertyMapImpl

public PropertyMapImpl(PropertyMapGroup propertyGroup,
                       PropertyMapImpl superObject)

PropertyMapImpl

public PropertyMapImpl(PropertyMapImpl parent,
                       PropertyMapProperty property)

PropertyMapImpl

public PropertyMapImpl(PropertyMapGroup propertyGroup,
                       PropertyMapImpl parent,
                       PropertyMapProperty property)
Method Detail

hasTreeListener

private boolean hasTreeListener()

hasListener

private boolean hasListener()

updateListenerRecursive

private void updateListenerRecursive()

updateListener

private void updateListener()

checkListeners

private boolean checkListeners(java.util.Set visited)

getMap

public ConstChangeNotifyMap getMap()

getSuperMap

public PropertyMap getSuperMap()
Description copied from interface: PropertyMap
Returns the most recently added super map.

Specified by:
getSuperMap in interface PropertyMap
Returns:
the super map

removeValue

public java.lang.Object removeValue(Property property)
                             throws InvalidPropertyException
Description copied from interface: PropertyMap
Removes a property value.

Specified by:
removeValue in interface PropertyMap
Parameters:
property - the property
Returns:
the value removed
Throws:
InvalidPropertyException - if values for this property can't be stored in this property map

getPathFrom

private PropertyMapRef getPathFrom(PropertyMapImpl parentObject)

getRelativePathTo

private PropertyMapRef getRelativePathTo(PropertyMapImpl propertyObject)

createRelativeRef

public java.lang.Object createRelativeRef(Property fromProperty,
                                          PropertyMap toObject,
                                          Property toProperty)
Description copied from interface: PropertyMap
Creates a relative reference from one property value to another property value.

When the value of the fromProperty is read, it will return the value of the toProperty in the toMap.

Sub maps of this property map will inherit this reference relative to themselves, ie the reference in the sub map is converted to a reference relative to the sub map if possible, otherwise the reference is the same as for the super map. Here is an example:

Changes to the referenced property value will be propagated to listeners of this property.

Specified by:
createRelativeRef in interface PropertyMap
Parameters:
fromProperty - the property value that will hold the reference
toObject - the property map that holds the property value that is referenced
toProperty - the property which value is referenced
Returns:
the old value that the fromProperty had in this property map

getSuperMapCount

public int getSuperMapCount()

addSuperMap

public void addSuperMap(PropertyMap superMap)
Description copied from interface: PropertyMap
Adds a super map to this map. If a property value is not found in this property map, the super maps will be searched recursively. The super map last added will be searched first.

Specified by:
addSuperMap in interface PropertyMap
Parameters:
superMap - the super map

removeSuperMap

public PropertyMap removeSuperMap()
Description copied from interface: PropertyMap
Removes the most recently added super map.

Specified by:
removeSuperMap in interface PropertyMap
Returns:
the super map removed

removeSuperMap

public boolean removeSuperMap(PropertyMap superMap)
Description copied from interface: PropertyMap
Removes a super map that has previously been added using PropertyMap.addSuperMap(PropertyMap).

Specified by:
removeSuperMap in interface PropertyMap
Parameters:
superMap - the super map to remove
Returns:
true if the super map was found and removed, otherwise false

replaceSuperMap

public boolean replaceSuperMap(PropertyMap oldSuperMap,
                               PropertyMap newSuperMap)
Description copied from interface: PropertyMap
Replaces a super map that has previously been added using PropertyMap.addSuperMap(PropertyMap).

Specified by:
replaceSuperMap in interface PropertyMap
Parameters:
oldSuperMap - the super map to replace
newSuperMap - the super map to replace it with
Returns:
true if the super map was found and replaced, otherwise false

removeParentSuperMap

private void removeParentSuperMap(int parentIndex)

removeSuperMap

private void removeSuperMap(int index)

addSuperMap

private void addSuperMap(PropertyMapImpl propertyObjectImpl)

addParentSuperMap

private void addParentSuperMap(PropertyMapImpl propertyObjectImpl,
                               int parentIndex)

addSuperMap

private void addSuperMap(int index,
                         PropertyMapImpl propertyObjectImpl)

addTreeListener

public void addTreeListener(PropertyMapTreeListener listener)
Description copied from interface: PropertyMap
Adds a tree listener that listens for value changes in this PropertyMap or any child maps. This listener will be notified of updates to values in this PropertyMap, any child map recusively and super maps unless the property value is overridden.

Specified by:
addTreeListener in interface PropertyMap
Parameters:
listener - the listener

removeTreeListener

public void removeTreeListener(PropertyMapTreeListener listener)
Description copied from interface: PropertyMap
Removes a previously added tree listener.

Specified by:
removeTreeListener in interface PropertyMap
Parameters:
listener - the listener

addListener

public void addListener(PropertyMapListener listener)
Description copied from interface: PropertyMap
Adds a listener that listens for value changes in this PropertyMap. This listener will be notified of updates to values in this PropertyMap and super maps unless the property value is overridden.

Specified by:
addListener in interface PropertyMap
Parameters:
listener - the listener

removeListener

public void removeListener(PropertyMapListener listener)
Description copied from interface: PropertyMap
Removes a listener which was previously added with PropertyMap.addListener(PropertyMapListener).

Specified by:
removeListener in interface PropertyMap
Parameters:
listener - the listener

getPropertyGroup

public PropertyMapGroup getPropertyGroup()

addPropertyChangeListener

public void addPropertyChangeListener(Property property,
                                      PropertyChangeListener listener)
Description copied from interface: PropertyMap
Adds a property listener that listens for value changes for a specific property. This listener will be notified of value changes for the property in this PropertyMap and super maps unless the property value is overridden.

Specified by:
addPropertyChangeListener in interface PropertyMap
Parameters:
property - the property to listen to changes on
listener - the listener

removePropertyChangeListener

public void removePropertyChangeListener(Property property,
                                         PropertyChangeListener listener)
Description copied from interface: PropertyMap
Removes a previously added property listener.

Specified by:
removePropertyChangeListener in interface PropertyMap
Parameters:
property - the property which the listener listens to changes on
listener - the listener

getParent

public PropertyMapImpl getParent()

getProperty

public PropertyMapProperty getProperty()

checkProperty

private void checkProperty(Property property)

getChildMap

public PropertyMap getChildMap(PropertyMapProperty property)

getChildMapImpl

public PropertyMapImpl getChildMapImpl(PropertyMapProperty property)

getParentDefaultValue

private PropertyValue getParentDefaultValue(PropertyPath path)

getValueWithDefault

public PropertyValue getValueWithDefault(Property property)

getValue

private PropertyValue getValue(PropertyPath propertyPath)

getValue

public PropertyValue getValue(Property property)

internalSetValue

private PropertyValue internalSetValue(Property property,
                                       PropertyValue value)

setValue

public PropertyValue setValue(Property property,
                              PropertyValue value)

valueIsSet

public boolean valueIsSet(Property property)

firePropertyValueChanged

public void firePropertyValueChanged(Property property,
                                     ValueChange change)

firePropertyTreeValuesChanged

protected void firePropertyTreeValuesChanged(java.util.Map changes)

firePropertyValuesChanged

void firePropertyValuesChanged(java.util.Map changes)

dump

public void dump()

dump

public void dump(Printer printer,
                 java.util.Set printed)

dumpSuperMaps

public void dumpSuperMaps(Printer printer)

clear

public void clear(boolean recursive)
Description copied from interface: PropertyMap
Removes all property values in this property map.

Specified by:
clear in interface PropertyMap
Parameters:
recursive - true if child maps should be cleared recursively

doClear

private void doClear(boolean recursive)

isEmpty

public boolean isEmpty(boolean recursive)
Description copied from interface: PropertyMap
Returns true if this property map doesn't contain any property values.

Specified by:
isEmpty in interface PropertyMap
Parameters:
recursive - true if child maps should be recursively checked
Returns:
true if this property map doesn't contain any property values

doRead

private void doRead(java.io.ObjectInputStream in)
             throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.io.ObjectOutputStream out,
                  boolean recursive)
           throws java.io.IOException
Description copied from interface: PropertyMap
Serializes the serializable values of this property map. Values not implementing the Serializable interface will not be written to the stream. The properties are identified using their names.

Specified by:
write in interface PropertyMap
Parameters:
out - the stream on which to serialize this map
recursive - true if child maps should be recursively serialized
Throws:
java.io.IOException - if there is an error in the stream

write

public void write(java.io.ObjectOutputStream out)
           throws java.io.IOException
Description copied from interface: PropertyMap

Serializes the serializable values of this property map. Values not implementing the Serializable interface will not be written to the stream. The properties are identified using their names.

This method recursively writes all child maps.

Specified by:
write in interface PropertyMap
Specified by:
write in interface Writable
Parameters:
out - the stream
Throws:
java.io.IOException - if there is a stream error

doWrite

private void doWrite(java.io.ObjectOutputStream out,
                     boolean recursive)
              throws java.io.IOException
Throws:
java.io.IOException

read

public void read(java.io.ObjectInputStream in)
          throws java.io.IOException
Description copied from interface: PropertyMap
Reads property values from a stream and sets them in this map. Will overwrite existing values, but not remove values not found in the stream. The properties are identified using their names. If no property is found for a property name read from the stream the value is skipped and no error is reported. If a value for a property in the stream is a reference to a another property value that cannot be resolved, the property is not modified.

Specified by:
read in interface PropertyMap
Specified by:
read in interface Readable
Parameters:
in - the stream from which to read property values
Throws:
java.io.IOException - if there is an error in the stream

skip

public static void skip(java.io.ObjectInputStream in)
                 throws java.io.IOException
Throws:
java.io.IOException

doSkip

private static void doSkip(java.io.ObjectInputStream in)
                    throws java.io.IOException
Throws:
java.io.IOException

doValuesEqual

private boolean doValuesEqual(PropertyMapImpl propertyObject,
                              boolean recursive)

valuesEqualTo

public boolean valuesEqualTo(PropertyMap propertyObject,
                             boolean recursive)
Description copied from interface: PropertyMap
Returns true if all the values in this property map is equal to the values in the given map. The property values are compared using Object.equals(java.lang.Object).

Specified by:
valuesEqualTo in interface PropertyMap
Parameters:
propertyObject - the map to compare values with
recursive - true if child maps should be recursively checked
Returns:
true if all the values in this property map is equal to the values in the given map

copy

public PropertyMap copy(boolean copySuperMaps,
                        boolean recursive)
Description copied from interface: PropertyMap
Creates a copy of this map. The method copies the values and optionally the references to super maps.

Specified by:
copy in interface PropertyMap
Parameters:
copySuperMaps - if true, copies the references to super maps
recursive - if true, copies all child maps as well
Returns:
a copy of this map

doCopy

private void doCopy(PropertyMapImpl map,
                    boolean copySuperMaps,
                    boolean recursive,
                    boolean topMap)