diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2012-07-30 22:03:28 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2012-07-30 22:03:28 +0200 |
| commit | 409741e181838b3712c17d858b3ea594976de623 (patch) | |
| tree | 58b5df049d46dd55718347416c36111950abeaf9 | |
| parent | ce633a2dc86f663fb35fd7ec4efb679c81ae138b (diff) | |
Remove RelationshipUtils. Move getIsComposite method into Aggregation
where it is used.
Separate slot adding from member assignment in Aggregation.
| -rw-r--r-- | src/main/java/com/c2kernel/collection/Aggregation.java | 70 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/collection/RelationshipUtils.java | 33 |
2 files changed, 53 insertions, 50 deletions
diff --git a/src/main/java/com/c2kernel/collection/Aggregation.java b/src/main/java/com/c2kernel/collection/Aggregation.java index 9c7b4ce..063eb77 100644 --- a/src/main/java/com/c2kernel/collection/Aggregation.java +++ b/src/main/java/com/c2kernel/collection/Aggregation.java @@ -2,9 +2,14 @@ package com.c2kernel.collection; import com.c2kernel.collection.gui.model.AggregationVertexOutlineCreator;
+import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.graph.model.GraphModel;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
+import com.c2kernel.lookup.EntityPath;
+import com.c2kernel.lookup.InvalidEntityPathException;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.process.Gateway;
import com.c2kernel.utils.CastorHashMap;
import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
@@ -67,27 +72,39 @@ abstract public class Aggregation extends Parent2ChildCollection<AggregationMemb return null;
}
+ public AggregationMember addSlot(CastorHashMap props, String classProps, GraphPoint location, int w, int h)
+ {
+
+ // Default geometry if not present
+ if (location == null) location = new GraphPoint(100,100*getCounter());
+ if (w<0) w = 20;
+ if (h<0) h = 20;
+
+ // Create new member object
+ AggregationMember aggMem = new AggregationMember();
+ aggMem.setProperties(props);
+ aggMem.setClassProps(classProps);
+ // create vertex
+ com.c2kernel.graph.model.Vertex vertex = new com.c2kernel.graph.model.Vertex();
+ vertex.setHeight(h); vertex.setWidth(w);
+ mLayout.addVertexAndCreateId(vertex,location);
+ aggMem.setCollection(this);
+ aggMem.setID(vertex.getID());
+ aggMem.setIsLayoutable(true);
+
+ mMembers.list.add(aggMem);
+ Logger.msg(8, "AggregationDescription::addSlot new slot linked to vertexid " + vertex.getID());
+ return aggMem;
+ }
public AggregationMember addMember(int entityKey, CastorHashMap props, String classProps, GraphPoint location, int w, int h)
throws MembershipException
{
- // Create new member object
- AggregationMember aggMem = new AggregationMember();
- aggMem.setProperties(props);
- aggMem.setClassProps(classProps);
- if (entityKey > -1) {
+ AggregationMember aggMem = addSlot(props, classProps, location, w, h);
+ if (entityKey > -1) { // some clients use this method when not setting a member
aggMem.assignEntity(entityKey);
- aggMem.setIsComposite( RelationshipUtils.getIsComposite(entityKey) );
+ aggMem.setIsComposite( getIsComposite(entityKey, getName()) );
}
- // create vertex
- com.c2kernel.graph.model.Vertex vertex = new com.c2kernel.graph.model.Vertex();
- vertex.setHeight(h); vertex.setWidth(w);
- mLayout.addVertexAndCreateId(vertex,location);
- aggMem.setCollection(this);
- aggMem.setID(vertex.getID());
- aggMem.setIsLayoutable(true);
-
- mMembers.list.add(aggMem);
- Logger.msg(8, "AggregationDescription::addMember(" + entityKey + ") added to children linked to vertexid " + vertex.getID());
+ Logger.msg(8, "AggregationDescription::addMember(" + entityKey + ") assigned to new slot " + aggMem.getID());
return aggMem;
}
@@ -95,7 +112,12 @@ abstract public class Aggregation extends Parent2ChildCollection<AggregationMemb @Override
public AggregationMember addMember(int entityKey, CastorHashMap props, String classProps) throws MembershipException
{
- return addMember(entityKey, props, classProps, new GraphPoint(100,100*getCounter()), 20, 20);
+ return addMember(entityKey, props, classProps, null, -1, -1);
+ }
+
+ public AggregationMember addSlot(CastorHashMap props, String classProps)
+ {
+ return addSlot(props, classProps, null, -1, -1);
}
@Override
@@ -115,5 +137,19 @@ abstract public class Aggregation extends Parent2ChildCollection<AggregationMemb }
throw new MembershipException("Member "+memberId+" not found");
}
+
+ static public boolean getIsComposite(int entityKey, String name)
+ {
+ if (entityKey == -1) return false;
+ try {
+ for(String collName: Gateway.getProxyManager().getProxy(new EntityPath(entityKey)).getContents(ClusterStorage.COLLECTION) )
+ if (name == null || name.equals(collName)) return true;
+ } catch (ObjectNotFoundException e) {
+ return false;
+ } catch (InvalidEntityPathException e) {
+ return false;
+ }
+ return false;
+ }
}
diff --git a/src/main/java/com/c2kernel/collection/RelationshipUtils.java b/src/main/java/com/c2kernel/collection/RelationshipUtils.java deleted file mode 100644 index 0151b7e..0000000 --- a/src/main/java/com/c2kernel/collection/RelationshipUtils.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.c2kernel.collection;
-
-
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.process.Gateway;
-
-
-/**
- * @version $Revision: 1.22 $ $Date: 2004/10/21 08:02:23 $
- * @author $Author: abranson $
- */
-
-public class RelationshipUtils
-{
-
- static public boolean getIsComposite(int entityKey)
- {
- if (entityKey == -1) return false;
- try
- {
- if ( Gateway.getProxyManager().getProxy(new EntityPath(entityKey)).getContents(ClusterStorage.COLLECTION).length > 0 )
- return true;
- }
- catch (Exception ex)
- {
- //do nothing - member has no composition, thus elementary
- }
-
- return false;
- }
-
-}
|
