public class ItemManager extends java.lang.Object implements ItemListener
The ItemManager is responsible for storing, managing and distributing all instances of the Item class. The ItemManager implements a basic, CRUD-style interface for managing items and contains two static methods to manage dynamic registrations of ItemBuilders from the underlying OSGi framework. This class will only store one instance of each ItemBuilder that is registered with it.
The ItemManager will store and retrieve Items to and from a data store if an IPersistenceProvider is set by calling ItemManager.setPersistenceProvider(). The ItemManager will persist Items when they are created, updated and processed. It loads all Item in the Provider by calling loadItems() and it persists all currently active Items by calling persistItems().
The process output file of an Item can be retrieved by calling getOutputFile() and passing the id of the Item as an argument. Retrieving an output file and retrieving a Form are separated because they are treated as two distinctly different things on the Item class.
Constructor and Description |
---|
ItemManager()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
FormStatus |
cancelItemProcess(int itemId,
java.lang.String actionName)
This operation cancels the process with the specified name for the Item
identified.
|
int |
createItem(java.lang.String newItemType,
org.eclipse.core.resources.IProject project)
This operation creates a new item of type newItemType and returns the
unique integer id of the created Item or, if the Item can not be created,
-1.
|
int |
createItem(java.lang.String filename,
java.lang.String itemType,
org.eclipse.core.resources.IProject project)
This operation creates a new item of type newItemType and returns the unique integer id of the created Item or, if the Item can not be created, -1. |
boolean |
deleteItem(int itemID)
This operation will delete the item with id itemID.
|
java.util.ArrayList<java.lang.String> |
getAvailableBuilders()
This operation returns a list of the names of Items that can be created
based on the ItemBuilders that have been registered in the ItemManager.
|
java.util.ArrayList<java.lang.String> |
getAvailableBuilders(ItemType type)
This operation returns a list of the names of Items that can be created
based on the ItemBuilders that have been registered in the ItemManager by
ItemType.
|
FormStatus |
getItemStatus(int itemId)
This operation returns the status of an Item with the specified id.
|
java.io.File |
getOutputFile(int id)
This operation returns a file handle to the output file for the Item with
the specified id.
|
void |
loadItems(org.eclipse.core.resources.IProject projectSpace)
This operation is called to direct the ItemManager to load all Items that
are currently persisted via its IPersistenceProvider.
|
void |
persistItems()
This operation is called to direct the ItemManager to persist all Items
via its IPersistenceProvider.
|
boolean |
postUpdateMessage(Message msg)
This operation updates the Item specified by the Message to let it know
that a particular event has occurred in an ICE subsystem, remote ICE
subsystem or external third-party process.
|
FormStatus |
processItem(int itemId,
java.lang.String actionName)
This operation processes the Item with the specified id and action.
|
void |
registerBuilder(ItemBuilder builder)
This operation registers an ItemBuilder and thereby a particular Item
class with the ItemManager.
|
void |
registerCompositeBuilder(ICompositeItemBuilder builder)
This operation registers an ICompositeItemBuilder with the ItemManager.
|
void |
reloadItemData()
This operation directs the ItemManager to have its Items reload any data
because of updates to projects during runtime.
|
void |
reloadProjectData()
(non-Javadoc)
|
Form |
retrieveItem(int itemID)
This operation retrieves the Form that represents the Item with id equal
to itemID and returns it to the caller.
|
java.util.ArrayList<Identifiable> |
retrieveItemList()
This operation will return a list of Identifiables that contain the names
and unique item ids of each Item that is managed by the ItemManager.
|
void |
setPersistenceProvider(IPersistenceProvider provider)
This operation sets up the persistence provider that implements the
IPersistenceProvider interface.
|
void |
unregisterBuilder(ItemBuilder builder)
This operation unregisters an ItemBuilder and thereby a particular Item
class with the ItemManager.
|
FormStatus |
updateItem(Form form)
This operation updates an Item that is managed by the ItemManager using
the Form for that Item and returns the status of that Item.
|
public int createItem(java.lang.String newItemType, org.eclipse.core.resources.IProject project)
This operation creates a new item of type newItemType and returns the unique integer id of the created Item or, if the Item can not be created, -1. The id of the Item is set from either a sequential list of ids or a previously used id that was made available by the deletion of an Item. The IProject passed to this operation is a handle to the Eclipse project where files should be stored by the newly created Item, but since there is no guarantee that an Item will need to store or use files, this argument may be null.
The ItemManager will call the persistence provider to store the newly created Item when this operation is called.
newItemType
- The type of new Item to create. This type name must be one of the set of names returned by a call to getAvailableBuilders().
project
- The Eclipse project where the newly created Item should store files and search for other resources.
The new and unique id of the item that was created.
public int createItem(java.lang.String filename, java.lang.String itemType, org.eclipse.core.resources.IProject project)
This operation creates a new item of type newItemType and returns the unique integer id of the created Item or, if the Item can not be created, -1. The id of the Item is set from either a sequential list of ids or a previously used id that was made available by the deletion of an Item. The IProject passed to this operation is a handle to the Eclipse project where files should be stored by the newly created Item, but since there is no guarantee that an Item will need to store or use files, this argument may be null.
The ItemManager will call the persistence provider to store the newly created Item when this operation is called.
This version takes a file that should be loaded as input by the newly created Item and is primarily intend for file import.
filename
- The file that should be imported. Nothing will happen if this argument is null. It should be a file in the project space.
itemType
- The type of Item to create.
project
- The Eclipse project where the newly created Item should store files and search for other resources.
The identification number of the newly created Item or -1 if it was unable to create the Item.
public Form retrieveItem(int itemID)
This operation retrieves the Form that represents the Item with id equal to itemID and returns it to the caller.
If this operation is called immediately after processItem() with the same Item id and the call to processItem() returns FormStatus.NeedsInfo, then this operation will return a simple Form composed of a single DataComponent with Entries for all of the additional required information. The smaller Form is created by the Action that is executed during the call to processItem().
itemID
- The unique itemID of the item that should be retrieved.
The Form that represents the Item with id itemID.
public void registerBuilder(ItemBuilder builder)
This operation registers an ItemBuilder and thereby a particular Item class with the ItemManager. This operation is primarily used by the underlying OSGi framework to publish available Item types to ICE.
builder
- An instance of ItemBuilder for a particular Item that is available to the Core.
public void registerCompositeBuilder(ICompositeItemBuilder builder)
This operation registers an ICompositeItemBuilder with the ItemManager. This operation is primarily used by the underlying OSGi framework to publish available Item types to ICE. It functions as registerItem(). The usual unregisterBuilder() operation should be called to unregister an ICompositeItemBuilder.
builder
- The ICompositeItemBuilder that will be used to create an Item that depends on others.
public void unregisterBuilder(ItemBuilder builder)
This operation unregisters an ItemBuilder and thereby a particular Item class with the ItemManager.
builder
- An instance of ItemBuilder for a particular Item that is now unavailable to the Core.
public java.util.ArrayList<java.lang.String> getAvailableBuilders()
This operation returns a list of the names of Items that can be created based on the ItemBuilders that have been registered in the ItemManager. If no ItemBuilders have been registered, this operation returns null.
The list of available Items.
public java.util.ArrayList<java.lang.String> getAvailableBuilders(ItemType type)
This operation returns a list of the names of Items that can be created based on the ItemBuilders that have been registered in the ItemManager by ItemType. If no ItemBuilders have been registered for the specified ItemType, this operation returns null.
type
- public FormStatus getItemStatus(int itemId)
This operation returns the status of an Item with the specified id.
itemId
- public void setPersistenceProvider(IPersistenceProvider provider)
This operation sets up the persistence provider that implements the IPersistenceProvider interface.
provider
- The persistence provider.
public void loadItems(org.eclipse.core.resources.IProject projectSpace)
This operation is called to direct the ItemManager to load all Items that are currently persisted via its IPersistenceProvider. This operation can only load the Items if the IPersistenceProvider has been set, but it should not fail if the persistence provider has not been set. It is meant to be called as a "initialization" or "start up" operation immediately after the core starts and should not be called frequently.
The ItemManager will call the persistence provider to load all available Items when this operation is called. It tries to load the Items in such a way that new Items are created with unique ids and old, unused ids are made available for reuse to prevent fragmentation of the set of Item ids. (No one wants to have five Items spread across three orders of magnitude in ids!)
projectSpace
- The project space that the Items should use for their work. It may be null, but it shouldn't be.
public void persistItems()
This operation is called to direct the ItemManager to persist all Items via its IPersistenceProvider. This operation can only persist the Items if the IPersistenceProvider has been set, but it should not fail if the persistence provider has not been set. It is meant to be called as a "finalization" operation immediately before the core shuts down and should not be called frequently.
The ItemManager will call the persistence provider to persist all available Items when this operation is called. This is not exactly a persistence operation per se since all of the Items have already been initially persisted during creation and updating. Instead, the persistence provider is asked to update all of the information for the persisted Items.
public java.io.File getOutputFile(int id)
This operation returns a file handle to the output file for the Item with the specified id. It returns a handle to the file whether or not it actually exists and clients should check the File.exists() operation before attempting to manipulate the file. The description of the output file can be found elsewhere in the class documentation. This file handle returned is the real file handle and can be written, but clients should be careful to only read from the file. It will return null if an Item with the specified id does not exist.
id
- The id of the Item.
The output file for the specified Item, thoroughly documented elsewhere.
public FormStatus cancelItemProcess(int itemId, java.lang.String actionName)
This operation cancels the process with the specified name for the Item identified.
itemId
- The id of the Item whose process should be canceled.
actionName
- The name of the action that should be canceled for the specified Item.
The status
public void reloadItemData()
This operation directs the ItemManager to have its Items reload any data because of updates to projects during runtime.
public boolean postUpdateMessage(Message msg)
This operation updates the Item specified by the Message to let it know that a particular event has occurred in an ICE subsystem, remote ICE subsystem or external third-party process.
msg
- The incoming Message.
True if the ItemManager was able to forward the Message and if the Item was able to respond to the Message, false otherwise.
public void reloadProjectData()
reloadProjectData
in interface ItemListener
ItemListener.reloadProjectData()
public java.util.ArrayList<Identifiable> retrieveItemList()
This operation will return a list of Identifiables that contain the names and unique item ids of each Item that is managed by the ItemManager.
The list of ItemHandles that contains the names and unique ids of the Items managed by the ItemManager.
public FormStatus updateItem(Form form)
This operation updates an Item that is managed by the ItemManager using the Form for that Item and returns the status of that Item. If the database has been configured by the OSGi and the Core, the ItemManager will also try to persist the updated Item to the database if it is not erroneous or working.
The ItemManager will call the persistence provider to update the Item when this operation is called.
form
- The Form that is associated with the Item that needs to be updated.
The status of the Item after the Form is submitted.
public FormStatus processItem(int itemId, java.lang.String actionName)
This operation processes the Item with the specified id and action. The action name must be one of the set of actions from the Form that represents the Item with the specified id.
It is possible that ICE may require information in addition to that which was requested in the original Form, such as for a username and password for a remote machine. If this is the case, processItem will return FormStatus.NeedsInfo and a new, temporary Form will be available for the Item by calling getItem(). Once this new Form is submitted It is possible that ICE may require information in addition to that which was requested in the original Form, such as for a username and password for a remote machine. If this is the case, processItem will return FormStatus.NeedsInfo and a new, temporary Form will be available for the Item by calling getItem(). Once this new Form is submitted (by calling updateItem() with the completed Form), the Item will finish processing.
The ItemManager will call the persistence provider to update the Item when this operation is called.
itemId
- The identification number of the Item.
actionName
- The name of the action that should be performed for the Item.
The status of the Item after the action has been performed.
public boolean deleteItem(int itemID)
This operation will delete the item with id itemID.
The ItemManager will call the persistence provider to delete the Item when this operation is called.
itemID
- The id of the item that should be deleted.
True if the Item was deleted, false if something went wrong.