summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/collection
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-10-03 17:30:41 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-10-03 17:30:41 +0200
commit275d0bbf555c8917be82ce4cc21eb4cabb00f4c5 (patch)
treeddcc6b14077d90d1b970b67829f07120547dbb62 /src/main/java/com/c2kernel/collection
parenta139f95bfeca603333b8c0310ae09c6805e58584 (diff)
Huge exception overhaul: Merged ClusterStorageException with
PersistencyException. Replaced MembershipException with InvalidCollectionModification CORBA Exception. Made all predef steps throw more accurate exceptions when they go wrong, and let more exceptions bubble through from underneath.
Diffstat (limited to 'src/main/java/com/c2kernel/collection')
-rw-r--r--src/main/java/com/c2kernel/collection/Aggregation.java33
-rw-r--r--src/main/java/com/c2kernel/collection/AggregationDescription.java16
-rw-r--r--src/main/java/com/c2kernel/collection/AggregationInstance.java16
-rw-r--r--src/main/java/com/c2kernel/collection/AggregationMember.java31
-rw-r--r--src/main/java/com/c2kernel/collection/AggregationVertexFactory.java5
-rw-r--r--src/main/java/com/c2kernel/collection/AggregationVertexOutlineCreator.java6
-rw-r--r--src/main/java/com/c2kernel/collection/Collection.java46
-rw-r--r--src/main/java/com/c2kernel/collection/CollectionArrayList.java10
-rw-r--r--src/main/java/com/c2kernel/collection/CollectionDescription.java9
-rw-r--r--src/main/java/com/c2kernel/collection/CollectionMember.java10
-rw-r--r--src/main/java/com/c2kernel/collection/Dependency.java36
-rw-r--r--src/main/java/com/c2kernel/collection/DependencyDescription.java14
-rw-r--r--src/main/java/com/c2kernel/collection/DependencyMember.java17
-rw-r--r--src/main/java/com/c2kernel/collection/MembershipException.java39
-rw-r--r--src/main/java/com/c2kernel/collection/package-info.java20
15 files changed, 155 insertions, 153 deletions
diff --git a/src/main/java/com/c2kernel/collection/Aggregation.java b/src/main/java/com/c2kernel/collection/Aggregation.java
index 575cd39..b4d1b6b 100644
--- a/src/main/java/com/c2kernel/collection/Aggregation.java
+++ b/src/main/java/com/c2kernel/collection/Aggregation.java
@@ -20,7 +20,9 @@
*/
package com.c2kernel.collection;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.graph.model.GraphModel;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
@@ -33,8 +35,7 @@ import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
/**
- * @version $Revision: 1.59 $ $Date: 2004/08/10 07:56:08 $
- * @author $Author: abranson $
+ * A Collection with a graph layout
*/
abstract public class Aggregation extends Collection<AggregationMember>
@@ -116,7 +117,7 @@ abstract public class Aggregation extends Collection<AggregationMember>
}
public AggregationMember addMember(ItemPath itemPath, CastorHashMap props, String classProps, GraphPoint location, int w, int h)
- throws MembershipException
+ throws InvalidCollectionModification, ObjectAlreadyExists
{
AggregationMember aggMem = addSlot(props, classProps, location, w, h);
if (itemPath != null) { // some clients use this method when not setting a member
@@ -129,24 +130,27 @@ abstract public class Aggregation extends Collection<AggregationMember>
@Override
- public AggregationMember addMember(ItemPath itemPath, CastorHashMap props, String classProps) throws MembershipException
+ public AggregationMember addMember(ItemPath itemPath, CastorHashMap props, String classProps) throws InvalidCollectionModification, ObjectAlreadyExists
{
return addMember(itemPath, props, classProps, null, -1, -1);
}
+
+ public AggregationMember addMember(CastorHashMap props, String classProps, GraphPoint location, int w, int h) throws InvalidCollectionModification {
+ try {
+ return addMember(null, props, classProps, location, w, h);
+ } catch (ObjectAlreadyExists e) { // not assigning an item so this won't happen
+ return null;
+ }
+ }
+
public AggregationMember addSlot(CastorHashMap props, String classProps)
{
return addSlot(props, classProps, null, -1, -1);
}
@Override
- public AggregationMember addMember(ItemPath itemPath) throws MembershipException {
- throw new MembershipException("Aggregations cannot accept arbitrary members without type info");
-
- }
-
- @Override
- public void removeMember(int memberId) throws MembershipException {
+ public void removeMember(int memberId) throws ObjectNotFound {
for (AggregationMember element : mMembers.list) {
if (element.getID() == memberId) {
element.clearItem();
@@ -154,7 +158,7 @@ abstract public class Aggregation extends Collection<AggregationMember>
return;
}
}
- throw new MembershipException("Member "+memberId+" not found");
+ throw new ObjectNotFound("Member "+memberId+" not found");
}
static public boolean getIsComposite(ItemPath itemPath, String name)
@@ -163,10 +167,9 @@ abstract public class Aggregation extends Collection<AggregationMember>
try {
for(String collName: Gateway.getProxyManager().getProxy(itemPath).getContents(ClusterStorage.COLLECTION) )
if (name == null || name.equals(collName)) return true;
- } catch (ObjectNotFoundException e) {
+ } catch (ObjectNotFound e) {
return false;
}
return false;
}
-
}
diff --git a/src/main/java/com/c2kernel/collection/AggregationDescription.java b/src/main/java/com/c2kernel/collection/AggregationDescription.java
index ec58cc1..400a91d 100644
--- a/src/main/java/com/c2kernel/collection/AggregationDescription.java
+++ b/src/main/java/com/c2kernel/collection/AggregationDescription.java
@@ -21,11 +21,14 @@
package com.c2kernel.collection;
/**
- * @version $Revision: 1.34 $ $Date: 2004/03/23 09:29:41 $
- * @author $Author: abranson $
+ * The description of a Collection with a graph layout. Each slot is
+ * instantiated empty in the resulting Aggregation, with ClassProps taken from
+ * the PropertyDescription outcome of the description slot's referenced Item.
*/
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.property.PropertyDescriptionList;
import com.c2kernel.property.PropertyUtility;
@@ -45,7 +48,7 @@ public class AggregationDescription extends Aggregation implements CollectionDes
}
@Override
- public Aggregation newInstance() throws ObjectNotFoundException
+ public Aggregation newInstance() throws ObjectNotFound
{
AggregationInstance newInstance = new AggregationInstance(getName());
//for each desc member
@@ -61,9 +64,8 @@ public class AggregationDescription extends Aggregation implements CollectionDes
try {
Vertex v = getLayout().getVertexById(mem.getID());
newInstance.addMember(null, PropertyUtility.createProperty(pdList), pdList.getClassProps(),v.getCentrePoint(),v.getWidth(),v.getHeight());
- } catch (MembershipException e) {
- // won't happen as we're not assigning an entity
- }
+ } catch (InvalidCollectionModification e) {
+ } catch (ObjectAlreadyExists e) { }
}
else
{
diff --git a/src/main/java/com/c2kernel/collection/AggregationInstance.java b/src/main/java/com/c2kernel/collection/AggregationInstance.java
index e01fe12..2de6b7f 100644
--- a/src/main/java/com/c2kernel/collection/AggregationInstance.java
+++ b/src/main/java/com/c2kernel/collection/AggregationInstance.java
@@ -21,10 +21,12 @@
package com.c2kernel.collection;
/**
- * @version $Revision: 1.30 $ $Date: 2003/06/04 13:21:24 $
- * @author $Author: abranson $
+ * Instance of an Aggregation. Unlike in the description, Items may only be
+ * assigned to one slot.
*/
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.ObjectAlreadyExists;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.utils.CastorHashMap;
@@ -45,20 +47,20 @@ public class AggregationInstance extends Aggregation
@Override
public AggregationMember addMember(ItemPath itemPath, CastorHashMap props, String classProps)
- throws MembershipException
+ throws InvalidCollectionModification, ObjectAlreadyExists
{
if( itemPath != null && exists(itemPath))
- throw new MembershipException(itemPath+" already exists in this collection.");
+ throw new ObjectAlreadyExists(itemPath+" already exists in this collection.");
else
return super.addMember(itemPath, props, classProps);
}
- @Override
+ @Override
public AggregationMember addMember(ItemPath itemPath, CastorHashMap props, String classProps, GraphPoint location, int w, int h)
- throws MembershipException
+ throws InvalidCollectionModification, ObjectAlreadyExists
{
if( itemPath != null && exists(itemPath))
- throw new MembershipException(itemPath+" already exists in this collection.");
+ throw new ObjectAlreadyExists(itemPath+" already exists in this collection.");
else
return super.addMember(itemPath, props, classProps, location, w, h);
}
diff --git a/src/main/java/com/c2kernel/collection/AggregationMember.java b/src/main/java/com/c2kernel/collection/AggregationMember.java
index 067bb46..4a5b8db 100644
--- a/src/main/java/com/c2kernel/collection/AggregationMember.java
+++ b/src/main/java/com/c2kernel/collection/AggregationMember.java
@@ -22,7 +22,8 @@ package com.c2kernel.collection;
import java.util.StringTokenizer;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.graph.model.GraphableVertex;
import com.c2kernel.lookup.InvalidItemPathException;
@@ -33,14 +34,12 @@ import com.c2kernel.property.Property;
import com.c2kernel.utils.Logger;
/**
-* @version $Revision: 1.11 $ $Date: 2005/12/01 14:23:15 $
-* @author $Author: abranson $
+* A CollectionMember, or slot, of an Aggregation instance or description.
+* Verifies type information of Items during assignment based on
+* PropertyDescription information stored in slot properties and listed as
+* ClassProps.
*/
-
-//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
{
@@ -87,11 +86,11 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb
}
@Override
- public void assignItem(ItemPath itemPath) throws MembershipException
+ public void assignItem(ItemPath itemPath) throws InvalidCollectionModification
{
if (itemPath != null) {
if (mClassProps == null || getProperties() == null)
- throw new MembershipException("ClassProps not yet set. Cannot check membership validity.");
+ throw new InvalidCollectionModification("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, ",");
@@ -102,17 +101,17 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb
String memberValue = (String)getProperties().get(aClassProp);
Property ItemProperty = (Property)Gateway.getStorage().get(itemPath, ClusterStorage.PROPERTY+"/"+aClassProp, null);
if (ItemProperty == null)
- throw new MembershipException("Property "+aClassProp+ " does not exist for item " + itemPath );
+ throw new InvalidCollectionModification("Property "+aClassProp+ " does not exist for item " + itemPath );
if (ItemProperty.getValue() == null || !ItemProperty.getValue().equalsIgnoreCase(memberValue))
- throw new MembershipException("Value of mandatory prop "+aClassProp+" does not match: " + ItemProperty.getValue()+"!="+memberValue);
+ throw new InvalidCollectionModification("Value of mandatory prop "+aClassProp+" does not match: " + ItemProperty.getValue()+"!="+memberValue);
}
- catch (MembershipException ex) {
+ catch (InvalidCollectionModification ex) {
throw ex;
}
catch (Exception ex)
{
Logger.error(ex);
- throw new MembershipException("Error checking properties");
+ throw new InvalidCollectionModification("Error checking properties");
}
}
}
@@ -130,7 +129,7 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb
}
@Override
- public ItemProxy resolveItem() throws ObjectNotFoundException {
+ public ItemProxy resolveItem() throws ObjectNotFound {
if (mItem == null && mItemPath != null) {
mItem = Gateway.getProxyManager().getProxy(mItemPath);
}
@@ -143,7 +142,7 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb
if (mItemPath != null) {
try {
mItemName = resolveItem().getName();
- } catch (ObjectNotFoundException ex) {
+ } catch (ObjectNotFound ex) {
Logger.error(ex);
mItemName = "Error ("+mItemPath+")";
}
@@ -155,7 +154,7 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb
return mItemName;
}
- public void setChildUUID(String uuid) throws MembershipException, InvalidItemPathException {
+ public void setChildUUID(String uuid) throws InvalidCollectionModification, InvalidItemPathException {
mItemPath = new ItemPath(uuid);
mItemName = null;
}
diff --git a/src/main/java/com/c2kernel/collection/AggregationVertexFactory.java b/src/main/java/com/c2kernel/collection/AggregationVertexFactory.java
index 242d0bb..6fa7014 100644
--- a/src/main/java/com/c2kernel/collection/AggregationVertexFactory.java
+++ b/src/main/java/com/c2kernel/collection/AggregationVertexFactory.java
@@ -26,7 +26,10 @@ import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
import com.c2kernel.graph.model.VertexFactory;
import com.c2kernel.utils.CastorHashMap;
-
+/**
+ * GraphModel vertex factory for AggregationMembers
+ *
+ */
public class AggregationVertexFactory implements VertexFactory
{
private Aggregation mAggregation = null;
diff --git a/src/main/java/com/c2kernel/collection/AggregationVertexOutlineCreator.java b/src/main/java/com/c2kernel/collection/AggregationVertexOutlineCreator.java
index 4be48e0..fbd5434 100644
--- a/src/main/java/com/c2kernel/collection/AggregationVertexOutlineCreator.java
+++ b/src/main/java/com/c2kernel/collection/AggregationVertexOutlineCreator.java
@@ -24,7 +24,11 @@ import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.model.VertexOutlineCreator;
-
+/**
+ * AggregationMember vertex outline creator. Sets up the new dimensions and
+ * position on the GraphModel.
+ *
+ */
public class AggregationVertexOutlineCreator implements VertexOutlineCreator
{
@Override
diff --git a/src/main/java/com/c2kernel/collection/Collection.java b/src/main/java/com/c2kernel/collection/Collection.java
index 355fa1c..fa0230b 100644
--- a/src/main/java/com/c2kernel/collection/Collection.java
+++ b/src/main/java/com/c2kernel/collection/Collection.java
@@ -22,15 +22,39 @@ package com.c2kernel.collection;
import java.util.Iterator;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.C2KLocalObject;
+import com.c2kernel.graph.model.GraphModel;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.utils.CastorHashMap;
/**
- * @version $Revision: 1.23 $ $Date: 2004/05/14 15:39:39 $
- * @author $Author: abranson $
+ * Collections are Item local objects that reference other Items.
+ *
+ * <p>In parallel with the OO meta-model, Items can be linked to other Items in
+ * different ways. These links are modelled with Collections, which are local
+ * objects stored in an Item which reference a number of other Items in the same
+ * server. The Collections holds a CollectionMember, sometimes known as a slot,
+ * to reference each Item and store additional information about the link.
+ *
+ * <p>Features:
+ * <ul>
+ * <li><b>Typing</b> - Collections can restrict membership of based on type
+ * information derived from Item, Property and Collection descriptions. This
+ * restriction may be per-slot or apply to the whole Collection.
+ *
+ * <li><b>Fixed or flexible slots</b> - The CollectionMember objects of a
+ * Collection may be empty, individually typed, or created and removed as
+ * required, simulating either array, structures or lists.
+ *
+ * <li><b>Layout</b> - Collections can include a {@link GraphModel} to lay out
+ * its slots on a two-dimensional canvas, for modelling real world compositions.
+ * </ul>
+ *
+ * <p>Collections are managed through predefined steps.
*/
abstract public class Collection<E extends CollectionMember> implements C2KLocalObject
{
@@ -131,12 +155,12 @@ abstract public class Collection<E extends CollectionMember> implements C2KLocal
return true;
}
- public E getMember(int memberId) throws ObjectNotFoundException {
+ public E getMember(int memberId) throws ObjectNotFound {
for (E element : mMembers.list) {
if (element.getID() == memberId)
return element;
}
- throw new ObjectNotFoundException("Member "+memberId+" not found in "+mName, "");
+ throw new ObjectNotFound("Member "+memberId+" not found in "+mName);
}
public CollectionMemberList<E> getMembers()
@@ -144,12 +168,10 @@ abstract public class Collection<E extends CollectionMember> implements C2KLocal
return mMembers;
}
- public abstract E addMember(ItemPath itemPath, CastorHashMap props, String classProps) throws MembershipException;
-
- public abstract E addMember(ItemPath itemPath) throws MembershipException;
-
- public abstract void removeMember(int memberId) throws MembershipException;
+ public abstract E addMember(ItemPath itemPath, CastorHashMap props, String classProps) throws InvalidCollectionModification, ObjectAlreadyExists;
+ public abstract void removeMember(int memberId) throws ObjectNotFound;
+
@Override
public boolean equals(Object other) {
if (!(other instanceof Collection<?>)) return false;
@@ -161,10 +183,12 @@ abstract public class Collection<E extends CollectionMember> implements C2KLocal
E thisMem = i.next();
CollectionMember otherMem = otherColl.getMember(thisMem.getID());
if (!thisMem.equals(otherMem)) return false;
- } catch (ObjectNotFoundException ex) {
+ } catch (ObjectNotFound ex) {
return false;
}
}
return true;
}
+
+
}
diff --git a/src/main/java/com/c2kernel/collection/CollectionArrayList.java b/src/main/java/com/c2kernel/collection/CollectionArrayList.java
index eb6ca1a..2c96170 100644
--- a/src/main/java/com/c2kernel/collection/CollectionArrayList.java
+++ b/src/main/java/com/c2kernel/collection/CollectionArrayList.java
@@ -24,6 +24,12 @@ import java.util.ArrayList;
import com.c2kernel.utils.CastorArrayList;
+/**
+ * A bundle of Collections. Used for storage and export/import using XML
+ * persistency via Castor, and to set up an Item's initial collections during
+ * initialization.
+ *
+ */
public class CollectionArrayList extends CastorArrayList<Collection<? extends CollectionMember>> {
public CollectionArrayList()
{
@@ -38,7 +44,9 @@ public class CollectionArrayList extends CastorArrayList<Collection<? extends Co
}
}
- /** Overwrite */
+ /** This put method overwrites any collections with the same name already in
+ * the list.
+ */
public void put(Collection<? extends CollectionMember> c) {
for (Collection<? extends CollectionMember> thisColl : list) {
if (thisColl.getName().equals(c.getName())) {
diff --git a/src/main/java/com/c2kernel/collection/CollectionDescription.java b/src/main/java/com/c2kernel/collection/CollectionDescription.java
index 4b49ccd..0c72b67 100644
--- a/src/main/java/com/c2kernel/collection/CollectionDescription.java
+++ b/src/main/java/com/c2kernel/collection/CollectionDescription.java
@@ -20,20 +20,21 @@
*/
package com.c2kernel.collection;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.entity.C2KLocalObject;
/**
* A collection that can be instantiated. Collection descriptions link Item
* descriptions together, which constrains membership of their instance.
*
*/
-public interface CollectionDescription<E extends CollectionMember> {
+public interface CollectionDescription<E extends CollectionMember> extends C2KLocalObject {
/**
* Create a new instance of this collection.
* @return a new collection instance
- * @throws ObjectNotFoundException When an essential piece of description
+ * @throws ObjectNotFound When an essential piece of description
* data, such as a child Item PropertyDescription outcome, doesn't exist.
*/
- public Collection<E> newInstance() throws ObjectNotFoundException;
+ public Collection<E> newInstance() throws ObjectNotFound;
}
diff --git a/src/main/java/com/c2kernel/collection/CollectionMember.java b/src/main/java/com/c2kernel/collection/CollectionMember.java
index 74d4671..b7b9f31 100644
--- a/src/main/java/com/c2kernel/collection/CollectionMember.java
+++ b/src/main/java/com/c2kernel/collection/CollectionMember.java
@@ -20,7 +20,8 @@
*/
package com.c2kernel.collection;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.utils.CastorHashMap;
@@ -57,8 +58,9 @@ public interface CollectionMember {
* @param itemPath The item to assign
* @throws MembershipException When the Item Properties don't match the
* typing specification in ClassProps and Properties
+ * @throws InvalidCollectionModification
*/
- public void assignItem(ItemPath itemPath) throws MembershipException;
+ public void assignItem(ItemPath itemPath) throws InvalidCollectionModification;
/**
* De-assign the slot, leaving it empty.
@@ -68,9 +70,9 @@ public interface CollectionMember {
/**
* Resolve the Item currently assigned
* @return the ItemProxy of the assigned Item
- * @throws ObjectNotFoundException When empty
+ * @throws ObjectNotFound When empty
*/
- public ItemProxy resolveItem() throws ObjectNotFoundException;
+ public ItemProxy resolveItem() throws ObjectNotFound;
/**
* Get the integer slot ID, as generated by the parent Collection
diff --git a/src/main/java/com/c2kernel/collection/Dependency.java b/src/main/java/com/c2kernel/collection/Dependency.java
index 7b7904d..cfcb4f7 100644
--- a/src/main/java/com/c2kernel/collection/Dependency.java
+++ b/src/main/java/com/c2kernel/collection/Dependency.java
@@ -21,20 +21,27 @@
package com.c2kernel.collection;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.utils.CastorHashMap;
import com.c2kernel.utils.KeyValuePair;
import com.c2kernel.utils.Logger;
-/*
-Dependency Object
-Objectified link representing dependency between items.
-e.g.: Used for ProductDesc::Item-dependency-dependencymember-WfDesc::Item
-*/
-
/**
- * @version $Revision: 1.15 $ $Date: 2005/04/07 08:03:21 $
- * @author $Author: abranson $
+ * A Collection implementation that contains a variable number of members of the
+ * same type, like a variable-length array. CollectionMembers are created and
+ * destroyed as needed. A Dependency never contains empty slots, nor duplicated
+ * members.
+ *
+ * <p>ClassProps are stored at the collection level and duplicated in each slot.
+ * Slots may still have their own individual properties annotating their link.
+ *
+ * Predefined steps managing Dependencies:
+ *
+ * <ul>
+ * <li>
*/
public class Dependency extends Collection<DependencyMember>
{
@@ -77,8 +84,8 @@ public class Dependency extends Collection<DependencyMember>
return mClassProps;
}
- @Override
- public DependencyMember addMember(ItemPath itemPath) throws MembershipException {
+ public DependencyMember addMember(ItemPath itemPath) throws InvalidCollectionModification, ObjectAlreadyExists {
+ if (contains(itemPath)) throw new ObjectAlreadyExists("Item "+itemPath+" already exists in Dependency "+getName());
// create member object
DependencyMember depMember = new DependencyMember();
depMember.setID(getCounter());
@@ -94,10 +101,11 @@ public class Dependency extends Collection<DependencyMember>
@Override
public DependencyMember addMember(ItemPath itemPath, CastorHashMap props, String classProps)
- throws MembershipException
+ throws InvalidCollectionModification, ObjectAlreadyExists
{
+ if (contains(itemPath)) throw new ObjectAlreadyExists("Item "+itemPath+" already exists in Dependency "+getName());
if (classProps != null && !classProps.equals(mClassProps))
- throw new MembershipException("Cannot change classProps in dependency member");
+ throw new InvalidCollectionModification("Cannot change classProps in dependency member");
DependencyMember depMember = new DependencyMember();
depMember.setID(getCounter());
@@ -125,14 +133,14 @@ public class Dependency extends Collection<DependencyMember>
}
@Override
- public void removeMember(int memberId) throws MembershipException {
+ public void removeMember(int memberId) throws ObjectNotFound {
for (DependencyMember element : mMembers.list) {
if (element.getID() == memberId) {
mMembers.list.remove(element);
return;
}
}
- throw new MembershipException("Member "+memberId+" not found");
+ throw new ObjectNotFound("Member "+memberId+" not found");
}
}
diff --git a/src/main/java/com/c2kernel/collection/DependencyDescription.java b/src/main/java/com/c2kernel/collection/DependencyDescription.java
index 0e6bb91..aff2aca 100644
--- a/src/main/java/com/c2kernel/collection/DependencyDescription.java
+++ b/src/main/java/com/c2kernel/collection/DependencyDescription.java
@@ -20,7 +20,9 @@
*/
package com.c2kernel.collection;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.property.PropertyDescriptionList;
import com.c2kernel.property.PropertyUtility;
@@ -39,7 +41,7 @@ public class DependencyDescription extends Dependency implements CollectionDescr
}
@Override
- public Collection<DependencyMember> newInstance() throws ObjectNotFoundException{
+ public Collection<DependencyMember> newInstance() throws ObjectNotFound{
String depName = getName().replaceFirst("\'$", ""); // HACK: Knock the special 'prime' off the end for the case of descriptions of descriptions
Dependency newDep = new Dependency(depName);
if (mMembers.list.size() == 1) { // constrain the members based on the property description
@@ -56,21 +58,21 @@ public class DependencyDescription extends Dependency implements CollectionDescr
@Override
- public DependencyMember addMember(ItemPath itemPath) throws MembershipException {
+ public DependencyMember addMember(ItemPath itemPath) throws InvalidCollectionModification, ObjectAlreadyExists {
checkMembership();
return super.addMember(itemPath);
}
@Override
public DependencyMember addMember(ItemPath itemPath, CastorHashMap props, String classProps)
- throws MembershipException {
+ throws InvalidCollectionModification, ObjectAlreadyExists {
checkMembership();
return super.addMember(itemPath, props, classProps);
}
- public void checkMembership() throws MembershipException {
+ public void checkMembership() throws InvalidCollectionModification {
if (mMembers.list.size() > 0)
- throw new MembershipException("Dependency descriptions may not have more than one member.");
+ throw new InvalidCollectionModification("Dependency descriptions may not have more than one member.");
}
}
diff --git a/src/main/java/com/c2kernel/collection/DependencyMember.java b/src/main/java/com/c2kernel/collection/DependencyMember.java
index 6f86ecd..502894f 100644
--- a/src/main/java/com/c2kernel/collection/DependencyMember.java
+++ b/src/main/java/com/c2kernel/collection/DependencyMember.java
@@ -22,7 +22,8 @@ package com.c2kernel.collection;
import java.util.StringTokenizer;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lookup.InvalidItemPathException;
import com.c2kernel.lookup.ItemPath;
@@ -105,11 +106,11 @@ public class DependencyMember implements CollectionMember
}
@Override
- public void assignItem(ItemPath itemPath) throws MembershipException
+ public void assignItem(ItemPath itemPath) throws InvalidCollectionModification
{
if (itemPath != null) {
if (mClassProps == null || getProperties() == null)
- throw new MembershipException("ClassProps not yet set. Cannot check membership validity.");
+ throw new InvalidCollectionModification("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, ",");
@@ -120,14 +121,14 @@ public class DependencyMember implements CollectionMember
String memberValue = (String)getProperties().get(aClassProp);
Property ItemProperty = (Property)Gateway.getStorage().get(itemPath, ClusterStorage.PROPERTY+"/"+aClassProp, null);
if (ItemProperty == null)
- throw new MembershipException("Property "+aClassProp+ " does not exist for item " + itemPath );
+ throw new InvalidCollectionModification("Property "+aClassProp+ " does not exist for item " + itemPath );
if (!ItemProperty.getValue().equalsIgnoreCase(memberValue))
- throw new MembershipException("DependencyMember::checkProperty() Values of mandatory prop "+aClassProp+" do not match " + ItemProperty.getValue()+"!="+memberValue);
+ throw new InvalidCollectionModification("DependencyMember::checkProperty() Values of mandatory prop "+aClassProp+" do not match " + ItemProperty.getValue()+"!="+memberValue);
}
catch (Exception ex)
{
Logger.error(ex);
- throw new MembershipException("Error checking properties");
+ throw new InvalidCollectionModification("Error checking properties");
}
}
}
@@ -143,13 +144,13 @@ public class DependencyMember implements CollectionMember
}
@Override
- public ItemProxy resolveItem() throws ObjectNotFoundException {
+ public ItemProxy resolveItem() throws ObjectNotFound {
if (mItem == null && mItemPath != null)
mItem = Gateway.getProxyManager().getProxy(mItemPath);
return mItem;
}
- public void setChildUUID(String uuid) throws MembershipException, InvalidItemPathException {
+ public void setChildUUID(String uuid) throws InvalidCollectionModification, InvalidItemPathException {
mItemPath = new ItemPath(uuid);
}
diff --git a/src/main/java/com/c2kernel/collection/MembershipException.java b/src/main/java/com/c2kernel/collection/MembershipException.java
deleted file mode 100644
index 3e2ce8c..0000000
--- a/src/main/java/com/c2kernel/collection/MembershipException.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * This file is part of the CRISTAL-iSE kernel.
- * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 3 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * http://www.fsf.org/licensing/licenses/lgpl.html
- */
-package com.c2kernel.collection;
-
-/**************************************************************************
- *
- * $Revision: 1.1 $
- * $Date: 2003/05/09 14:23:01 $
- *
- **************************************************************************/
-
-public class MembershipException extends Exception {
-
- public MembershipException() {
- super();
- }
-
- public MembershipException(String s) {
- super(s);
- }
-}
diff --git a/src/main/java/com/c2kernel/collection/package-info.java b/src/main/java/com/c2kernel/collection/package-info.java
index 1c77816..96bd022 100644
--- a/src/main/java/com/c2kernel/collection/package-info.java
+++ b/src/main/java/com/c2kernel/collection/package-info.java
@@ -21,25 +21,7 @@
/**
* Collections are Item local objects that reference other Items.
*
- * <p>In parallel with the OO meta-model, Items can be linked to other Items in
- * different ways. These links are modelled with Collections, which are local
- * objects stored in an Item which reference a number of other Items in the same
- * server. The Collections holds a CollectionMember, sometimes known as a slot,
- * to reference each Item and store additional information about the link.
- *
- * <p>Features:
- * <ul>
- * <li><b>Typing</b> - Collections can restrict membership of based on type
- * information derived from Item, Property and Collection descriptions. This
- * restriction may be per-slot or apply to the whole Collection.
- *
- * <li><b>Fixed or flexible slots</b> - The CollectionMember objects of a
- * Collection may be empty, individually typed, or created and removed as
- * required, simulating either array, structures or lists.
- *
- * <li><b>Layout</b> - Collections can include a {@link GraphModel} to lay out
- * its slots on a two-dimensional canvas, for modelling real world compositions.
- * </ul>
+ * @see Collection
*/
package com.c2kernel.collection; \ No newline at end of file