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 GraphModel to lay out its slots on a two-dimensional canvas, for modelling real world compositions.

Collections are managed through predefined steps.

  • Field Details

  • 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

      public void setName(String name)
      Sets the collection name
      Specified by:
      setName in interface C2KLocalObject
      Parameters:
      name - Name of the C2KLocalObject
    • getName

      public String getName()
      Description copied from interface: C2KLocalObject
      Gets the name of the C2KLocalObject
      Specified by:
      getName in interface C2KLocalObject
      Returns:
      The collection's name
    • getVersion

      public Integer getVersion()
      Get the collection version. Null if not set, and will be stored as 'last'
      Returns:
      Integer version
    • setVersion

      public void setVersion(Integer version)
      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

      public String getVersionName()
      Get the version name for storage, which is 'last' unless the version number is set.
      Returns:
      String
    • getClusterType

      public ClusterType getClusterType()
      Description copied from interface: C2KLocalObject
      Each object belongs to a specific type defined in ClusterType
      Specified by:
      getClusterType in interface C2KLocalObject
      Returns:
      string id of the type
    • getClusterPath

      public String getClusterPath()
      Description copied from interface: C2KLocalObject
      Each 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:
      getClusterPath in interface C2KLocalObject
      Returns:
      The path identifier (i.e. primary key) of the object
    • setMembers

      public void setMembers(CollectionMemberList<E> newMembers)
    • contains

      public boolean contains(ItemPath itemPath)
    • getDescVer

      public String getDescVer(E mem)
      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

      public E getMember(int memberId) throws ObjectNotFoundException
      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

      public E getMember(ItemPath itemPath) throws ObjectNotFoundException
      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

      public CollectionMemberList<E> 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 slots
      props - the Properties of the new member
      classProps - 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

      public E removeMember(int memberId) throws ObjectNotFoundException
      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

      public E removeMember(ItemPath ip) throws ObjectNotFoundException
      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()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • resolveMembers

      public List<E> resolveMembers(ItemPath childPath) throws ObjectNotFoundException
      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

      public List<E> resolveMembers(int slotID) throws ObjectNotFoundException
      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

      public List<E> resolveMembers(int slotID, ItemPath childPath) throws ObjectNotFoundException
      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.