Holger's
Java API

com.antelmann.mgmt
Class EntityImpl

java.lang.Object
  extended by com.antelmann.mgmt.EntityImpl
All Implemented Interfaces:
Entity, Resource, Serializable
Direct Known Subclasses:
ImageHolder, RowItem, UserImpl

public class EntityImpl
extends Object
implements Entity

This class represents a default Entity implementation that can serve as a base class for Entity implementations. In addition this implementation optionally monitors changes on its properties.

Author:
Holger Antelmann
See Also:
Serialized Form

Field Summary
protected  PropertyChangeSupport propertyChangeSupport
          access to the embedded property change support; this variable is initally null (until initialized by enableChangeListenerSupport(boolean))
protected  HashMap<String,Object> props
          provides unmonitored access to the properties
 
Constructor Summary
  EntityImpl(Object id)
           
  EntityImpl(Object id, Entity entity)
          all properties from the given entity are copied into this entity; the given properties do NOT run through the property change check.
protected EntityImpl(Object id, Map<String,Object> properties)
          the given properties do NOT run through the property change check; they ought to be checked once the extending class is fully initialized
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
           
protected  void checkPropertyChange(String key, Object value)
          determines whether a property can be changed as given.
protected  boolean containsPropertyText(String text)
          searches within the property values (based on toString()) for the given text case-insensivitely
 void enableChangeListenerSupport(boolean flag)
          allows to enable/disable listener support on this object (disabled by default).
 boolean equals(Object obj)
          returns true if the given Object is an Entity, is of the same class and its id is equal
protected  boolean equalWithProperties(Entity entity)
          checks (next to equals) whether all properties are the same
 Object getID()
          returns the immutable id that is used for checking equality
 Map<String,Object> getProperties()
          generates a new view on each call
 Object getProperty(String key)
          allows access to some property; may return null if not set
 PropertyChangeListener[] getPropertyChangeListeners()
           
 int hashCode()
           
 boolean isChangeListenerSupportEnabled()
          determines whether listener support is enabled on this object (false by default)
 Object removeProperty(String key)
          removes the given key from the properties
 void removePropertyChangeListener(PropertyChangeListener listener)
           
 void setAll(Map<String,Object> map)
          all imported properties are checked by checkPropertyChange()
 Object setProperty(String key, Object value)
          removes the given property
protected  void verifyProperties()
          This default implementation simply runs all existing properties through checkPropertyChange(String, Object).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

props

protected HashMap<String,Object> props
provides unmonitored access to the properties


propertyChangeSupport

protected PropertyChangeSupport propertyChangeSupport
access to the embedded property change support; this variable is initally null (until initialized by enableChangeListenerSupport(boolean))

See Also:
enableChangeListenerSupport(boolean)
Constructor Detail

EntityImpl

public EntityImpl(Object id)

EntityImpl

public EntityImpl(Object id,
                  Entity entity)
all properties from the given entity are copied into this entity; the given properties do NOT run through the property change check. If needed, they ought to be checked once the extending class is fully initialized. checkPropertyChange()

See Also:
checkPropertyChange(String, Object)

EntityImpl

protected EntityImpl(Object id,
                     Map<String,Object> properties)
the given properties do NOT run through the property change check; they ought to be checked once the extending class is fully initialized

Method Detail

getID

public Object getID()
returns the immutable id that is used for checking equality

Specified by:
getID in interface Resource

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
returns true if the given Object is an Entity, is of the same class and its id is equal

Overrides:
equals in class Object

equalWithProperties

protected boolean equalWithProperties(Entity entity)
checks (next to equals) whether all properties are the same


getProperty

public Object getProperty(String key)
Description copied from interface: Entity
allows access to some property; may return null if not set

Specified by:
getProperty in interface Entity

verifyProperties

protected void verifyProperties()
                         throws IllegalArgumentException
This default implementation simply runs all existing properties through checkPropertyChange(String, Object). If any implementation requires to check for more (e.g. for missing properties), this method is to be overridden to provide this functionality. Within the implementation of EntityImpl, this method is never called.

Throws:
IllegalArgumentException

checkPropertyChange

protected void checkPropertyChange(String key,
                                   Object value)
                            throws IllegalArgumentException
determines whether a property can be changed as given. This method is checked on the attempt to change any property; If this method throws an IllegalArgumentException, it is propagated to the caller of setProperty() or removeProperty(). If this is called on the attempt to remove a property, the value is null. This method may be overridden to guarantee a specific consistency of all properties. The message within the IllegalArgumentException allows for specific information on why a property change would not be allowed. This implementation is plain empty, i.e. any change is allowed.

Throws:
IllegalArgumentException - if the change of the value is not to be allowed
See Also:
setProperty(String, Object), removeProperty(String)

setProperty

public Object setProperty(String key,
                          Object value)
                   throws IllegalArgumentException
Description copied from interface: Entity
removes the given property

Specified by:
setProperty in interface Entity
Returns:
the value of the property previously set if any (thus may return null)
Throws:
IllegalArgumentException - if checkPropertyChange(key, value) throws one
See Also:
checkPropertyChange(String, Object)

setAll

public void setAll(Map<String,Object> map)
all imported properties are checked by checkPropertyChange()


removeProperty

public Object removeProperty(String key)
                      throws IllegalArgumentException
Description copied from interface: Entity
removes the given key from the properties

Specified by:
removeProperty in interface Entity
Returns:
the previous value of the given key or null if previously unset
Throws:
IllegalArgumentException - if checkPropertyChange(key, value) throws one
See Also:
checkPropertyChange(String, Object)

getProperties

public Map<String,Object> getProperties()
generates a new view on each call

Specified by:
getProperties in interface Entity

containsPropertyText

protected boolean containsPropertyText(String text)
searches within the property values (based on toString()) for the given text case-insensivitely


enableChangeListenerSupport

public void enableChangeListenerSupport(boolean flag)
allows to enable/disable listener support on this object (disabled by default). Calling this method will also set the protected member propertyChangeSupport to null.

See Also:
isChangeListenerSupportEnabled()

isChangeListenerSupportEnabled

public boolean isChangeListenerSupportEnabled()
determines whether listener support is enabled on this object (false by default)

See Also:
enableChangeListenerSupport(boolean)

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
                               throws IllegalStateException
Throws:
IllegalStateException - if the listener support is not enabled on this object
See Also:
isChangeListenerSupportEnabled()

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
                                  throws IllegalStateException
Throws:
IllegalStateException - if the listener support is not enabled on this object
See Also:
isChangeListenerSupportEnabled()

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()
                                                    throws IllegalStateException
Throws:
IllegalStateException - if the listener support is not enabled on this object
See Also:
isChangeListenerSupportEnabled()


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads