uk.ac.ic.doc.automed.reps
Class Model

java.lang.Object
  extended by uk.ac.ic.doc.automed.reps.Model
All Implemented Interfaces:
Positionable, PersistentObject

public class Model
extends java.lang.Object
implements Positionable, PersistentObject

Model.java The Model class represents instances of conceptual modelling languages, such as the relational model, ER, UML, XML, or ORM languages. Each Model will have one or more Construct instances.

Author:
Michael Boyd (mboyd@doc.ic.ac.uk), Peter McBrien (pjm@doc.ic.ac.uk), Nerissa Tong (nnyt98@doc.ic.ac.uk)

Method Summary
 boolean addModelChangeListener(ModelChangeListener scl)
           
static boolean addModelsListener(ModelsListener nl)
          Add an instance of any class implementing interface ModelsListener such that it will be notified of any adding or deleting of models that may occur.
 Construct createConstruct(java.lang.String cName, int cClass, boolean isRoot)
          Creates a new construct and add to the model.
static Model createModel(java.lang.String modelName)
          Creates a new model with the given name.
static boolean exists(int MID)
           
static boolean exists(java.lang.String modelName)
           
 void exportConstructs(java.io.OutputStream os)
           
 void exportConstructs(java.io.PrintWriter pw)
           
 java.awt.Point getAbsolutePosition()
          Same behaviour as getPosition() since Model instances are not placed relative to other Positionables.
 java.awt.Color getBackgroundColor()
          Return the default background colour to be used from drawing SchemaObjects of this Model.
 Construct getConstruct(java.lang.String name)
          Returns the named construct in the model or throws an AutoMedException if the construct name doesn't exist in the model.
 Construct[] getConstructs()
          Returns an array of all the constructs in the model.
 Construct[] getConstructs(boolean full)
          Get a list of Construct objects associated to a Model object for generating XML structure.
 java.awt.Color getForegroundColor()
          Return the default foreground colour to be used from drawing SchemaObjects of this Model.
 PersistentKey getKey()
          Implements the PersistentObject interface
 java.lang.String getLabel()
          Get the text used to label this Model.
 java.awt.Point getLabelPosition()
           
 int getLabelXPos()
           
 int getLabelYPos()
           
 int getMID()
          Returns the repository identifer of the model.
static Model getModel(int MID)
          Returns a reference to the Model with the given MID.
static Model getModel(java.lang.String name)
          Returns a reference to the Model with the given modelName.
 java.lang.String getModelDescription()
          Returns a description of the model, each construct along with their schemes is listed in a way suitable for printing.
 java.lang.String getModelDescription(boolean full)
          Returns a description of the model, each construct along with its schemes are listed in a way suitable for printing.
static Model[] getModels()
          Returns an array of all models.
 java.lang.String getName()
          Returns the name of the model.
 java.util.Map getPersistentAttributes()
          Implements the PersistentObject interface
 java.awt.Point getPosition()
          Return the Point that represents the position of this Positionable in a Panel.
 Positionable getPositionedRelativeTo()
          Return the Positionable this is relative to.
 java.lang.Object getRepObject()
           
 java.awt.Color getTextColor()
          Return the default text colour to be used from drawing SchemaObjects of this Model.
 TypeHierarchy getTypeHierarchy()
          Return the type hierarchy for this model
 java.util.List getTypeObjects()
          Get a list of TypeHierarchy objects associated to this model
 int getXPos()
           
 int getYPos()
           
 void importConstructs(java.io.InputStream is)
           
static Model read(java.io.InputStream is)
           
static Model read(java.io.InputStream is, java.lang.String name)
           
static void reloadModels()
          This method empties the cached model data and then reloads it from the MDR as if the class had just been loaded.
 void remove()
          Removes the Model from the repository.
protected  void removeConstructFromMap(java.lang.String name)
          THIS METHOD DOESN'T DO ANYTHING AT THE MOMENT Sets the content of a particular position of the model's constructs list.
static void removeModel(java.lang.String modelName)
          Removes the Model with the given modelName.
 boolean removeModelChangeListener(ModelChangeListener scl)
           
static boolean removeModelsListener(ModelsListener nl)
          Remove an instance of any class implementing interface ModelsListener such that it will no longer be notified of any adding or deleting of models that may occur.
 void retract()
          Removes the Model from the repository, together with all associated information --- in particular all Constructs belonging to the model are removed, and hence all SchemaObjects, and hence all Transformations on those objects.
 void setAbsolutePosition(int x, int y)
          Same behaviour as #setPosition() since Model instances are not placed relative to other Positionables.
 void setBackgroundColor(java.awt.Color c)
          Set the default background colour to be used from drawing SchemaObjects of this Model.
 void setForegroundColor(java.awt.Color c)
          Set the default foreground colour to be used from drawing SchemaObjects of this Model.
 void setLabel(java.lang.String label)
           
 void setLabelPosition(int x, int y)
           
 void setLabelXPos(int x)
           
 void setLabelYPos(int y)
           
 void setName(java.lang.String modelName)
          Sets the model's name.
 void setPosition(int x, int y)
           
 void setTextColor(java.awt.Color c)
          Set the default text colour to be used from drawing SchemaObjects of this Model.
 void setXPos(int x)
           
 void setYPos(int y)
           
 java.lang.String toString()
           
 void write(java.io.OutputStream os)
           
 void write(java.io.PrintWriter pw)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

reloadModels

public static void reloadModels()
This method empties the cached model data and then reloads it from the MDR as if the class had just been loaded. If you change the contents of the MDR directly rather than through the reps API but wish to then use the reps API in the same JVM instance then you should call this method to synchronize the reps API data with the MDR


createModel

public static Model createModel(java.lang.String modelName)
                         throws IntegrityException
Creates a new model with the given name.

Parameters:
modelName - name of the model.
Throws:
IntegrityException - if model already exists

removeModel

public static void removeModel(java.lang.String modelName)
                        throws IntegrityException
Removes the Model with the given modelName.

Parameters:
modelName - name of the model to be removed.
Throws:
IntegrityException - if model does not exist

remove

public void remove()
            throws IntegrityException
Removes the Model from the repository.

Throws:
IntegrityException

retract

public void retract()
Removes the Model from the repository, together with all associated information --- in particular all Constructs belonging to the model are removed, and hence all SchemaObjects, and hence all Transformations on those objects.


getModels

public static Model[] getModels()
Returns an array of all models.

Returns:
an array of all models.

exists

public static boolean exists(java.lang.String modelName)

exists

public static boolean exists(int MID)

getModel

public static Model getModel(java.lang.String name)
                      throws NotFoundException
Returns a reference to the Model with the given modelName.

Parameters:
modelName - name of the model.
Returns:
the reference to the model with the given modelName
Throws:
NotFoundException

getModel

public static Model getModel(int MID)
                      throws NotFoundException
Returns a reference to the Model with the given MID.

Parameters:
MID - numeric identifier of the model.
Returns:
the reference to the model with the given MID, or null if the model can not be found in the repository
Throws:
NotFoundException

getTypeHierarchy

public TypeHierarchy getTypeHierarchy()
Return the type hierarchy for this model


createConstruct

public Construct createConstruct(java.lang.String cName,
                                 int cClass,
                                 boolean isRoot)
Creates a new construct and add to the model.

Parameters:
cName - name of the construct.
cClass - class of the construct (one of CONSTRUCT_CLASS_NODAL, CONSTRUCT_CLASS_LINK, CONSTRUCT_CLASS_LINK_NODAL, and CONSTRUCT_CLASS_CONSTRAINT, see Constants).
isRoot - set to true if the construct is a construct type of its underlying data model; false otherwise.
Returns:
reference to the new construct.

getName

public java.lang.String getName()
Returns the name of the model.

Returns:
name of the model.

getMID

public int getMID()
Returns the repository identifer of the model.

Returns:
mid of the model.

getConstruct

public Construct getConstruct(java.lang.String name)
                       throws NotFoundException
Returns the named construct in the model or throws an AutoMedException if the construct name doesn't exist in the model.

Throws:
NotFoundException - if the named construct doesn't exist in the model.

getConstructs

public Construct[] getConstructs()
Returns an array of all the constructs in the model.

Returns:
an array of all the constructs in the model.

getConstructs

public Construct[] getConstructs(boolean full)
Get a list of Construct objects associated to a Model object for generating XML structure. We are interested in having full details about every Construct and its schemes.

Parameters:
full - a boolean flag indicating whether or not to get the full construct details. If set to false, it calls getConstructs() method.

getTypeObjects

public java.util.List getTypeObjects()
                              throws AutoMedException
Get a list of TypeHierarchy objects associated to this model

Throws:
AutoMedException

setName

public void setName(java.lang.String modelName)
             throws IntegrityException
Sets the model's name.

Parameters:
modelName - new name of model.
Throws:
MDRException
java.sql.SQLException
DSRException
java.io.IOException
IntegrityException

removeConstructFromMap

protected void removeConstructFromMap(java.lang.String name)
                               throws IntegrityException
THIS METHOD DOESN'T DO ANYTHING AT THE MOMENT Sets the content of a particular position of the model's constructs list.

Parameters:
position - the position in the model's list of constructs whose content is to be set.
con - the new construct to be inserted into the given position.
Throws:
IntegrityException

getModelDescription

public java.lang.String getModelDescription()
Returns a description of the model, each construct along with their schemes is listed in a way suitable for printing. This calls getModelDescription(boolean) passing it false to get the shorter description.


getModelDescription

public java.lang.String getModelDescription(boolean full)
Returns a description of the model, each construct along with its schemes are listed in a way suitable for printing. If a full description is asked for, constructs are expanded to their full description when they appear in another construct's scheme. When false, just the name of the construct is used in the schemes in which it appears.

Parameters:
full - If true, expand construct descriptions in scheme

importConstructs

public void importConstructs(java.io.InputStream is)
                      throws java.io.IOException,
                             AutoRepException,
                             AutoMedException,
                             java.sql.SQLException
Throws:
java.io.IOException
AutoRepException
AutoMedException
java.sql.SQLException

exportConstructs

public void exportConstructs(java.io.OutputStream os)

exportConstructs

public void exportConstructs(java.io.PrintWriter pw)

read

public static Model read(java.io.InputStream is)
                  throws java.io.IOException,
                         AutoRepException,
                         AutoMedException,
                         java.sql.SQLException
Throws:
java.io.IOException
AutoRepException
AutoMedException
java.sql.SQLException

read

public static Model read(java.io.InputStream is,
                         java.lang.String name)
                  throws java.io.IOException,
                         AutoRepException,
                         AutoMedException,
                         java.sql.SQLException
Throws:
java.io.IOException
AutoRepException
AutoMedException
java.sql.SQLException

write

public void write(java.io.OutputStream os)

write

public void write(java.io.PrintWriter pw)

getXPos

public int getXPos()
Specified by:
getXPos in interface Positionable

getYPos

public int getYPos()
Specified by:
getYPos in interface Positionable

setXPos

public void setXPos(int x)
Specified by:
setXPos in interface Positionable

setYPos

public void setYPos(int y)
Specified by:
setYPos in interface Positionable

setPosition

public void setPosition(int x,
                        int y)
Specified by:
setPosition in interface Positionable

setAbsolutePosition

public void setAbsolutePosition(int x,
                                int y)
Same behaviour as #setPosition() since Model instances are not placed relative to other Positionables.

Specified by:
setAbsolutePosition in interface Positionable

getPosition

public java.awt.Point getPosition()
Description copied from interface: Positionable
Return the Point that represents the position of this Positionable in a Panel. Note that depending on the implementation of the interface, this might a coordinate relative to some other positionable

Specified by:
getPosition in interface Positionable

getAbsolutePosition

public java.awt.Point getAbsolutePosition()
Same behaviour as getPosition() since Model instances are not placed relative to other Positionables.

Specified by:
getAbsolutePosition in interface Positionable

getPositionedRelativeTo

public Positionable getPositionedRelativeTo()
Description copied from interface: Positionable
Return the Positionable this is relative to. If not relative to some other Positionable then return null.

Specified by:
getPositionedRelativeTo in interface Positionable

getLabelXPos

public int getLabelXPos()
Specified by:
getLabelXPos in interface Positionable

getLabelYPos

public int getLabelYPos()
Specified by:
getLabelYPos in interface Positionable

getLabelPosition

public java.awt.Point getLabelPosition()
Specified by:
getLabelPosition in interface Positionable

setLabelXPos

public void setLabelXPos(int x)
Specified by:
setLabelXPos in interface Positionable

setLabelYPos

public void setLabelYPos(int y)
Specified by:
setLabelYPos in interface Positionable

setLabelPosition

public void setLabelPosition(int x,
                             int y)
Specified by:
setLabelPosition in interface Positionable

getForegroundColor

public java.awt.Color getForegroundColor()
Return the default foreground colour to be used from drawing SchemaObjects of this Model.

Specified by:
getForegroundColor in interface Positionable
Returns:
A Color, or null if no default colour is set for this Model

setForegroundColor

public void setForegroundColor(java.awt.Color c)
Set the default foreground colour to be used from drawing SchemaObjects of this Model.

Specified by:
setForegroundColor in interface Positionable
Parameters:
A - Color that will be used when drawing SchemaObjects of this Model where no + invidual foreground color has been set.

getBackgroundColor

public java.awt.Color getBackgroundColor()
Return the default background colour to be used from drawing SchemaObjects of this Model.

Specified by:
getBackgroundColor in interface Positionable
Returns:
A Color, or null if no default colour is set for this Model

setBackgroundColor

public void setBackgroundColor(java.awt.Color c)
Set the default background colour to be used from drawing SchemaObjects of this Model.

Specified by:
setBackgroundColor in interface Positionable
Parameters:
A - Color that will be used when drawing SchemaObjects of this Model where no + invidual background color has been set.

getTextColor

public java.awt.Color getTextColor()
Return the default text colour to be used from drawing SchemaObjects of this Model.

Specified by:
getTextColor in interface Positionable
Returns:
A Color, or null if no default colour is set for this Model

setTextColor

public void setTextColor(java.awt.Color c)
Set the default text colour to be used from drawing SchemaObjects of this Model.

Specified by:
setTextColor in interface Positionable
Parameters:
A - Color that will be used when drawing SchemaObjects of this Model where no + invidual text color has been set.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getKey

public PersistentKey getKey()
Implements the PersistentObject interface

Specified by:
getKey in interface PersistentObject
See Also:
PersistentObject.getKey()

getPersistentAttributes

public java.util.Map getPersistentAttributes()
Implements the PersistentObject interface

Specified by:
getPersistentAttributes in interface PersistentObject
See Also:
PersistentObject.getPersistentAttributes()

getLabel

public java.lang.String getLabel()
Get the text used to label this Model. Note that this will differ from getName() at least in that any characters that need escaping for printing are escaped.

Specified by:
getLabel in interface Positionable
Returns:
Name of this model used for writing on to the screen or file

setLabel

public void setLabel(java.lang.String label)
Specified by:
setLabel in interface Positionable

getRepObject

public java.lang.Object getRepObject()
Specified by:
getRepObject in interface Positionable

addModelsListener

public static boolean addModelsListener(ModelsListener nl)
Add an instance of any class implementing interface ModelsListener such that it will be notified of any adding or deleting of models that may occur.


removeModelsListener

public static boolean removeModelsListener(ModelsListener nl)
Remove an instance of any class implementing interface ModelsListener such that it will no longer be notified of any adding or deleting of models that may occur.


addModelChangeListener

public boolean addModelChangeListener(ModelChangeListener scl)

removeModelChangeListener

public boolean removeModelChangeListener(ModelChangeListener scl)