com.hedgehog.model
Class Model

java.lang.Object
  extended by com.hedgehog.HObject
      extended by com.hedgehog.model.Model
All Implemented Interfaces:
java.lang.Comparable, java.util.Comparator
Direct Known Subclasses:
GeometricModel

public class Model
extends HObject

Title: Model - a model of objects.

Description: Represents a model of ModelObject objects.

Copyright: Copyright (c) Hedgehog Software.

Company: Hedgehog Software.

Since:
1.0
Version:
1.1

Field Summary
protected  IDManager mIDManager
          Model ID manager.
protected  IDSetManager mIDSetManager
          Model ID set manager.
protected  MaterialManager mMaterialManager
          Model material manager
protected  ModelDatabaseManager mModelDatabaseManager
          Model database manager.
protected  java.lang.String mModelDescription
          A brief description of this model.
protected  ModelObjectAttributeManager mModelObjectAttributeManager
          Model object attribute manager.
protected  java.util.Hashtable<ID,ModelObject> mModelObjects
          Hash map of model objects.
protected  ModelState mModelState
          Model state object.
protected  UnitManager mUnitManager
          Model units manager
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
Model()
          Default constructor.
Model(java.util.Hashtable<ID,ModelObject> modelObjects)
          Constructor.
Model(ID id)
          Constructor.
Model(Model object)
          Copy constructor.
Model(java.lang.String name)
          Default constructor.
Model(java.lang.String name, ID id)
          Default constructor.
 
Method Summary
 boolean addModelObjectAttribute(ID modelObjectID, Attribute attribute)
          Adds the specified (ID,attribute) association to this model's attribute manager.
 boolean addModelObjectAttributes(ID modelObjectID, Attributes attributes)
          Adds the specified vector of attribute, associating them the specified ID.
 boolean addObject(ID id, ModelObject object)
          Adds an object to this model.
 boolean addObject(ModelObject object)
          Same as addObject(ID id,ModelObject object) except that the ID is extracted from the specified ModelObject.
 boolean addObjectOnly(ID id, ModelObject object)
          As addObject() except that adds only the specified object and no child objects of the specified object.
 boolean addObjectOnly(ModelObject object)
          As addObject() except that adds only the specified object and no child objects of the specified object.
 java.util.Vector<AttributeType> attributeType(ID modelObjectID)
          Returns the vector of attribute types for the specified object ID.
 void clear()
          Flushes this model.
static PairPQ<DatabaseImport,Model> fromDatabase(java.sql.Connection connection, int modelID)
          Imports a model from the specified database.
static PairPQ<XMLImport,Model> fromXML(java.io.File file)
          Imports a model from the specified file in xml file.
 ID generateID()
          Generates a new unique minimum available ID.
 java.util.Hashtable<java.lang.String,ModelObject> getAllDatabaseModelObjects()
          Internally used for storing the IDs of all model objects and child objects when loading a model from a database.
 IntHashtable getAllModelObjects()
          Internally used for storing the IDs of all model objects and child objects when loading a model from an xml file.
 AttributeManager getAttributeManager()
          Returns the model object attribute manager.
 IDManager getIDManager()
          Returns the ID manager.
 IDSetManager getIDSetManager()
          Returns the ID set manager.
 MaterialManager getMaterialManager()
          Returns the material manager.
 ModelDatabaseManager getModelDatabaseManager()
          Returns the database manager.
 java.lang.String getModelDescription()
          Returns the model description.
 ModelObject getModelObject(ID id)
          Returns the model object associated with the specified ID.
 Attributes getModelObjectAttributes(ID modelObjectID)
          Returns the Attributes object associated with the specified ID.
 java.util.Hashtable<ID,ModelObject> getModelObjects()
          Returns the hash map of model objects.
 ModelObjectAttributeManager getModelObjectsAttributeManager()
          Returns the model object attribute manager.
 ModelState getModelState()
          Returns the model state object.
 UnitManager getUnitManager()
          Returns the unit manager.
 boolean hasModelObjectAttributes()
          Tests whether or not this model has any attributes.
 boolean hasModelObjects()
          Tests whether or not this model has any model objects.
 boolean isChildObjectID(ID id)
          Tests whether or not the specified ID is an ID of a child object of this model's mModelObjects map.
 boolean isModelObject(ModelObject object)
          Tests whether or not the specified object is managed by this manager.
 boolean isModelObjectAttribute(ID modelObjectID)
          Tests whether or not the specified ID is managed by this model's attribute manager.
 boolean isModelObjectID(ID id)
          Tests whether or not the specified ID is an object ID managed by this manager.
 java.util.Vector<java.lang.String> modelObjectClassNames()
          Returns a vector of model object simple class names.
 int numberOfModelObjects()
          Returns the number of model objects.
 boolean objectInModel(ModelObject object)
          Tests whether or not the specified object is in this model.
 boolean removeObject(java.lang.Object object)
          Removes the specified object from this model, if present.
 void setAttributeManager(AttributeManager attributeManager)
          Sets the model object attribute manager.
 void setIDManager(IDManager idManager)
          Sets the ID manager.
 void setIDSetManager(IDSetManager idSetManager)
          Sets the ID set manager.
 void setMaterialManager(MaterialManager materialManager)
          Sets the material manager.
 void setModelDatabaseManager(ModelDatabaseManager modelDatabaseManager)
          Sets the database manager.
 void setModelDescription(java.lang.String description)
          Sets the model description.
 boolean setModelObjectIDs()
          Sets the IDs of all model objects and child nodes (if any) if their ID is equal to the default ID.
 void setModelObjects(java.util.Hashtable<ID,ModelObject> newModelObjects)
          Sets the model map of objects.
 void setModelObjectsAttributeManager(ModelObjectAttributeManager modelObjectAttributeManager)
          Sets the model object attribute manager.
 void setModelState(ModelState modelState)
          Sets the model state object.
 void setUnitManager(UnitManager unitManager)
          Sets the unit manager.
 DatabaseExport toDatabase(java.sql.Connection connection, boolean updateObjectIDs)
          Exports this model's objects to the specified database.
 java.lang.String toString()
          Returns a String representation of this Model object.
 X3DExport toX3D(java.io.File file, ProfileType profileType, X3DObject x3dObject)
          Exports this model to the specified file in X3D format.
 XMLExport toXML(java.io.File file)
          Exports this model's objects and object attributes to the specified file in xml format.
 
Methods inherited from class com.hedgehog.HObject
clone, compare, compareTo, copy, equals, getID, getName, hashCode, hasID, hasName, setID, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mModelObjects

protected java.util.Hashtable<ID,ModelObject> mModelObjects
Hash map of model objects.


mIDManager

protected IDManager mIDManager
Model ID manager.


mIDSetManager

protected IDSetManager mIDSetManager
Model ID set manager.


mUnitManager

protected UnitManager mUnitManager
Model units manager


mMaterialManager

protected MaterialManager mMaterialManager
Model material manager


mModelObjectAttributeManager

protected ModelObjectAttributeManager mModelObjectAttributeManager
Model object attribute manager.


mModelDatabaseManager

protected ModelDatabaseManager mModelDatabaseManager
Model database manager.


mModelState

protected ModelState mModelState
Model state object.


mModelDescription

protected java.lang.String mModelDescription
A brief description of this model.

Constructor Detail

Model

public Model()
Default constructor. Allocates new but empty mModelObjects, mIDManager, mIDSetManager, mUnitManager, mMaterialManager and mAttributeManager objects. Sets mModelDatabaseManager to a new but empty model database manager. Sets mModelPersistenceType to the default type of IN_MEMORY.


Model

public Model(ID id)
Constructor. Allocates new but empty mModelObjects, mIDManager, mIDSetManager, mUnitManager, mMaterialManager and mAttributeManager objects.

Parameters:
id - Model ID.

Model

public Model(java.lang.String name)
Default constructor. Allocates new but empty mModelObjects, mIDManager, mIDSetManager, mUnitManager, mMaterialManager and mAttributeManager objects.

Parameters:
name - Model name.

Model

public Model(java.lang.String name,
             ID id)
Default constructor. Allocates new but empty mModelObjects, mIDManager, mIDSetManager, mUnitManager, mMaterialManager and mAttributeManager objects.

Parameters:
name - Model name.
id - Model ID.

Model

public Model(java.util.Hashtable<ID,ModelObject> modelObjects)
      throws java.lang.IllegalArgumentException
Constructor. Intialises the model ID and list of objects to the specified objects.

Parameters:
modelObjects - Hahs map of model objects.
Throws:
java.lang.IllegalArgumentException - Thrown if a null argument of one of the objects in modelObjects does not implement the ModelObject interface.

Model

public Model(Model object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

isModelObjectID

public boolean isModelObjectID(ID id)
Tests whether or not the specified ID is an object ID managed by this manager.

Parameters:
id - ID to test.
Returns:
Logical-true if the specified ID is an object ID managed by this manager, else logical-false.

isModelObject

public boolean isModelObject(ModelObject object)
Tests whether or not the specified object is managed by this manager.

Parameters:
object - Object to test.
Returns:
Logical-true if the specified object is managed by this manager, else logical-false.

isChildObjectID

public boolean isChildObjectID(ID id)
Tests whether or not the specified ID is an ID of a child object of this model's mModelObjects map.

Parameters:
id - ID to search for.
Returns:
Logical-true if the specified ID is the ID of a model child object, else logical-false.

isModelObjectAttribute

public boolean isModelObjectAttribute(ID modelObjectID)
Tests whether or not the specified ID is managed by this model's attribute manager.

Parameters:
modelObjectID - Model object ID to test.
Returns:
Logical-true if the specified ID is managed by this model's attribute manager, else logical-false.

attributeType

public java.util.Vector<AttributeType> attributeType(ID modelObjectID)
Returns the vector of attribute types for the specified object ID.

Parameters:
modelObjectID - Object ID.
Returns:
Vector of attribute types for the specified object ID.

clear

public void clear()
Flushes this model. Clears the map of model objects and clears all managers. Sets the model description to a new non-null empty string.


addObject

public boolean addObject(ModelObject object)
                  throws java.lang.IllegalArgumentException
Same as addObject(ID id,ModelObject object) except that the ID is extracted from the specified ModelObject.

Parameters:
object - Object to add.
Returns:
Logical-true if object added, else logical-false if object already part of this model.
Throws:
java.lang.IllegalArgumentException - Thrown if null argument.

addObject

public boolean addObject(ID id,
                         ModelObject object)
                  throws java.lang.IllegalArgumentException
Adds an object to this model. If mModelObjects already contains an object with the specified ID then it is not added and an exception is thrown. Note that all child objects of the specified object are added to the model if not already present. The reason for this is because it saves a user from trying to remember what has been added to a model and what has not. When saving a model to either an xml file or database it is important that all necessary objects form part of the model, including child objects.

Parameters:
id - Object ID. If equal to the default ID of -1 then a new and unique ID is generated by the ID manager and the object's ID is set to this new ID and used to add the object to the model.
object - Object to add.
Returns:
Logical-true if object added, else logical-false if object already part of this model.
Throws:
java.lang.IllegalArgumentException - Thrown if null argument or if the specified object does not implement ModelObject or if the specified ID is currently being used by another object.

addObjectOnly

public boolean addObjectOnly(ModelObject object)
                      throws java.lang.IllegalArgumentException
As addObject() except that adds only the specified object and no child objects of the specified object.

Parameters:
object - Object to add.
Returns:
Logical-true if object added, else logical-false if object already part of this model.
Throws:
java.lang.IllegalArgumentException

addObjectOnly

public boolean addObjectOnly(ID id,
                             ModelObject object)
                      throws java.lang.IllegalArgumentException
As addObject() except that adds only the specified object and no child objects of the specified object.

Parameters:
id - Object ID. If equal to the default ID of -1 then a new and unique ID is generated by the ID manager and the object's ID is set to this new ID and used to add the object to the model.
object - Object to add.
Returns:
Logical-true if object added, else logical-false if object already part of this model.
Throws:
java.lang.IllegalArgumentException

addModelObjectAttribute

public boolean addModelObjectAttribute(ID modelObjectID,
                                       Attribute attribute)
Adds the specified (ID,attribute) association to this model's attribute manager. Passes on the call to ModelObjectAttributeManager.addAttribute().

Parameters:
modelObjectID - ID.
attribute - Attribute.
Returns:
Logical-true if the (ID,attribute) association added to this manager, else logical-false.

addModelObjectAttributes

public boolean addModelObjectAttributes(ID modelObjectID,
                                        Attributes attributes)
Adds the specified vector of attribute, associating them the specified ID. Passes on the call to ModelObjectAttributeManager.addAttribute().

Parameters:
modelObjectID - ID.
attributes - Attributes.
Returns:
Logical-true if the (ID,attributes) association added to this manager, else logical-false.

generateID

public ID generateID()
Generates a new unique minimum available ID.

Returns:
New ID.

getIDManager

public IDManager getIDManager()
Returns the ID manager.

Returns:
The ID manager.

setIDManager

public void setIDManager(IDManager idManager)
Sets the ID manager.

Parameters:
idManager - New ID manager.

getIDSetManager

public IDSetManager getIDSetManager()
Returns the ID set manager.

Returns:
The ID set manager.

setIDSetManager

public void setIDSetManager(IDSetManager idSetManager)
Sets the ID set manager.

Parameters:
idSetManager - New ID set manager.

getUnitManager

public UnitManager getUnitManager()
Returns the unit manager.

Returns:
The unit manager.

setUnitManager

public void setUnitManager(UnitManager unitManager)
Sets the unit manager.

Parameters:
unitManager - New unit manager.

getMaterialManager

public MaterialManager getMaterialManager()
Returns the material manager.

Returns:
The material manager.

setMaterialManager

public void setMaterialManager(MaterialManager materialManager)
Sets the material manager.

Parameters:
materialManager - New material manager.

getAttributeManager

public AttributeManager getAttributeManager()
Returns the model object attribute manager.

Returns:
The model object attribute manager.

setAttributeManager

public void setAttributeManager(AttributeManager attributeManager)
Sets the model object attribute manager.

Parameters:
attributeManager - New model object attribute manager.

getModelObjectsAttributeManager

public ModelObjectAttributeManager getModelObjectsAttributeManager()
Returns the model object attribute manager.

Returns:
The model object attribute manager.

setModelObjectsAttributeManager

public void setModelObjectsAttributeManager(ModelObjectAttributeManager modelObjectAttributeManager)
Sets the model object attribute manager.

Parameters:
modelObjectAttributeManager - New model object attribute manager.

getModelDatabaseManager

public ModelDatabaseManager getModelDatabaseManager()
Returns the database manager.

Returns:
The database manager.

setModelDatabaseManager

public void setModelDatabaseManager(ModelDatabaseManager modelDatabaseManager)
Sets the database manager.

Parameters:
modelDatabaseManager - New database manager.

getModelDescription

public java.lang.String getModelDescription()
Returns the model description.

Returns:
Model description.

setModelDescription

public void setModelDescription(java.lang.String description)
Sets the model description.

Parameters:
description - New model description.

getModelState

public ModelState getModelState()
Returns the model state object.

Returns:
The model state object.

setModelState

public void setModelState(ModelState modelState)
Sets the model state object.

Parameters:
modelState - New model state obejct.

getModelObjects

public java.util.Hashtable<ID,ModelObject> getModelObjects()
Returns the hash map of model objects.

Returns:
The hash map of model objects.

getModelObject

public ModelObject getModelObject(ID id)
Returns the model object associated with the specified ID.

Parameters:
id - ID.
Returns:
Model object associated with the specified ID.

getModelObjectAttributes

public Attributes getModelObjectAttributes(ID modelObjectID)
Returns the Attributes object associated with the specified ID. If the specified ID is either null or not managed by this model's model object attribute manager then a null value is returned.

Parameters:
modelObjectID - Attribute ID.
Returns:
Attributes object associated with the specified model object ID, or null if the specified ID is null or it is an ID not managed by this model's attribute manager.

numberOfModelObjects

public int numberOfModelObjects()
Returns the number of model objects.

Returns:
The number of model objects.

hasModelObjects

public boolean hasModelObjects()
Tests whether or not this model has any model objects.

Returns:
Logical-true if this model has any model objects, else logical-false.

hasModelObjectAttributes

public boolean hasModelObjectAttributes()
Tests whether or not this model has any attributes.

Returns:
Logical-true if this model has any model attributes, else logical-false.

objectInModel

public boolean objectInModel(ModelObject object)
                      throws java.lang.IllegalArgumentException
Tests whether or not the specified object is in this model.

Parameters:
object - Object to test.
Returns:
Logical-true if the specified object is in this model, else logical-false.
Throws:
java.lang.IllegalArgumentException - Thrown if object is null.

removeObject

public boolean removeObject(java.lang.Object object)
                     throws java.lang.IllegalArgumentException
Removes the specified object from this model, if present.

Parameters:
object - Object to remove.
Returns:
Logical-true if the specified object is removed, else logical-false.
Throws:
java.lang.IllegalArgumentException - Thrown if object is null.

setModelObjects

public void setModelObjects(java.util.Hashtable<ID,ModelObject> newModelObjects)
                     throws java.lang.IllegalArgumentException
Sets the model map of objects.

Parameters:
newModelObjects - New map of model objects.
Throws:
java.lang.IllegalArgumentException - Thrown if newModelObjects is null.

setModelObjectIDs

public boolean setModelObjectIDs()
Sets the IDs of all model objects and child nodes (if any) if their ID is equal to the default ID. If an object's ID is not equal to the default ID then it not altered. The method of generating unique IDs for all model objects is to use this model's ID manager.

Returns:
Logical-true if all IDs set to non-default values, else logical-false.

toString

public java.lang.String toString()
Returns a String representation of this Model object.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this Model object.

toXML

public XMLExport toXML(java.io.File file)
                throws InvalidObjectException
Exports this model's objects and object attributes to the specified file in xml format.

Parameters:
file - Export file object.
Returns:
An xml export object to indicate the success/failure of the export.
Throws:
InvalidObjectException - Thrown if an error writing this model.

fromXML

public static PairPQ<XMLImport,Model> fromXML(java.io.File file)
                                       throws InvalidObjectException,
                                              java.lang.IllegalArgumentException
Imports a model from the specified file in xml file.

Parameters:
file - Import file object.
Returns:
A pair consisting of an xml import object to indicate the success/failure of the import and a newly built Model from the xml file contents.
Throws:
InvalidObjectException - Thrown if an error occurred building the model from the specified xml file.
java.lang.IllegalArgumentException - Thrown if the specified model ID is not found in the specified file.

toDatabase

public DatabaseExport toDatabase(java.sql.Connection connection,
                                 boolean updateObjectIDs)
                          throws java.sql.SQLException,
                                 InvalidObjectException
Exports this model's objects to the specified database.

Parameters:
connection - Database connection.
updateObjectIDs - Specifies whether or not model object IDs are to be updated to match those of the database.
Returns:
A database export object to indicate the success/failure of the export.
Throws:
java.sql.SQLException - Thrown if an SQL exception occurs.
InvalidObjectException - Thrown if this object is invalid.

fromDatabase

public static PairPQ<DatabaseImport,Model> fromDatabase(java.sql.Connection connection,
                                                        int modelID)
                                                 throws java.sql.SQLException,
                                                        java.lang.IllegalArgumentException
Imports a model from the specified database.

Parameters:
connection - Database connection.
modelID - Model ID.
Returns:
An database import object to indicate the sucess/failure of the import.
Throws:
java.sql.SQLException - Thrown if an SQL exception occurs.
java.lang.IllegalArgumentException - Thrown if connection is null or if modelID is not a Models table ID.

toX3D

public X3DExport toX3D(java.io.File file,
                       ProfileType profileType,
                       X3DObject x3dObject)
                throws InvalidObjectException
Exports this model to the specified file in X3D format.

Parameters:
file - File object.
profileType - Profile type.
x3dObject - X3D governing object.
Returns:
X3D export object, indicating export success/failure.
Throws:
InvalidObjectException - Thrown if an invalid object is encountered.

modelObjectClassNames

public java.util.Vector<java.lang.String> modelObjectClassNames()
Returns a vector of model object simple class names. This method does not recurse through each object's sub-objects but rather just returns the vector of simple class names of the objects store in the mModelObjects hash map.

Returns:
Vector of model object simple class names, sorted in alphabetical order.

getAllModelObjects

public IntHashtable getAllModelObjects()
Internally used for storing the IDs of all model objects and child objects when loading a model from an xml file.

Returns:
Model objects IDs for XML files.

getAllDatabaseModelObjects

public java.util.Hashtable<java.lang.String,ModelObject> getAllDatabaseModelObjects()
Internally used for storing the IDs of all model objects and child objects when loading a model from a database.

Returns:
Model objects ODs for database.