com.ashridgetech.jamda.uml
Class Model

java.lang.Object
  |
  +--com.ashridgetech.jamda.uml.ModelElement
        |
        +--com.ashridgetech.jamda.uml.Model

public class Model
extends ModelElement

A UML model. Provides access to the Packages, Stereotypes and DataTypes.

Version:
1.0
Author:
paulb

Nested Class Summary
static interface Model.ElementFactory
          A factory object responsible for creating the correct ModelElement subclass object for a NSUML MModelElement encountered during loading.
static class Model.ElementType
          Type-safe enumeration for the standard UML element types, as used in Stereotype as the base class type.
 
Nested classes inherited from class com.ashridgetech.jamda.uml.ModelElement
ModelElement.DuplicateElementException, ModelElement.ElementListStore, ModelElement.ElementNameListStore, ModelElement.ElementNameStore, ModelElement.ElementStore, ModelElement.TaggedValue, ModelElement.UnknownElementException
 
Field Summary
static java.lang.String DATA_TYPE_PACKAGE_NAME
           
 
Fields inherited from class com.ashridgetech.jamda.uml.ModelElement
DUMMY_STORE
 
Constructor Summary
Model(ru.novosoft.uml.model_management.MModel mm)
          Creates new Model from a NSUML model object using the Model.ElementFactorys from getDefaultElementFactoryList().
Model(ru.novosoft.uml.model_management.MModel mm, java.util.List factoryList, java.util.List stdElementClasses)
          Creates new Model from a NSUML model object.
 
Method Summary
static void addDefaultElementFactory(Model.ElementFactory factory)
          Add to the default list of Model.ElementFactorys.
 void addElementFactory(Model.ElementFactory factory)
          Add to the end of the list of ElementFactorys used to create ModelElements within this Model
 boolean checkStandardElement(StandardElementDef def, boolean create)
          Check whether the element defined by a StandardElementDef is present in this model.
 boolean checkStandardElementColl(java.util.Collection defObjects, boolean create)
          Check whether the elements defined by a set of StandardElementDefs and StandardElementDef constants in Classes are present in this model.
 boolean checkStandardElements(java.util.Collection defs, boolean create)
          Check whether the elements defined by a Collection of StandardElementDefs are present in this model.
 void checkValid()
          Check whether this object is valid.
 ModelElement createElement(ru.novosoft.uml.foundation.core.MModelElement me, ModelElement parent)
          Create an element using the Model.ElementFactorys with which this Model was created.
 java.util.Set extractStandardElements(java.lang.Class defClass)
          Get the StandardElementDef constants defined by a Class.
 java.util.Collection getAbstractions()
          Get the Abstractions which are defined at any level in this Model.
 Actor getActor(java.lang.String name)
          Get the Actor defined at any level in this Model with a given name
 java.util.Collection getActors()
          Get the Actors which are defined at any level in this Model.
 java.util.Collection getAllElements()
          Get all the ModelElements in this Model.
 java.util.Collection getAllStereotypes()
          Get all the Stereotypes in this Model.
 java.util.Collection getAssociations()
          Get the Associations which are defined at any level in this Model.
 ClassType getClass(java.lang.String name)
          Get the ClassType defined at any level in this Model with a given name
 java.util.Collection getClasses()
          Get the ClassTypes which are defined at any level in this Model.
 DataType getDataType(java.lang.String name)
          Get the DataType at any level in this Model with a given name
 ModelPackage getDataTypePackage()
          Get the ModelPackage to which DataTypes belong in this Model.
 java.util.Collection getDataTypes()
          Get the DataTypes at any level in this Model
static java.util.List getDefaultElementFactoryList()
          Get the default list of Model.ElementFactorys.
 ModelElement getElementById(java.lang.String id)
          Get the ModelElement in this Model with a given XMI id, as returned by ModelElement.getId().
 Model.ElementFactory getElementFactory(java.lang.Class factoryClass)
          Get the ElementFactory of the given class, if it exists in this Model.
 java.util.List getElementFactoryList()
          Get the list of ElementFactorys used to create ModelElements within this Model
 java.util.Collection getGeneralizations()
          Get the Generalizations which are defined at any level in this Model.
 InterfaceType getInterface(java.lang.String name)
          Get the InterfaceType defined at any level in this Model with a given name
 java.util.Collection getInterfaces()
          Get the InterfaceTypes which are defined at any level in this Model.
 Model getModel()
          Override the ModelElement method to return this Model
 ModelPackage getPackage(java.lang.String name)
          Get the ModelPackage at any level in this Model with a given name
 java.util.Collection getPackages()
          Get the ModelPackages at any level in this Model
 Stereotype getStereotype(java.lang.String name)
          Get the Stereotype in this Model with a given name.
 java.util.List getStereotypes(java.lang.String shortName)
          Get the Stereotypes in this Model with a given short name.
protected  ModelElement.ElementStore getSubElementStore(java.lang.Class meClass)
          Overridden to return the sub-element ModelElement.ElementStore into which an object of the class meClass should be stored.
 TagDefinition getTagDefinition(java.lang.String name)
          Get the TagDefinition in this Model with a given name
 java.util.Collection getTagDefinitions()
          Get all the TagDefinitions in this Model.
 java.util.Collection getTopPackages()
          Get the top-level ModelPackages in this Model
 Type getType(java.lang.String name)
          Get the Type at any level in this Model with a given name.
(package private)  ru.novosoft.uml.foundation.core.MCorePackage getUmlCorePackage()
          Get the NSUML core package connected with this Model.
(package private)  ru.novosoft.uml.foundation.data_types.MDataTypesPackage getUmlDataTypesPackage()
          Get the NSUML core package connected with this Model.
(package private)  ru.novosoft.uml.model_management.MModelManagementPackage getUmlModelManagementPackage()
          Get the NSUML model management package connected with this Model.
protected  void load()
          Override ModelElement.load() to get the Stereotypes first.
protected  void loadTagDefinitions(java.util.Collection c)
          Load the MTagDefinitions of a given collection, choosing those which are instances of a certain class.
static Model loadXmi(java.lang.String xmiFileName)
          Loads a Model from an XMI file.
static Model loadXmi(java.lang.String xmiFileName, java.util.List factoryList, java.util.List stdElementClasses)
          Loads a Model from an XMI file.
 ModelPackage makePackages(java.util.List packageChain)
          Add any packages which do not exist in a hierarchical list, starting below this Model.
 ModelPackage makePackages(java.lang.String fullPackageName)
          Create a package and any necessary intermediate packages, starting below this Model.
 java.util.Collection selectClasses(Stereotype stereotype)
          Get the ClassTypes which are defined at any level in this Model, and which have a given stereotype.
 java.util.Collection selectElements(Stereotype stereotype)
          Get the ModelElements which are defined at any level in this Model, and which have a given stereotype.
protected  void store(ModelElement me)
          Add a ModelElement instance to this Model.
 void writeXmi(java.lang.String xmiFileName)
          Writes a Model to an XMI file.
 
Methods inherited from class com.ashridgetech.jamda.uml.ModelElement
add, addStereotype, addTaggedValue, addTaggedValue, addTaggedValues, addTaggedValuesInternal, checkInitialised, checkState, findTaggedValueCollection, getBooleanTaggedValue, getChildElements, getComment, getDescription, getDirectSource, getElement, getElementType, getFullName, getId, getName, getNsElement, getOriginalSource, getParentElement, getProperties, getStereotypes, getStringTaggedValue, getTaggedValue, getTaggedValues, getXpathContext, hasStereotype, hasTaggedValue, init, initLoad, isInitialised, load, load, loadElement, logChange, logger, logger, logLoad, logLoadWarning, logNew, logWarning, removeTaggedValue, select, setComment, setDirectSource, setTaggedValue, setTaggedValue, setTaggedValue, setTaggedValues, stereotype, tag, tagError, toString, type, type, type, xpath, xpathList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DATA_TYPE_PACKAGE_NAME

public static final java.lang.String DATA_TYPE_PACKAGE_NAME
See Also:
Constant Field Values
Constructor Detail

Model

public Model(ru.novosoft.uml.model_management.MModel mm)
Creates new Model from a NSUML model object using the Model.ElementFactorys from getDefaultElementFactoryList().

Parameters:
mm - The NSUML model backing this Model within this Model

Model

public Model(ru.novosoft.uml.model_management.MModel mm,
             java.util.List factoryList,
             java.util.List stdElementClasses)
Creates new Model from a NSUML model object. Allows standard model elements to be created before loading elements that depend on them.

Parameters:
mm - The NSUML model backing this Model
factoryList - the list of factories to use to create new elements at any level within this Model. These are added to the default list. The factories are used in the reverse order that they occur in the list. The Model calls Model.ElementFactory.createCopy(com.ashridgetech.jamda.uml.Model) on each one. May be null.
stdElementClasses - a list of Class objects used as described in checkStandardElementColl(java.util.Collection, boolean) to create standard model elements. May be null.
Method Detail

getDefaultElementFactoryList

public static java.util.List getDefaultElementFactoryList()
Get the default list of Model.ElementFactorys.

Returns:
the unmodifiable factory list

addDefaultElementFactory

public static void addDefaultElementFactory(Model.ElementFactory factory)
Add to the default list of Model.ElementFactorys.

Parameters:
factory - the Model.ElementFactory to add

loadXmi

public static Model loadXmi(java.lang.String xmiFileName)
                     throws java.io.IOException
Loads a Model from an XMI file. If there is more than one model in the XMI file, the first one is returned.

Parameters:
xmiFileName - the name of the file containing the model in XMI format
Returns:
the first model in the XMI file
Throws:
java.io.IOException - if there is a problem reading from the file

loadXmi

public static Model loadXmi(java.lang.String xmiFileName,
                            java.util.List factoryList,
                            java.util.List stdElementClasses)
                     throws java.io.IOException
Loads a Model from an XMI file. If there is more than one model in the XMI file, the first one is returned.

Parameters:
xmiFileName - the name of the file containing the model in XMI format
factoryList - the list of factories to use to create new elements at any level within the new Model. The factories are used in the reverse order that they occur in the list.
stdElementClasses - a list of Class objects used as described in checkStandardElementColl(java.util.Collection, boolean) to create standard model elements
Returns:
the first model in the XMI file
Throws:
java.io.IOException - if there is a problem reading from the file

getModel

public Model getModel()
Override the ModelElement method to return this Model

Overrides:
getModel in class ModelElement

getElementFactoryList

public java.util.List getElementFactoryList()
Get the list of ElementFactorys used to create ModelElements within this Model


addElementFactory

public void addElementFactory(Model.ElementFactory factory)
Add to the end of the list of ElementFactorys used to create ModelElements within this Model


getElementFactory

public Model.ElementFactory getElementFactory(java.lang.Class factoryClass)
Get the ElementFactory of the given class, if it exists in this Model.


getAllElements

public java.util.Collection getAllElements()
Get all the ModelElements in this Model.

Returns:
an unmodifiable collection of all the elements

getElementById

public ModelElement getElementById(java.lang.String id)
Get the ModelElement in this Model with a given XMI id, as returned by ModelElement.getId().

Parameters:
id - the id of the required ModelElement
Returns:
the ModelElement whose id is id, or null if there is no such object

getTopPackages

public java.util.Collection getTopPackages()
Get the top-level ModelPackages in this Model

Returns:
an unmodifiable list of ModelPackage objects

getAllStereotypes

public java.util.Collection getAllStereotypes()
Get all the Stereotypes in this Model. Note: the ModelElement.getStereotypes() method will return an empty list for a Model

Returns:
an unmodifiable list of Stereotype objects

getStereotype

public Stereotype getStereotype(java.lang.String name)
Get the Stereotype in this Model with a given name. The name may be either the full name, including the base class, as returned by Stereotype.getName(ru.novosoft.uml.foundation.core.MStereotype) or the short name as returned by Stereotype.getShortName().

Parameters:
name - the full or short name of the required Stereotype
Returns:
the Stereotype whose name is name, or null if there is no such object
Throws:
java.lang.IllegalArgumentException - if there is more than one Stereotype with a given short name

getStereotypes

public java.util.List getStereotypes(java.lang.String shortName)
Get the Stereotypes in this Model with a given short name.

Parameters:
shortName - short name of the required Stereotypes
Returns:
the list of Stereotype whose name is name, may be empty

getTagDefinitions

public java.util.Collection getTagDefinitions()
Get all the TagDefinitions in this Model.

Returns:
an unmodifiable list of TagDefinition objects

getTagDefinition

public TagDefinition getTagDefinition(java.lang.String name)
Get the TagDefinition in this Model with a given name

Parameters:
name - the name of the required TagDefinition
Returns:
the TagDefinition whose name is name, or null if there is no such object

getPackages

public java.util.Collection getPackages()
Get the ModelPackages at any level in this Model

Returns:
an unmodifiable list of ModelPackage objects

getPackage

public ModelPackage getPackage(java.lang.String name)
Get the ModelPackage at any level in this Model with a given name

Parameters:
name - the full name of the required ModelPackage
Returns:
the ModelPackage whose name is name, or null if there is no such object

makePackages

public ModelPackage makePackages(java.util.List packageChain)
Add any packages which do not exist in a hierarchical list, starting below this Model. If all the packages exist, nothing is added.

Parameters:
packageChain - the list of Stringpackage names, from top to bottom
Returns:
the bottom-most package in the chain

makePackages

public ModelPackage makePackages(java.lang.String fullPackageName)
Create a package and any necessary intermediate packages, starting below this Model. If all the packages exist, nothing is added.

Parameters:
fullPackageName - the full package name
Returns:
the package named by fullPackageName

getDataTypes

public java.util.Collection getDataTypes()
Get the DataTypes at any level in this Model

Returns:
an unmodifiable list of DataType objects

getDataType

public DataType getDataType(java.lang.String name)
Get the DataType at any level in this Model with a given name

Parameters:
name - the name of the required DataType
Returns:
the DataType whose name is name, or null if there is no such object

getDataTypePackage

public ModelPackage getDataTypePackage()
Get the ModelPackage to which DataTypes belong in this Model. This is the package with the name given by DATA_TYPE_PACKAGE_NAME. Create the package if it does not exist.

Returns:
the ModelPackage for data types

getClasses

public java.util.Collection getClasses()
Get the ClassTypes which are defined at any level in this Model.

Returns:
an unmodifiable list of ClassType objects

getClass

public ClassType getClass(java.lang.String name)
Get the ClassType defined at any level in this Model with a given name

Parameters:
name - the full name (see ModelElement.getFullName()) of the required ClassType
Returns:
the ClassType whose name is name, or null if there is no such object

selectElements

public java.util.Collection selectElements(Stereotype stereotype)
Get the ModelElements which are defined at any level in this Model, and which have a given stereotype.

Returns:
an unmodifiable list of the selected ClassType objects

selectClasses

public java.util.Collection selectClasses(Stereotype stereotype)
Get the ClassTypes which are defined at any level in this Model, and which have a given stereotype.

Returns:
an unmodifiable list of the selected ClassType objects

getInterfaces

public java.util.Collection getInterfaces()
Get the InterfaceTypes which are defined at any level in this Model.

Returns:
an unmodifiable list of InterfaceType objects

getInterface

public InterfaceType getInterface(java.lang.String name)
Get the InterfaceType defined at any level in this Model with a given name

Parameters:
name - the full name (see ModelElement.getFullName()) of the required InterfaceType
Returns:
the InterfaceType whose name is name, or null if there is no such object

getType

public Type getType(java.lang.String name)
Get the Type at any level in this Model with a given name. Searches first for a ClassType, then for an InterfaceType, then for a DataType.

Parameters:
name - the name of the required Type
Returns:
the Type whose name is name, or null if there is no such object
See Also:
#getInterface #getDataType

getGeneralizations

public java.util.Collection getGeneralizations()
Get the Generalizations which are defined at any level in this Model.

Returns:
an unmodifiable collection of Generalization objects

getAbstractions

public java.util.Collection getAbstractions()
Get the Abstractions which are defined at any level in this Model.

Returns:
an unmodifiable collection of Abstraction objects

getAssociations

public java.util.Collection getAssociations()
Get the Associations which are defined at any level in this Model.

Returns:
an unmodifiable collection of Association objects

getActors

public java.util.Collection getActors()
Get the Actors which are defined at any level in this Model.

Returns:
an unmodifiable list of Actor objects

getActor

public Actor getActor(java.lang.String name)
Get the Actor defined at any level in this Model with a given name

Parameters:
name - the full name (see ModelElement.getFullName()) of the required Actor
Returns:
the Actor whose name is name, or null if there is no such object

writeXmi

public void writeXmi(java.lang.String xmiFileName)
              throws java.io.IOException
Writes a Model to an XMI file.

Parameters:
xmiFileName - the name of the file to which the model is written in XMI format
Throws:
java.io.IOException - if there is a problem writing to the file

extractStandardElements

public java.util.Set extractStandardElements(java.lang.Class defClass)
Get the StandardElementDef constants defined by a Class.

Parameters:
defClass - the Class containing the StandardElementDefs
Returns:
a Set of StandardElementDef objects

checkStandardElementColl

public boolean checkStandardElementColl(java.util.Collection defObjects,
                                        boolean create)
Check whether the elements defined by a set of StandardElementDefs and StandardElementDef constants in Classes are present in this model. Optionally create the elements. Log error if an element is not present and create is false, or info if an element is created.

Parameters:
create - if true, and an element defined in defClasses is not present, create it.
Returns:
true if all the elements were present or were created

checkStandardElement

public boolean checkStandardElement(StandardElementDef def,
                                    boolean create)
Check whether the element defined by a StandardElementDef is present in this model. Optionally create the element. Log error if not present and create is false, or info if created.

Parameters:
def - the StandardElementDef of the element to check
create - if true, and the element defined by def is not present, create it.
Returns:
true if the element was present already, or it was created, false if it is missing

checkStandardElements

public boolean checkStandardElements(java.util.Collection defs,
                                     boolean create)
Check whether the elements defined by a Collection of StandardElementDefs are present in this model. Optionally create the elements. Log error if not present and create is false, or warning if an element is created.

Parameters:
defs - the StandardElementDefs of the elements to check
create - if true, and an element defined one of the defs is not present, create it.
Returns:
true if all element were present already, or were created, false if any were missing

getUmlCorePackage

ru.novosoft.uml.foundation.core.MCorePackage getUmlCorePackage()
Get the NSUML core package connected with this Model. This can be used for creating new NSUML core objects.

Returns:
the core package

getUmlModelManagementPackage

ru.novosoft.uml.model_management.MModelManagementPackage getUmlModelManagementPackage()
Get the NSUML model management package connected with this Model. This can be used for creating new NSUML model objects.

Returns:
the model management package

getUmlDataTypesPackage

ru.novosoft.uml.foundation.data_types.MDataTypesPackage getUmlDataTypesPackage()
Get the NSUML core package connected with this Model. This can be used for creating new NSUML datatype objects.

Returns:
the data types package

store

protected void store(ModelElement me)
Add a ModelElement instance to this Model.

Parameters:
me - The ModelElement to be added to this Model. Must not be null and its name property must not be null
Throws:
java.lang.IllegalArgumentException - if me already belongs to this Model

load

protected void load()
Override ModelElement.load() to get the Stereotypes first.

Overrides:
load in class ModelElement

loadTagDefinitions

protected void loadTagDefinitions(java.util.Collection c)
Load the MTagDefinitions of a given collection, choosing those which are instances of a certain class. Calls ModelElement.loadElement(ru.novosoft.uml.foundation.core.MModelElement) for each one.

Parameters:
c - the MModelElements from which to load the MTagDefinitions

createElement

public ModelElement createElement(ru.novosoft.uml.foundation.core.MModelElement me,
                                  ModelElement parent)
Create an element using the Model.ElementFactorys with which this Model was created. They are tried in reverse order. If none of the ElementFactorys return a new element, return null.

Parameters:
me - the model element being loaded
parent - the element which will contain the new ModelElement
Returns:
the new ModelElement, or null if no ElementFactory can create one for me

checkValid

public void checkValid()
                throws java.lang.IllegalStateException
Check whether this object is valid.

Overrides:
checkValid in class ModelElement
Throws:
java.lang.IllegalStateException - if a problem is found

getSubElementStore

protected ModelElement.ElementStore getSubElementStore(java.lang.Class meClass)
Overridden to return the sub-element ModelElement.ElementStore into which an object of the class meClass should be stored.

Overrides:
getSubElementStore in class ModelElement
Returns:
the store to use, or the superclass implementation if the class of the object is not stored by this class.


Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.