Workflow API
The ItemCollection is a general Data Object used by the Imixs Workflow API. Each Workitem processed by the Imixs Workflow is represented as an ItemCollection. But also all other Entities like the Model Entities are represented as ItemCollections.
An ItemColleciton is a kind of document with a set of attributes (Items). Each Item of an ItemCollectio has a name and a value. The value of an Item can be any java based data object which is serializeable. The ItemCollection provides methods which makes it easy to work with an ItemCollection creating or modify Items.
import org.imixs.workflow.ItemCollection;
ItemCollection myItemCollection=new ItemCollection;
myItemCollection.replaceItemValue("name","Ralph");
myItemCollection.replaceItemValue("age",new Integer(40));This code example demonstrates the usage of the Imixs ItemCollection. The code creates a new empty ItemCollection and adds two items. The first Item with the "name" contains a String value and the second item "age" contains an Integer.
There are also methods to access items values of an ItemCollection. Some of the methods are Type save and allow to access a value of an specific type
String name=myItemCollection.getItemValueString("name");
int age=myItemCollection.getItemValueInteger("age");This is very easy to use as there is no need for a type cast.
A value of an Item can also be a collection of objects. So you can add multi values to an Item inside an ItemCollection. Therefore the ItmeCollection expects a java.util.Vector containing the list of values for an Item:
Vector multiValue=new Vector();
multiValue.add("Ralph");
multiValue.add("Gaby");
myItemCollection.replaceItemValue("team", multiValue);This code example adds a teamlist with two String values as an item with the Name "team" to an ItemCollection.
To access a multivalue item you can use the following method:
Vector multiValue=myItemCollection.getItemValue("team");
String name=(String)multiValue.firstElement();When you access an Item of an ItemCollection with the method getItemValue() the ItemCollection returns always a Vector. So you will need to care about the type casting of the values stored in the Vector object.
Using the getItemValue() method allows you also to store any type of serializable Java Object into a ItemCollection:
// create a Java HashMap
HashMap hashMap = new HashMap();
hashMap.put( "One", new Integer(1) ); // adding value into HashMap
hashMap.put( "Two", new Integer(2) );
hashMap.put( "Three", new Integer(3) );
// put data object into ItemCollection
myItemCollection.replaceItemValue("MyData", hashMap);
//....
// read hashMap form itemCollection
hashMap = (HashMap) myItemCollection.getItemValue("MyData").firstElement();As an ItemCollection is also a Dataobject each ItemCollection can be strored in another ItemCollection. See the following example:
ItemCollection teamMember=new ItemCollection();
teamMember.replaceItemValue("name", "Ralph");
teamMember.replaceItemValue("city", "munich");
ItemCollection project=new ItemCollection();
project.replaceItemValue("projectname", "my first worklfow project");
project.replaceItemValue("projectManager", teamMember);In this code example the ItemCollection "teamMemer" is stored into the ItemCollection "project" with an item called "projectManager".