Joda System API

org.joda.property
Interface Bean

All Superinterfaces:
java.lang.Cloneable, ModelElement, java.io.Serializable
All Known Subinterfaces:
Bean.Internal
All Known Implementing Classes:
AbstractBean, AbstractProxyBean

public interface Bean
extends ModelElement, java.lang.Cloneable

Bean is the interface used to mark a class as a JavaBean. When using the proxy generation technique, each bean interface must extend this one. When coding classes, each bean must extend this interface.

A Bean contains a Map of Property objects. This map is dynamic and extensible. This permits applications to add data to a bean that the original designers did not think of. This is comparable to the ability to add an element of any name to a DOM object model.

A Bean also contains a Map of String attributes. This map allows additional arbitrary data to be attached to any bean. This corresponds to the XML attribute concept. One good use for attributes is to attach an error code to the bean which caused the error during validation.

Author:
Stephen Colebourne

Nested Class Summary
static interface Bean.Internal
          Interface used during the cloning process.
 
Method Summary
 java.lang.Object cloneDeep()
          Deep clone this property.
 boolean equals(java.lang.Object anotherObject)
          Test to see if this property equal to another.
 java.lang.Class getBeanType()
          Get the bean's type.
 Property getProperty(java.lang.String propertyName)
          Get a Property object by name.
 java.util.Map getPropertyMap()
          Get the Map of Property objects.
 int hashCode()
          Get the hashCode for the property.
 java.lang.String toString()
          Get a debugging string.
 
Methods inherited from interface org.joda.property.ModelElement
getAttribute, getAttributeCount, getAttributeMap, setAttribute
 

Method Detail

getPropertyMap

public java.util.Map getPropertyMap()
Get the Map of Property objects. The map is modifiable, but care should be taken with this flexibility. It allows extra properties to be dynamically added to a Bean for example. However this also allows a Bean's real properties to be removed! Thus use the modifiability with care.

Returns:
the Map of Property objects, keyed by String property name

getProperty

public Property getProperty(java.lang.String propertyName)
Get a Property object by name. If a property does not exist, null will be returned.

Parameters:
propertyName - the name of the property to obtain
Returns:
the property, or null if none found

getBeanType

public java.lang.Class getBeanType()
Get the bean's type. This will be a Class object which implements this interface.

Returns:
the bean type

equals

public boolean equals(java.lang.Object anotherObject)
Test to see if this property equal to another. This should be implemented to check this bean's properties and recurse down the tree of associated objects.

Overrides:
equals in class java.lang.Object
Parameters:
anotherObject - another object to compare this one to
Returns:
true if the properties are equal

hashCode

public int hashCode()
Get the hashCode for the property. As Beans are typically modifiable, they do not make good keys in HashMaps/Hashtables. A typical implementation is to always return 1 from this method, which leads to inefficient but accurate HashMap behaviour providing equals() is written correctly.

Overrides:
hashCode in class java.lang.Object
Returns:
a suitable hashcode

cloneDeep

public java.lang.Object cloneDeep()
Deep clone this property. A full deep clone is performed of the bean that should equate to serialising and deserialising the bean.

Returns:
deep clone of this bean

toString

public java.lang.String toString()
Get a debugging string.

Overrides:
toString in class java.lang.Object
Returns:
debugging string

Joda System API

Copyright © 2001-2003 Stephen Colebourne. All Rights Reserved.