summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/collection/AggregationMember.java
diff options
context:
space:
mode:
Diffstat (limited to 'source/com/c2kernel/collection/AggregationMember.java')
-rwxr-xr-xsource/com/c2kernel/collection/AggregationMember.java154
1 files changed, 154 insertions, 0 deletions
diff --git a/source/com/c2kernel/collection/AggregationMember.java b/source/com/c2kernel/collection/AggregationMember.java
new file mode 100755
index 0000000..753f503
--- /dev/null
+++ b/source/com/c2kernel/collection/AggregationMember.java
@@ -0,0 +1,154 @@
+package com.c2kernel.collection;
+
+import java.awt.Image;
+import java.util.StringTokenizer;
+
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.proxy.EntityProxy;
+import com.c2kernel.graph.model.GraphableVertex;
+import com.c2kernel.lookup.EntityPath;
+import com.c2kernel.lookup.InvalidEntityPathException;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.property.Property;
+import com.c2kernel.utils.Logger;
+import com.c2kernel.utils.Resource;
+
+/**
+* @version $Revision: 1.11 $ $Date: 2005/12/01 14:23:15 $
+* @author $Author: abranson $
+*/
+
+
+//this extends Vertex for inherit the graph visualization
+//this does not implement MemberObject anylonger. it is a java object.
+//eventually the member object corba interface will be phased out.
+public class AggregationMember extends GraphableVertex implements CollectionMember
+{
+
+ private int mEntityKey = -1;
+ private EntityProxy mEntity = null;
+ private Collection mCollection = null;
+ private String mClassProps = null;
+ String entityName;
+ Image image;
+
+
+ /**************************************************************************
+ *
+ **************************************************************************/
+ public AggregationMember()
+ {
+ super();
+ mEntityKey = -1;
+ mCollection = null;
+ }
+
+ public void setEntityKey(int entityKey) {
+ mEntityKey = entityKey;
+ entityName = null;
+ }
+
+ public void setCollection(Collection aggregation)
+ {
+ mCollection = aggregation;
+ }
+
+ public void setClassProps(String props)
+ {
+ mClassProps = props;
+ }
+
+ public int getEntityKey()
+ {
+ return mEntityKey;
+ }
+
+ public Collection getCollection()
+ {
+ return mCollection;
+ }
+
+ public String getClassProps()
+ {
+ return mClassProps;
+ }
+
+ public void assignEntity(int entityKey) throws MembershipException
+ {
+ if (entityKey > -1) {
+ if (mClassProps == null || getProperties() == null)
+ throw new MembershipException("ClassProps not yet set. Cannot check membership validity.");
+
+ //for each mandatory prop check if its in the member property and has the matching value
+ StringTokenizer sub = new StringTokenizer(mClassProps, ",");
+ while (sub.hasMoreTokens())
+ {
+ String aClassProp = sub.nextToken();
+ try {
+ String memberValue = (String)getProperties().get(aClassProp);
+ Property entityProperty = (Property)Gateway.getStorage().get(entityKey, ClusterStorage.PROPERTY+"/"+aClassProp, null);
+ if (entityProperty == null)
+ throw new MembershipException("Property "+aClassProp+ " does not exist for entityKey=" + entityKey );
+ if (entityProperty.getValue() == null || !entityProperty.getValue().equalsIgnoreCase(memberValue))
+ throw new MembershipException("Value of mandatory prop "+aClassProp+" does not match: " + entityProperty.getValue()+"!="+memberValue);
+ }
+ catch (MembershipException ex) {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ Logger.error(ex);
+ throw new MembershipException("Error checking properties");
+ }
+ }
+ }
+
+ mEntityKey = entityKey;
+ mEntity = null;
+ entityName = null;
+ }
+
+ public void clearEntity() {
+ mEntityKey = -1;
+ mEntity = null;
+ }
+
+ public EntityProxy resolveEntity() throws ObjectNotFoundException {
+ if (mEntity == null) {
+ try {
+ EntityPath path = new EntityPath(mEntityKey);
+ mEntity = Gateway.getProxyManager().getProxy(path);
+ } catch (InvalidEntityPathException ex) {
+ throw new ObjectNotFoundException("No member defined", "");
+ }
+ }
+ return mEntity;
+
+ }
+
+ public Image getImage() {
+ if (image == null) {
+ image = Resource.getImageResource("typeicons/"+getProperties().get("Type")+"_16.png").getImage();
+ }
+ return image;
+ }
+
+ public String getEntityName() {
+ if (entityName == null) {
+ if (mEntityKey > -1) {
+ try {
+ entityName = resolveEntity().getName();
+ } catch (ObjectNotFoundException ex) {
+ Logger.error(ex);
+ entityName = "Error ("+mEntityKey+")";
+ }
+ }
+ else
+ entityName = "Empty";
+ }
+
+ return entityName;
+ }
+
+}