org.openbp.guiclient.model
Class ModelConnector

java.lang.Object
  extended by org.openbp.guiclient.model.ModelConnector

public final class ModelConnector
extends java.lang.Object

The model connector provides access to models (Model) and items (Item) of models. It is actually some kind of proxy class for the active implementation of the ModelMgr interface. It adds some functionalities like observer management to the model manager.

Author:
Heiko Erhardt

Method Summary
 void addItem(Model model, Item item, boolean syncGlobalReferences)
          Adds an item.
 void addModel(Model model)
          Adds a new model
protected  void fireEvent(ModelConnectorEvent event)
          Notifies all registered observers about a model connector event.
static ModelConnector getInstance()
          Gets the singleton instance for this class.
 Item getItemByQualifier(ModelQualifier qualifier, boolean required)
          Gets a particular model item.
 ItemTypeDescriptor getItemTypeDescriptor(java.lang.String itemType)
          Gets the item type descriptor of a particular item type.
 ItemTypeDescriptor[] getItemTypeDescriptors(int mode)
          Gets a list of item type descriptors.
 java.lang.String[] getItemTypes(int mode)
          Gets a list of item types.
 Model getModelByQualifier(ModelQualifier modelQualifier)
          Gets a model specified by its qualifier.
 java.util.List getModels()
          Gets a list of all top level models.
 StandardMsgContainer getMsgContainer()
          Gets the message container for validation error logging.
 Model getOptionalModelByQualifier(ModelQualifier modelQualifier)
          Gets an (optional) model specified by its path name.
 void initialize(CoreModule coreModule)
          Looks up the model manager reads the model tree from the server.
 void moveItem(Item item, ModelQualifier destinationQualifier)
          Moves an item.
 void registerObserver(EventObserver observer, java.lang.String[] eventTypes)
          Registers an observer.
 void removeItem(Item item)
          Deletes an item from a model.
 void removeModel(Model model)
          Deletes a model including all its sub models and the contents (processes, actions) of these models.
 void resumeModelConnectorEvents()
          Resumes broadcasting of model connector events.
 boolean saveItem(Item item, boolean isNew)
          Convenience method: Saves the given item.
 void showExceptionDialog(java.lang.Throwable e, ModelObject o)
          Shows an exception message dialog.
 boolean suspendModelConnectorEvents()
          Suspends broadcasting of model connector events.
 void unregisterObserver(EventObserver observer)
          Unregisters an observer.
 void updateItem(Item item)
          Updates the properties of an item.
 void updateModel(Model model)
          Updates the properties of the model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ModelConnector getInstance()
Gets the singleton instance for this class.


initialize

public void initialize(CoreModule coreModule)
Looks up the model manager reads the model tree from the server.

Parameters:
coreModule - The core module
Throws:
OpenBPException - If the server's model manager be located or there was an error reading the model tree

getMsgContainer

public StandardMsgContainer getMsgContainer()
Gets the message container for validation error logging.


showExceptionDialog

public void showExceptionDialog(java.lang.Throwable e,
                                ModelObject o)
Shows an exception message dialog.

Parameters:
e - Exception that occured
o - Model object that caused the exception

saveItem

public boolean saveItem(Item item,
                        boolean isNew)
Convenience method: Saves the given item. The item can be a regular item or a model.

Parameters:
item - Item or model to save
isNew - true: The item is a new item and will be added to the model.
false: The item is an existing item. The model will be updated.
Returns:
true: The item was save successfully.
false: An error occurred while saving the item. An error message was displayed to the user.

getModelByQualifier

public Model getModelByQualifier(ModelQualifier modelQualifier)
Gets a model specified by its qualifier.

Parameters:
modelQualifier - Reference to the model
Returns:
The model
Throws:
OpenBPException - If the specified model does not exist

getOptionalModelByQualifier

public Model getOptionalModelByQualifier(ModelQualifier modelQualifier)
Gets an (optional) model specified by its path name. Will not throw an exception if the model does not exist.

Parameters:
modelQualifier - Reference to the model
Returns:
The model or null

getModels

public java.util.List getModels()
Gets a list of all top level models.

Returns:
A list of model descriptors (Model objects) or null

addModel

public void addModel(Model model)
Adds a new model

Parameters:
model - Model to add
The name of the model must have been set already.
Throws:
OpenBPException - If the model could not be created

updateModel

public void updateModel(Model model)
Updates the properties of the model.

Parameters:
model - Model to update
Throws:
OpenBPException - If the model could not be updated

removeModel

public void removeModel(Model model)
Deletes a model including all its sub models and the contents (processes, actions) of these models.

Parameters:
model - Model to delete
Throws:
OpenBPException - On error. Note that depending on the error condition, some or all of the processes and/or sub models may already have been deleted when the error condition is raised.

getItemByQualifier

public Item getItemByQualifier(ModelQualifier qualifier,
                               boolean required)
Gets a particular model item. Note that the qualifier must specify an existing item.

Parameters:
qualifier - Reference to the item
required - true: Will throw an exception if the item does not exist.
false: Will return null if the item does not exist.
Returns:
Item descriptors or null if the item does not exist.
Note that the appropriate subclass of the Item class will be returned.
Throws:
OpenBPException - On error

addItem

public void addItem(Model model,
                    Item item,
                    boolean syncGlobalReferences)
Adds an item. Note that name and type of the item must be set in order to add it to the model.

Parameters:
model - Model the item shall belong to
item - Item to add
syncGlobalReferences - true: Updates the names of external references (e. g. to data types)
false: Does not perform name updates
Throws:
OpenBPException - If the item could not be added

updateItem

public void updateItem(Item item)
Updates the properties of an item. Note that the name of the item may not be changed. Use moveItem(org.openbp.core.model.item.Item, org.openbp.core.model.ModelQualifier) for this.
The type of the item may never be changed once it was added to the model.

Parameters:
item - Item to update
Throws:
OpenBPException - If the item could not be updated

removeItem

public void removeItem(Item item)
Deletes an item from a model.

Parameters:
item - Item to delete
Throws:
OpenBPException - On error

moveItem

public void moveItem(Item item,
                     ModelQualifier destinationQualifier)
Moves an item. This can be used to simply rename an item within a model or to move an item to a new model.

Parameters:
item - Item to rename
destinationQualifier - New name of the item
Throws:
OpenBPException - On error. The item has not been renamed/moved in this case.

getItemTypes

public java.lang.String[] getItemTypes(int mode)
Gets a list of item types.

Parameters:
mode - ItemTypeRegistry.ALL_TYPES / ItemTypeRegistry.SKIP_MODEL|ItemTypeRegistry.SKIP_INVISIBLE
Returns:
A list of strings (see the constants of the ItemTypes class)

getItemTypeDescriptors

public ItemTypeDescriptor[] getItemTypeDescriptors(int mode)
Gets a list of item type descriptors.

Parameters:
mode - ItemTypeRegistry.ALL_TYPES / ItemTypeRegistry.SKIP_MODEL|ItemTypeRegistry.SKIP_INVISIBLE
Returns:
A list of ItemTypeDescriptor objects or null

getItemTypeDescriptor

public ItemTypeDescriptor getItemTypeDescriptor(java.lang.String itemType)
Gets the item type descriptor of a particular item type.

Parameters:
itemType - Item type to look for
Returns:
The item type descriptor or null if the model does not support this item type

registerObserver

public void registerObserver(EventObserver observer,
                             java.lang.String[] eventTypes)
Registers an observer.

Parameters:
observer - The observer
eventTypes - Lit of event types the observer wants to be notified of or null for all event types

unregisterObserver

public void unregisterObserver(EventObserver observer)
Unregisters an observer.

Parameters:
observer - The observer

suspendModelConnectorEvents

public boolean suspendModelConnectorEvents()
Suspends broadcasting of model connector events.

Returns:
The previous suspend status

resumeModelConnectorEvents

public void resumeModelConnectorEvents()
Resumes broadcasting of model connector events.


fireEvent

protected void fireEvent(ModelConnectorEvent event)
Notifies all registered observers about a model connector event.

Parameters:
event - Model connector event to dispatch


Copyright © 2011. All Rights Reserved.