|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.entities.AggregateEntity
public class AggregateEntity
AggregateEntity is a collection of entities that function as a single Entity object. AggregateEntity is often used in visual displays (property sheets) because of its ability to map its attribute values to the underlying entities that comprise it.
AggregateEntity ae = new AggregateEntity(); EntityInterface entityOne = new Entity(); entityOne.setAttribute("season", "spring"); entityOne.setAttribute("month", "May"); entityOne.setAttribute("foo", "someValue"); EntityInterface entityTwo = new Entity(); entityTwo.setAttribute("season", "summer"); entityTwo.setAttribute("month", "July"); entityTwo.setAttribute("year", "2002"); ae.addEntity(entityOne, "entityOne"); ae.addEntity(entityTwo, "entityTwo");
The AggregateEntity maintains an "association map" that is used to associate AttributeDescriptors to the entities that they were obtained from. The keys in the "association map" are the names of the AttributeDescriptors. The value associated with a key is a list of EntityAttrs. EntityAttr is a complex object created by specifying an EntityInterface and the name of the AttributeDescriptor (EntityAttr).
AttributeDescriptor Association Map | |||||||
AttributeDescriptor | EntityInterface+ AttributeDescriptor Name (EntityAttr) | ||||||
season |
| ||||||
month |
| ||||||
foo |
| ||||||
year |
|
getEntityInterface()
:
AggregateEntity ae = new AggregateEntity(); EntityInterface ei = ae.getEntityInterface(); ei.setAttribute("season", "autumn");
The action, setAttribute("season", autumn"), will cause all AttributeDescriptors associated with the AttributeDescriptor key, "season", to be updated with the new value of "autumn". The attribute value for "season" for both entityOne and entityTwo will now be "autumn".
When an Entity is added to the AggregateEntity, the entity is queried for a list of its AttributeDescriptors. Keys are created in the "association map" for each unique AttributeDescriptor name and an EntityAttr is created for the entity and is mapped to the key. This occurs automatically (no user action needed to create the association map). However, this may not be desired. A user may wish to remove an EntityAttr for a particular AttributeDescriptor key. Referring to the example in Creating an AggregateEntity, we will "disassociate" the "season" attribute for entityTwo. Setting the attribute "season" for the AggregateEntity will no longer effect the value of "season" for entityTwo:
EntityAttr seasonAttr = new EntityAttr(entityTwo, "season"); ae.removeFromKeyList("season",seasonAttr);
Referring to the example in Creating an AggregateEntity, we will associate the attribute, "foo" in
entityOne with the AggregateEntity attribute,"year". Any change to the AggregateEntity attribute, "year",
is automatically reflected in the attribute, "year", of entityOne (assuming that it was not explicitly
removed through
removeFromKeyList( String key, EntityAttr item )
).
To associate the attribute, "foo", of entityOne to the AggregateEntity attribute, "year", we need to
add an entry for "foo" to the association map:
EntityAttr fooAttr = new EntityAttr(entityOne, "foo"); ae.addToKeyList("year", fooAttr, -1);
Any changes to the value of the AggregateEntity attribute, "year" will be reflected in the value of "year" in entityTwo as well as "foo" in entityOne.
AttributeDescriptor Association Map | ||||
month |
|
After adding entityTwo, the AttributeDescriptorMap entry for "month" would look as follows:
AttributeDescriptor Association Map | |||||||
month |
|
The initial value of "month" can be changed by invoking
moveBetweenKeyLists( String keyFrom, String keyTo, EntityAttr item, int index
to reorder the list of EntityAttrs:
EntityAttr monthAttr = new EntityAttr(entityTwo, "month"); ae.moveBetweenKeyLists("month","month",monthAttr,0); //move this to the top of the list
AttributeDescriptor Association Map | |||||||
month |
|
AggregateEntity ae = new AggregateEntity(); EntityInterface entityOne = new Entity(); EntityInterface entityTwo = new Entity(); ae.addEntity(entityOne, "entityOne"); ae.addEntity(entityTwo, "entityTwo"); //persist the individual entities and the AggregateEntity //using the EntityPersistenceUtility and the //AggregateEntityPersistenceUtility String sEntityOne = EntityPersistenceUtility.writeXMLToString(entityOne); String sEntityTwo = EntityPersistenceUtility.writeXMLToString(entityTwo); String sAgg = AggregateEntityPersistenceUtility.writeXMLToString(ae); //recreate the individual entities and the AggregateEntity EntityInterface newEntityOne = EntityPersistenceUtility.createEntityFromXML(sEntityOne); EntityInterface newEntityTwo = EntityPersistenceUtility.createEntityFromXML(sEntityTwo); AggregateEntity newAe = AggregateEntityPersistenceUtility.createEntityFromXML(sAgg); //associate ("relink") the individual entities to the AggregateEntity boolean newEntityOneStatus = newAe.relink(newEntityOne); boolean newEntityTwoStatus = newAe.relink(newEntityTwo); boolean allStatus = newAe.validateRelink();
Constructor Summary | |
---|---|
AggregateEntity()
Default constructor. |
|
AggregateEntity(java.lang.String name)
Constructor that specifies the AggregateEntity's name. |
Method Summary | |
---|---|
void |
addEntity(EntityInterface entity,
java.lang.String entityName)
Add an Entity to the AggregateEntity. |
void |
addEntityKey(java.lang.String entityKey,
java.lang.String entityName)
Add an entity key to the aggregate. |
void |
addToKeyList(java.lang.String key,
EntityAttr item,
int index)
Add an entry to the AttributeDescriptor "association map". |
java.util.Map |
getEntities()
Returns a map of entities that have been added to the AggregateEntity. |
EntityInterface |
getEntityInterface()
Returns an EntityInterface interface that can be used to invoke "entity methods" on the AggregateEntity. |
java.util.ArrayList |
getKeyList(java.lang.String key)
Returns the ordered list of EntityAttrs(EntityInterface + AttributeDescriptor name) for a specific AttributeDescriptor key. |
javax.swing.tree.TreeModel |
getMappingTreeModel()
Returns a TreeModel interface to be used to display the mappings in the AggregateEntity. |
java.lang.String[] |
getMissingEntities()
Returns an array of entityKeys corresponding to the individual entities that were not successfully relinked. |
java.lang.String |
getName()
Returns the AggregateEntity's name. |
void |
moveBetweenKeyLists(java.lang.String keyFrom,
java.lang.String keyTo,
EntityAttr item,
int index)
Move an EntityAttr (EntityInterface + AttributeDescriptor name) from one AttributeDescriptor key to another. |
void |
refreshModelListeners()
Fires a TreeStructureChangeEvent to all of the listeners on the model to notify them of a change. |
boolean |
relink(EntityInterface entity)
Associates an individual entity to the AggregateEntity. |
void |
removeEntity(EntityInterface entity)
Remove an Entity from the AggregateEntity. |
void |
removeFromKeyList(java.lang.String key,
EntityAttr item)
Remove an EntityAttr (EntityInterface + AttributeDescriptor name) from the AttributeDescriptor "association map". |
void |
setName(java.lang.String name)
Sets the AggregateEntity's name. |
java.lang.String |
toString()
Returns the AggregateEntity's name. |
boolean |
validateRelink()
Returns a boolean indicating whether all of the individual entities associated with the AggregateEntity were successfully relinked. |
Constructor Detail |
---|
public AggregateEntity()
public AggregateEntity(java.lang.String name)
name
- name associated with the AggregateEntityMethod Detail |
---|
public java.util.Map getEntities()
public void setName(java.lang.String name)
name
- AggregateEntity namegetName()
public java.lang.String getName()
setName(String name)
public java.lang.String toString()
toString
in class java.lang.Object
setName(String name)
public void addEntityKey(java.lang.String entityKey, java.lang.String entityName)
String
- entityKey to be addedString
- entityName to show for that entitypublic void addEntity(EntityInterface entity, java.lang.String entityName)
entity
- instance of EntityInterface to be added to the AggregateEntityentityName
- name associated with the instance of EntityInterfacepublic void removeEntity(EntityInterface entity)
entity
- instance of EntityInterface to be removedpublic void addToKeyList(java.lang.String key, EntityAttr item, int index)
|
  |
|
AttributeDescriptor Association Map | |||||||
foregroundColor |
| ||||||
style |
| ||||||
backgroundColor |
|
key
- AttributeDescriptor nameitem
- instance of EntityAttr (EntityInterface + AttributeDescriptor name)index
- location for adding the item (-1 = last position)public void removeFromKeyList(java.lang.String key, EntityAttr item)
key
- AttributeDescriptor nameitem
- instance of EntityAttr (EntityInterface + AttributeDescriptor name)public void moveBetweenKeyLists(java.lang.String keyFrom, java.lang.String keyTo, EntityAttr item, int index)
keyFrom
- the name of the AttributeDescriptor that the entry is removed fromkeyTo
- the name of the AttributeDescriptor that the entry is added toitem
- instance of EntityAttr (EntityInterface + AttributeDescriptor name)
that is to be movedindex
- location in the target listpublic java.util.ArrayList getKeyList(java.lang.String key)
key
- name of the AttributeDescriptor
public javax.swing.tree.TreeModel getMappingTreeModel()
public EntityInterface getEntityInterface()
EntityInterface
public void refreshModelListeners()
public boolean relink(EntityInterface entity)
AggregateEntity ae = new AggregateEntity(); EntityInterface entityOne = new Entity(); EntityInterface entityTwo = new Entity(); ae.addEntity(entityOne, "entityOne"); ae.addEntity(entityTwo, "entityTwo"); //persist the individual entities and the AggregateEntity //using the EntityPersistenceUtility and the //AggregateEntityPersistenceUtility String sEntityOne = EntityPersistenceUtility.writeXMLToString(entityOne); String sEntityTwo = EntityPersistenceUtility.writeXMLToString(entityTwo); String sAgg = AggregateEntityPersistenceUtility.writeXMLToString(ae); //recreate the individual entities and the AggregateEntity EntityInterface newEntityOne = EntityPersistenceUtility.createEntityFromXML(sEntityOne); EntityInterface newEntityTwo = EntityPersistenceUtility.createEntityFromXML(sEntityTwo); AggregateEntity newAe = AggregateEntityPersistenceUtility.createEntityFromXML(sAgg); //associate ("relink") the individual entities to the AggregateEntity boolean newEntityOneStatus = newAe.relink(newEntityOne); boolean newEntityTwoStatus = newAe.relink(newEntityTwo); boolean allStatus = newAe.validateRelink();
entity
- instance of EntityInterface
public boolean validateRelink()
relink(com.sas.entities.EntityInterface)
public java.lang.String[] getMissingEntities()
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |