|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.entities.Entity
public class Entity
Entity, as described by EntityInterface
, is a Java component which can have a dynamic or changing set of attributes, as opposed to the fixed set of properties
of a Java Bean.
Similar to
an EJB Entity Bean, an Entity contains data that is probably
persisted as a record in a data table/database.
Examples of entities in an eCommerce domain would be a User, a Customer,
a MailAddress, an Agent, a PurchaseOrder, a PurchaseOrderItem, etc.
An attribute can be thought of as a name/value pair where name corresponds to the attribute's name and
value is the attribute's value. The name/value pairs are stored internally in a map within the Entity.
They should not be accessed directly. A getAttribute
call should be made in order to obtain the value of an attribute.
Attributes are classified as either type-based(static) or instance-based(dynamic). Type-based attributes are those that are defined by Java Beans and the java.beans.Introspector and java.beans.BeanInfo associated with the Entity class. Instance-based attributes are those that are not defined by Java Beans.
An AttributeDescriptor can be thought of as metadata that describes an attribute (.ie a description of the
attribute, a locale-sensitive label, etc.). AttributeDescriptors are described by AttributeDescriptorInterface
.
AttributeDescriptors are grouped together in an instance of AttributeGroupInterface
Upon instantiation of an Entity, an AttributeGroup is created. There is only one root AttributeGroup
associated with an Entity. This "root" AttributeGroup cannot be removed from the Entity. AttributeDescriptors are created for all
type-based attributes (by the Entity) and are added to the AttributeGroup. Instance-based attributes can have AttributeDescriptors
created in one of two ways:
setAttribute
occurs.
AttributeDescriptor adReportName = new AttributeDescriptor("report name");
entity.getAttributeGroup().addAttributeDescriptor(adReportName, com.sas.entities.AttributeGroup.LAST_POSITION);
AttributeTypes for type-based attributes are created when the AttributeDescriptor is created. The
correct AttributeType is derived by using the java.beans.PropertyDescriptor associated with the attribute.
Instance-based attributes can have AttributeTypes created in one of two ways:
An AttributeType with sql type of Types.INTEGER would be created for the AttributeDescriptor associated with
the attribute, "intAttribute".
setAttribute
occurs.
The
setAttribute("intAttribute", new Integer(5))
AttributeDescriptor adReportName = new AttributeDescriptor("report name");
adReportName.setType(AttributeTypeFactory.STRING_ATTRIBUTE_TYPE);
AttributeTypeFactory
contains constants for creating common AttributeTypes.
getAttribute
.
The AttributeTypes associated
with these sql types attempt to simulate their corresponding primitives which
do not allow null values. If no value has been set through either a setAttribute
call or a default value has not been set on the corresponding AttributeDescriptor, false will be returned for
a sql type of Types.BOOLEAN and 0 will be returned for the others listed above.
For attributes whose AttributeType is non-boolean (Types.BOOLEAN), users can simply pass a java.util.List as a parameter to
the setAttribute
method. Use of a java.util.List
for receiving/sending multiple values would continue to allow the sql type to be used to identify the values stored
in the java.util.List (AttributeType does not have to be changed to have a sql type of Types.ARRAY).
AttributeGroupInterface
,
AttributeTypeFactory
,
AttributeTypeInterface
,
RemoteEntity
Field Summary | |
---|---|
protected java.util.Map |
dynamicSupplementalProperties
Map of supplemental properties for dynamic (instance-based properties). |
static java.lang.String |
RB_KEY
|
Constructor Summary | |
---|---|
Entity()
Constructs an instance of Entity with a unique GUID (Globally Unique Identifier) or entity key. |
|
Entity(AttributeTypeFactoryInterface atfi)
Constructs an instance of Entity with a unique GUID (Globally Unique Identifier) or entity key. |
|
Entity(java.util.Map supplementalAttributeProperties)
Constructs an instance of Entity with a unique GUID (Globally Unique Identifier) or entity key. |
|
Entity(java.util.Map supplementalAttributeProperties,
AttributeTypeFactoryInterface atfi)
Constructs an instance of Entity with a unique GUID (Globally Unique Identifier) or entity key. |
Method Summary | |
---|---|
void |
addAttributeValidator(java.lang.String attributeName,
java.beans.VetoableChangeListener listener)
Convenience method for calling addVetoableChangeListener(String propertyName, VetoableChangeListener listener) . |
void |
addVetoableChangeListener(java.lang.String propertyName,
java.beans.VetoableChangeListener listener)
Add a VetoableChangeListener for the attribute. |
void |
clear()
Clear ("unset") all attribute values. |
void |
clearAttribute(java.lang.String attributeName)
Clear ("unset") an individual attribute. |
boolean |
equals(Entity p)
Returns a boolean indicating whether the Entities are "equal". |
boolean |
equals(java.lang.Object o)
Returns a boolean indicating whether the Entities are "equal". |
void |
fireVetoableChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
Report a bound property update to any registered listeners. |
java.lang.Object |
getAttribute(java.lang.String attributeName)
Get an attribute value from the Entity. |
AttributeDescriptorInterface |
getAttributeDescriptor(java.lang.String attributeName)
Returns an AttributeDescriptor |
AttributeDescriptorInterface[] |
getAttributeDescriptors()
Returns an array of AttributeDescriptors |
AttributeGroupInterface |
getAttributeGroup()
Return a list of attributes and their descriptions. |
AttributeTypeInterface |
getAttributeType(java.lang.String attributeName)
Returns the type of an attribute. |
java.util.Map |
getAttributeValidators()
Return a map of attribute validators. |
AttributeDescriptorInterface[] |
getBooleanSpecifiedAttributeDescriptors(java.util.Map map)
Returns an array of AttributeDescriptors that meet specified boolean attribute criteria. |
java.lang.String |
getCustomizer(java.lang.String contextNotYetImplementedThusIGNORED)
Return this object's customizer. |
java.util.List |
getCustomizerContexts()
Not currently implemented |
RemoteEntityInterface |
getPrototype()
Get the prototype object from which the Entity inherits dynamic attributes from. |
java.lang.String |
getStringAttribute(java.lang.String attributeName,
java.lang.String defaultValue)
Get a string value of an attribute from the Entity. |
boolean |
isAllRequiredAttributesAssigned()
Returns true if all attributes, designated as required, have had a value assigned or the attribute has a default value. |
boolean |
isAttributeAssigned(java.lang.String attributeName)
Returns true if an attribute has had a value assigned or the attribute has a default value. |
java.util.List |
listAllRequiredAttributesNotAssigned()
Returns a list of AttributeDescriptor names where the AttributeDescriptor has been designated as required, but has not had a value assigned (a value has not been set through the setAttribute method and the AttributeDescriptor does not have a default value assigned). |
java.lang.String[] |
listAttributeNames(boolean includeDynamicAttributes,
boolean includeStaticAttributes)
Return an array of the AttributeDescriptor names. |
void |
removeAllAttributes()
Remove all attributes from the Entity. |
void |
removeAttribute(java.lang.String attributeName)
Remove an attribute from the Entity if the attribute is an instance-based attribute. |
void |
removeAttributeValidator(java.lang.String attributeName,
java.beans.VetoableChangeListener listener)
Convenience method for calling removeVetoableChangeListener(String propertyName, VetoableChangeListener listener) . |
void |
removeVetoableChangeListener(java.lang.String propertyName,
java.beans.VetoableChangeListener listener)
Remove a VetoableChangeListener for the attribute. |
void |
setCustomizer(java.lang.String contextNotYetImplementedThusIGNORED,
java.lang.String customizer)
Set the customizer for a specific context. |
void |
setDynamicSupplementalPropertiesDefaultMap(java.util.Map dynamicSupplementalProperties)
Sets the properties defined in the input map, dynamicSupplementalProperties, on all AttributeDescriptors associated with dynamic (instanced-based) attributes. |
void |
setEntityKey(java.lang.String guid)
Assign this entity's key or GUID (Globally Unique Identifier). |
void |
setPrototype(RemoteEntityInterface prototype)
Set the prototype object from which the Entity inherits dynamic attributes from. |
Methods inherited from class com.sas.entities.BaseEntity |
---|
clone, containsAttributeNamed, equals, getAttribute, getAttributeCount, getAttributes, getEntityKey, getPropertyDescriptors, listAttributeNames, reset, sameEntity, setAttribute, setAttributes, toString |
Methods inherited from interface com.sas.entities.RemoteEntityInterface |
---|
getEntityKey, sameEntity |
Methods inherited from interface com.sas.entities.RemoteBaseEntityInterface |
---|
containsAttributeNamed, getAttribute, getAttributes, listAttributeNames, setAttributes |
Methods inherited from interface com.sas.entities.RemoteBaseEntityValueInterface |
---|
setAttribute |
Field Detail |
---|
public static final java.lang.String RB_KEY
protected java.util.Map dynamicSupplementalProperties
Constructor Detail |
---|
public Entity()
property
parameter for all
AttributeDescriptors associated with static (type-based) attributes to true.
public Entity(java.util.Map supplementalAttributeProperties)
property
parameter for all
AttributeDescriptors associated with static (type-based) attributes to true.
Sets the properties defined in the input map,
supplementalAttributeProperties, on all AttributeDescriptors
associated with static (type-based) attributes.
supplementalAttributeProperties
- name/value pairs of
supplemental propertiespublic Entity(AttributeTypeFactoryInterface atfi)
property
parameter for all
AttributeDescriptors associated with static (type-based) attributes to true.
Uses the input AttributeTypeFactory, atfi, for creating
AttributeTypes for the AttributeDescriptors.
atfi
- instance of AttributeTypeFactoryInterfacepublic Entity(java.util.Map supplementalAttributeProperties, AttributeTypeFactoryInterface atfi)
property
parameter for all
AttributeDescriptors associated with static (type-based) attributes to true.
Sets the properties defined in the input map,
supplementalAttributeProperties, on all AttributeDescriptors
associated with static (type-based) attributes.
Uses the input AttributeTypeFactory, atfi, for creating
AttributeTypes for the AttributeDescriptors.
supplementalAttributeProperties
- name/value pairs of
supplemental propertiesatfi
- instance of AttributeTypeFactoryInterfaceMethod Detail |
---|
public void setEntityKey(java.lang.String guid)
setEntityKey
in interface EntityKeyInterface
setEntityKey
in interface RemoteEntityInterface
setEntityKey
in class BaseEntity
guid
- a unique entity key also known as a globally unique identifer (GUID)
java.lang.IllegalStateException
- subclasses may throw an IllegalStateException if this
Entity already has a GUID although this base class method does notBaseEntity.getEntityKey()
public boolean equals(Entity p)
p
- the Entity to compare
public boolean equals(java.lang.Object o)
equals
in class BaseEntity
o
- the object to compare
public java.lang.String getCustomizer(java.lang.String contextNotYetImplementedThusIGNORED)
RemoteEntityInterface
getCustomizer
in interface RemoteEntityInterface
contextNotYetImplementedThusIGNORED
- the context, such as a Java, COM, or WEB context
EntityContextInterface
public void setCustomizer(java.lang.String contextNotYetImplementedThusIGNORED, java.lang.String customizer)
RemoteEntityInterface
setCustomizer
in interface RemoteEntityInterface
contextNotYetImplementedThusIGNORED
- the context, such as a Java, COM, or WEB contextcustomizer
- the name of the customizerEntityContextInterface
public java.util.List getCustomizerContexts()
getCustomizerContexts
in interface RemoteEntityInterface
public void addAttributeValidator(java.lang.String attributeName, java.beans.VetoableChangeListener listener)
addVetoableChangeListener(String propertyName, VetoableChangeListener listener)
.
addAttributeValidator
in interface RemoteEntityInterface
attributeName
- name of the attributelistener
- object that implements VetoableChangeListenerpublic void removeAttributeValidator(java.lang.String attributeName, java.beans.VetoableChangeListener listener)
removeVetoableChangeListener(String propertyName, VetoableChangeListener listener)
.
removeAttributeValidator
in interface RemoteEntityInterface
RemoteEntityInterface.addAttributeValidator(String, VetoableChangeListener)
public java.util.Map getAttributeValidators()
getAttributeValidators
in interface RemoteEntityInterface
public AttributeGroupInterface getAttributeGroup()
RemoteEntityInterface
getAttributeGroup
in interface RemoteEntityInterface
AttributeGroupInterface
from which you can access
each attribute by name or get them all as an array.
AttributeGroupInterface provides a structured, hierarchical grouping of an Entity's
attributes.public RemoteEntityInterface getPrototype()
RemoteEntityInterface
getPrototype
in interface RemoteEntityInterface
public void setPrototype(RemoteEntityInterface prototype)
RemoteEntityInterface
setPrototype
in interface RemoteEntityInterface
prototype
- object from which the Entity inherits dynamic attributes frompublic AttributeTypeInterface getAttributeType(java.lang.String attributeName)
RemoteEntityInterface
getAttributeType
in interface RemoteEntityInterface
attributeName
- attribute name
AttributeTypeInterface
public java.lang.String getStringAttribute(java.lang.String attributeName, java.lang.String defaultValue)
BaseEntityInterface
BaseEntityValueInterface.getAttribute(String)
.
getStringAttribute
in interface BaseEntityInterface
getStringAttribute
in interface RemoteBaseEntityInterface
getStringAttribute
in class BaseEntity
attributeName
- the name of the valuedefaultValue
- a default value to return if the named attribute,
attributeName does not exist in the Entity
public java.lang.Object getAttribute(java.lang.String attributeName) throws java.util.NoSuchElementException
BaseEntityValueInterface
getAttribute
in interface BaseEntityValueInterface
getAttribute
in interface RemoteBaseEntityValueInterface
getAttribute
in class BaseEntity
attributeName
- the name of the value
java.util.NoSuchElementException
- if there
is no such value in the Entity
(this is necessary to distinguish between
no such attributeName and a value of null)public java.util.List listAllRequiredAttributesNotAssigned()
public void removeAttribute(java.lang.String attributeName)
BaseEntityInterface
BaseEntityInterface.containsAttributeNamed(String)
will return false
and BaseEntityValueInterface.getAttribute(String)
will throw a NoSuchElementException
removeAttribute
in interface BaseEntityInterface
removeAttribute
in interface RemoteBaseEntityInterface
removeAttribute
in class BaseEntity
attributeName
- the name of the attributepublic void removeAllAttributes()
BaseEntityInterface
removeAllAttributes
in interface BaseEntityInterface
removeAllAttributes
in interface RemoteBaseEntityInterface
removeAllAttributes
in class BaseEntity
public AttributeDescriptorInterface[] getAttributeDescriptors()
RemoteEntityInterface
getAttributeDescriptors
in interface RemoteEntityInterface
public AttributeDescriptorInterface getAttributeDescriptor(java.lang.String attributeName) throws java.util.NoSuchElementException
RemoteEntityInterface
getAttributeDescriptor
in interface RemoteEntityInterface
java.util.NoSuchElementException
- if there
is no such value in this entity
(this is necessary to distinguish between
no such attributeName and a value of null)public boolean isAttributeAssigned(java.lang.String attributeName) throws java.util.NoSuchElementException
RemoteEntityInterface
isAttributeAssigned
in interface RemoteEntityInterface
java.util.NoSuchElementException
- if there
is no such value in the Entity
(this is necessary to distinguish between
no such attributeName and a value of null)public AttributeDescriptorInterface[] getBooleanSpecifiedAttributeDescriptors(java.util.Map map) throws java.lang.NoSuchMethodException
RemoteEntityInterface
HashMap map = new HashMap(); map.put(AttributeDescriptorInterface.MODIFIABLE,Boolean.FALSE); map.put(AttributeDescriptorInterface.VISIBLE,Boolean.TRUE); try { RemoteEntity rentity = new RemoteEntity(); AttributeDescriptorInterface[] adi = rentity.getBooleanSpecifiedAttributeDescriptors(map); } catch(NoSuchMethodException e) {}
getBooleanSpecifiedAttributeDescriptors
in interface RemoteEntityInterface
map
- set of name/value pairs consisting of attribute/value
java.lang.NoSuchMethodException
- if method does not exist on the AttributeDescriptorInterfaceAttributeDescriptorInterface
public boolean isAllRequiredAttributesAssigned()
RemoteEntityInterface
isAllRequiredAttributesAssigned
in interface RemoteEntityInterface
public void clear()
RemoteEntityInterface
clear
in interface RemoteEntityInterface
public void clearAttribute(java.lang.String attributeName)
RemoteEntityInterface
clearAttribute
in interface RemoteEntityInterface
public java.lang.String[] listAttributeNames(boolean includeDynamicAttributes, boolean includeStaticAttributes)
BaseEntityValueInterface.setAttribute(String attributeName, Object value)
method.
If set to true, this method will return the name of any
AttributeDescriptor that meets either of the following:
BaseEntityValueInterface.setAttribute(String attributeName, Object value)
(dynamic attribute) OR
If set to false, this method will return the names of only those attributes that
have been explicitly created through the BaseEntityValueInterface.setAttribute(String attributeName, Object value)
method.
The boolean parameter, includeStaticAttributes, indicates whether to include static (type-based) attributes. If set to true, this method will return the name of any AttributeDescriptor that corresponds to a type-based attribute. If set to false, this method will not return any type-based attribute names.
includeDynamicAttributes
- indicates whether to include instance-based
attributes that have not been explicitly createdincludeStaticDescriptors
- indicates whether to include type-based
attributes
public void addVetoableChangeListener(java.lang.String propertyName, java.beans.VetoableChangeListener listener)
propertyName
- attribute namelistener
- instance of VetoableChangeListenerpublic void removeVetoableChangeListener(java.lang.String propertyName, java.beans.VetoableChangeListener listener)
propertyName
- name of the attributelistener
- instance of VetoableChangeListenerpublic void fireVetoableChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
propertyName
- name of the attribute that was changedoldValue
- old value of the attributenewValue
- new value of the attributepublic void setDynamicSupplementalPropertiesDefaultMap(java.util.Map dynamicSupplementalProperties)
setAttribute
method.
dynamicSupplementalProperties
- name/value pairs of
supplemental properties
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |