Package org.cristalise.kernel.collection
Class Collection<E extends CollectionMember>
java.lang.Object
org.cristalise.kernel.collection.Collection<E>
- All Implemented Interfaces:
C2KLocalObject
- Direct Known Subclasses:
Aggregation,Dependency
public abstract class Collection<E extends CollectionMember>
extends Object
implements C2KLocalObject
Collections are Item local objects that reference other Items.
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.
Features:
- Typing - 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.
- Fixed or flexible slots - The CollectionMember objects of a Collection may be empty, individually typed, or created and removed as required, simulating either array, structures or lists.
- Layout - Collections can include a
GraphModelto lay out its slots on a two-dimensional canvas, for modelling real world compositions.
Collections are managed through predefined steps.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract EaddMember(ItemPath itemPath, CastorHashMap props, String classProps, TransactionKey transactionKey) Add a member to this collection, with the given property and class properties and optionally an Item to assign, which may be null if the collection allows empty slots.booleanbooleanEach C2KLocalObject is stored with a path identifier starting with the ClusterType: DomainPath: /Path/Domain/Name ItemPath: /Path/Item AgentPath: /Path/Agent RolePath: /Path/Role/Name Properties: /Property/Name Workflow: /LifeCycle/workflow Collections: /Collection/Name/Version (default Name='last') Outcomes: /Outcome/SchemaName/SchemaVersion/EventID Viewpoints: /ViewPoint/SchemaName/Name (default Name='last') Events: /AuditTrail/EventID Jobs: /Job/JobIDEach object belongs to a specific type defined inClusterTypeintFetch the current highest member ID of the collection.getDescVer(E mem) Gets the description version referenced by the given collection member.getMember(int memberId) Find collection member by its integer IDFind first collection member with the given ItemPath.getName()Gets the name of the C2KLocalObjectGet the collection version.Get the version name for storage, which is 'last' unless the version number is set.inthashCode()booleanisFull()Check if all slots have an assigned ItemremoveMember(int memberId) Removes the slot with the given ID from the collection.removeMember(ItemPath ip) Removes the slot with the given itemPath from the collection.resolveMembers(int slotID) Helper method to find all the members for the given item.resolveMembers(int slotID, ItemPath childPath) Helper method to find all the members with the combination of the input parameters.resolveMembers(ItemPath childPath) Helper method to find all the members for the given item.voidsetMembers(CollectionMemberList<E> newMembers) voidSets the collection namevoidsetVersion(Integer version) Set a named version for this collection.intsize()
-
Field Details
-
mMembers
-
mName
-
mVersion
-
-
Constructor Details
-
Collection
public Collection()
-
-
Method Details
-
getCounter
public int getCounter()Fetch the current highest member ID of the collection. This is found by scanning all the current members and kept in the mCounter field, but is not persistent.- Returns:
- the current highest member ID
-
size
public int size()- Returns:
- The total number of slots in this collection, including empty ones
-
setName
Sets the collection name- Specified by:
setNamein interfaceC2KLocalObject- Parameters:
name- Name of the C2KLocalObject
-
getName
Description copied from interface:C2KLocalObjectGets the name of the C2KLocalObject- Specified by:
getNamein interfaceC2KLocalObject- Returns:
- The collection's name
-
getVersion
Get the collection version. Null if not set, and will be stored as 'last'- Returns:
- Integer version
-
setVersion
Set a named version for this collection. Must be an integer or null. Named versions will be stored separately to the current version ('last') and should not change once saved.- Parameters:
version- the version to set
-
getVersionName
Get the version name for storage, which is 'last' unless the version number is set.- Returns:
- String
-
getClusterType
Description copied from interface:C2KLocalObjectEach object belongs to a specific type defined inClusterType- Specified by:
getClusterTypein interfaceC2KLocalObject- Returns:
- string id of the type
-
getClusterPath
Description copied from interface:C2KLocalObjectEach C2KLocalObject is stored with a path identifier starting with the ClusterType:- DomainPath: /Path/Domain/Name
- ItemPath: /Path/Item
- AgentPath: /Path/Agent
- RolePath: /Path/Role/Name
- Properties: /Property/Name
- Workflow: /LifeCycle/workflow
- Collections: /Collection/Name/Version (default Name='last')
- Outcomes: /Outcome/SchemaName/SchemaVersion/EventID
- Viewpoints: /ViewPoint/SchemaName/Name (default Name='last')
- Events: /AuditTrail/EventID
- Jobs: /Job/JobID
- Specified by:
getClusterPathin interfaceC2KLocalObject- Returns:
- The path identifier (i.e. primary key) of the object
-
setMembers
-
contains
-
getDescVer
Gets the description version referenced by the given collection member. Assumes 'last' if version not given.- Parameters:
mem- The member in question- Returns:
- String version tag
-
isFull
public boolean isFull()Check if all slots have an assigned Item- Returns:
- boolean
-
getMember
Find collection member by its integer ID- Parameters:
memberId- to find- Returns:
- the CollectionMember with that ID
- Throws:
ObjectNotFoundException- when the ID wasn't found
-
getMember
Find first collection member with the given ItemPath.- Parameters:
itemPath- to find- Returns:
- the CollectionMember with that ItemPath
- Throws:
ObjectNotFoundException- when the ID wasn't found
-
getMembers
-
addMember
public abstract E addMember(ItemPath itemPath, CastorHashMap props, String classProps, TransactionKey transactionKey) throws InvalidCollectionModification, ObjectAlreadyExistsException Add a member to this collection, with the given property and class properties and optionally an Item to assign, which may be null if the collection allows empty slots.- Parameters:
itemPath- the Item to assign to the new slot. Optional for collections that allow empty slotsprops- the Properties of the new memberclassProps- the names of the properties that dictate the type of assigned Items.- Returns:
- the new CollectionMember instance
- Throws:
InvalidCollectionModification- when the assignment was invalid because of collection constraints, such as global type constraints, or not allowing empty slots.ObjectAlreadyExistsException- some collections don't allow multiple slots assigned to the same Item, and throw this Exception if it is attempted
-
removeMember
Removes the slot with the given ID from the collection.- Parameters:
memberId- to remove- Returns:
- removed member instance
- Throws:
ObjectNotFoundException- when there was no slot with this ID found.
-
removeMember
Removes the slot with the given itemPath from the collection.- Parameters:
ip- itemPath to be removed- Returns:
- removed member instance
- Throws:
ObjectNotFoundException- when there was no slot with this itemPath found.
-
hashCode
public int hashCode() -
equals
-
resolveMembers
Helper method to find all the members for the given item.- Parameters:
childPath- the UUID of the item in the slots- Returns:
- the list of members found for the given item
- Throws:
ObjectNotFoundException- there is not member found for the given input parameters
-
resolveMembers
Helper method to find all the members for the given item.- Parameters:
slotID- The id of the slot (aka memberID)- Returns:
- the list of members found for the given ID
- Throws:
ObjectNotFoundException- there is not member found for the given input parameters
-
resolveMembers
Helper method to find all the members with the combination of the input parameters.- Parameters:
slotID- The id of the slot (aka memberID). When it is set to -1, only the chilPath is used for searching.childPath- The UUID of the item in the slots. When it is set to null, only the slotID is used for searching.- Returns:
- the list of members found for the combination of the input parameters
- Throws:
ObjectNotFoundException- iff no member was found for the given input parameters. When both parameters are supplied it indicates that the given slotID does not reference the childPath.
-