com.endeca.portal.attributes.model
Class BasePropertyContainer

java.lang.Object
  extended by com.endeca.portal.attributes.model.BasePropertyContainer
Direct Known Subclasses:
Attribute, Group

public abstract class BasePropertyContainer
extends java.lang.Object

Base class representing a container of properties (in the meta sense, not in the sense of MDEX property). It is essentially a container for an object dictionary, which can contain arbitrary terms but also has a special identifier term named "key" (not to be confused with the HashMap key).

Author:
Endeca Technologies, Inc

Field Summary
static java.lang.String KEY_PROPERTY
          Name of the property that serves as the identifier for all BPC objects TODO: Should this be overridable by sub-classes?
protected  java.util.HashMap<java.lang.String,java.lang.Object> properties
           
 
Constructor Summary
BasePropertyContainer()
           
 
Method Summary
 void addProperty(java.lang.String propKey, java.lang.Object propValue)
           
 java.lang.String getKey()
           
 java.util.HashMap<java.lang.String,java.lang.Object> getProperties()
           
 java.lang.Object getProperty(java.lang.String property)
           
<T> T
getProperty(java.lang.String property, T defaultValue)
          This is a type-safe and null-safe method to extract a property from a BPC.
 boolean isEmpty()
           
 boolean isValid()
           
 void setKey(java.lang.String key)
           
 void setProperties(java.util.HashMap<java.lang.String,java.lang.Object> properties)
           
 java.lang.String toString()
          this toString() is pretty expensive!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_PROPERTY

public static final java.lang.String KEY_PROPERTY
Name of the property that serves as the identifier for all BPC objects TODO: Should this be overridable by sub-classes? This may be useful if we ever decided that the key property for groups is named differently than the key property for attributes (unlikely). However, overriding static members is very cumbersome in Java and differentiating key properties will lead to other areas of the code becoming difficult.

See Also:
Constant Field Values

properties

protected java.util.HashMap<java.lang.String,java.lang.Object> properties
Constructor Detail

BasePropertyContainer

public BasePropertyContainer()
Method Detail

setKey

public void setKey(java.lang.String key)
Parameters:
key - the key to set

getKey

public java.lang.String getKey()
Returns:
the value of the key property associated with this object. The name of the Key property is defined by KEY_PROPERTY

isValid

public boolean isValid()
Returns:
true if this object has a non-blank "key" property.

isEmpty

public boolean isEmpty()
Returns:
true if the list of properties is empty or if "key" is the only property, false otherwise.

setProperties

public void setProperties(java.util.HashMap<java.lang.String,java.lang.Object> properties)
Parameters:
properties - the properties to set

addProperty

public void addProperty(java.lang.String propKey,
                        java.lang.Object propValue)

getProperties

public java.util.HashMap<java.lang.String,java.lang.Object> getProperties()
Returns:
the properties. These properties are NOT related to the MDEX Record Properties.

getProperty

public java.lang.Object getProperty(java.lang.String property)

getProperty

public <T> T getProperty(java.lang.String property,
                         T defaultValue)
This is a type-safe and null-safe method to extract a property from a BPC. It takes an additional parameter, which defines the default value to be returned, and also provides information about the expected type of the returned property.

Type Parameters:
T - inferred at compile-time from the type of defaultValue
Parameters:
property - - name of the property to be returned
defaultValue - - a default value to be returned when the property is invalid
Returns:
the value of the specified property if it exists, is not null, and is of the same type as defaultValue or is a subtype of the defaultValue's type. Otherwise it returns defaultValue. One exception is that if defaultValue is null, the property value will be returned without performing type checks.

toString

public java.lang.String toString()
this toString() is pretty expensive! Use it only for debugging; don't use in performance-intensive code blocks.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()