com.ashridgetech.jamda.uml
Class AbstractElementFactory

java.lang.Object
  |
  +--com.ashridgetech.jamda.uml.AbstractElementFactory
All Implemented Interfaces:
Model.ElementFactory
Direct Known Subclasses:
DataTransferObjectTypeFactory, StdElementFactory

public abstract class AbstractElementFactory
extends java.lang.Object
implements Model.ElementFactory

A base implementation of Model.ElementFactory. com.ashridgetech.jamda.uml package. Allows the Class of ModelElement produced for a particular MModelElement class or stereotype name to be set. More complex rules may be implemented by overriding createCustom(ru.novosoft.uml.foundation.core.MModelElement, com.ashridgetech.jamda.uml.ModelElement).

Version:
1.0
Author:
paulb

Constructor Summary
protected AbstractElementFactory()
          Default constructor for use by instances which are to be used as prototypes.
protected AbstractElementFactory(AbstractElementFactory prototype, Model model)
          Constructor for use when creating a copy of an existing factory for a specific Model.
 
Method Summary
abstract  Model.ElementFactory createCopy(Model model)
          Create the correct ElementFactory for model.
protected  ModelElement createCustom(ru.novosoft.uml.foundation.core.MModelElement me, ModelElement parent)
          May be overridden by subclasses to create the required ModelElement, for any or all MModelElements.
 ModelElement createElement(ru.novosoft.uml.foundation.core.MModelElement me, ModelElement parent)
          Create the appropriate subclass of ModelElement.
protected  java.lang.reflect.Constructor getConstructor(ru.novosoft.uml.foundation.core.MModelElement me)
          Obtain a constructor for a ModelElement subclass.
 Model getModel()
          Get the Model to which this AbstractElementFactory is attached.
protected  java.lang.reflect.Constructor lookupConstructor(java.lang.Class meClass)
          Look up a constructor for a ModelElement subclass by the interfaces implemented by meClass.
protected  java.lang.reflect.Constructor lookupConstructor(java.lang.String stereotypeName)
          Look up a constructor for a ModelElement subclass by stereotype name.
protected  void setClass(java.lang.Class nsumlElementClass, java.lang.Class modelElementClass)
          Set a ModelElement subclass to be created for a subclass of MModelElement.
protected  void setClass(StandardStereotypeDef stereotypeDef)
          Set a ModelElement subclass to be created for a particular stereotype.
protected  void setClass(StandardStereotypeDef stereotypeDef, java.lang.Class modelElementClass)
          Set a ModelElement subclass to be created for a particular stereotype.
protected  void setClassesForStereotypes(java.lang.Class stereotypeConstantClass)
          Set the ModelElement subclass to be created for the StandardStereotypeDef constants in a given class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractElementFactory

protected AbstractElementFactory()
Default constructor for use by instances which are to be used as prototypes.


AbstractElementFactory

protected AbstractElementFactory(AbstractElementFactory prototype,
                                 Model model)
Constructor for use when creating a copy of an existing factory for a specific Model.

Parameters:
prototype - the factory to be copied
model - the model which will use the new factory
Method Detail

getModel

public Model getModel()
Get the Model to which this AbstractElementFactory is attached.

Returns:
the Model - or null if this instance is not attached to a specific Model

createElement

public ModelElement createElement(ru.novosoft.uml.foundation.core.MModelElement me,
                                  ModelElement parent)
Create the appropriate subclass of ModelElement. This implementation first calls createCustom(ru.novosoft.uml.foundation.core.MModelElement, com.ashridgetech.jamda.uml.ModelElement). If that returns null, it calls getConstructor(ru.novosoft.uml.foundation.core.MModelElement) and constructs the new ModelElement using it. If getConstructor(ru.novosoft.uml.foundation.core.MModelElement) returns null, or if the constructor returned cannot be used to create a ModelElement, an ModelElement.UnknownElementException is thrown.

Specified by:
createElement in interface Model.ElementFactory
Parameters:
me - the model element being loaded
parent - the element which will contain the new ModelElement
Returns:
the new ModelElement, or null if this ElementFactory cannot create one for me
See Also:
Model.ElementFactory.createElement(ru.novosoft.uml.foundation.core.MModelElement, com.ashridgetech.jamda.uml.ModelElement)

createCopy

public abstract Model.ElementFactory createCopy(Model model)
Create the correct ElementFactory for model. Subclasses should implement this by creating a new instance with a constructor that calls AbstractElementFactory(AbstractElementFactory,Model) and then copies any data specific to the subclass.

Specified by:
createCopy in interface Model.ElementFactory
Parameters:
model - the model being loaded
Returns:
the new ElementFactory.
See Also:
Model.Model(ru.novosoft.uml.model_management.MModel, java.util.List, java.util.List), Model.getDefaultElementFactoryList()

createCustom

protected ModelElement createCustom(ru.novosoft.uml.foundation.core.MModelElement me,
                                    ModelElement parent)
May be overridden by subclasses to create the required ModelElement, for any or all MModelElements. This implementation returns null.

Parameters:
me - the MModelElement for which a ModelElement is required
parent - the ModelElement which is to be the parent of the one created
Returns:
the new object, or null if the class does not wish to create an object in a customised way for this MModelElement
See Also:
lookupConstructor(java.lang.Class)

getConstructor

protected java.lang.reflect.Constructor getConstructor(ru.novosoft.uml.foundation.core.MModelElement me)
Obtain a constructor for a ModelElement subclass. This implementation first calls lookupConstructor(String) for the name of each stereotype attached to me. If no constructor is found, it then calls lookupConstructor(Class) with the class of me. If no constructor is found, it returns null.

Parameters:
me - the MModelElement for which a constructor is required
Returns:
the constructor, or null if there is no suitable constructor for me
See Also:
lookupConstructor(java.lang.Class)

lookupConstructor

protected java.lang.reflect.Constructor lookupConstructor(java.lang.Class meClass)
Look up a constructor for a ModelElement subclass by the interfaces implemented by meClass. The constructor must have been registered using setClass( Class, Class )

Parameters:
meClass - the MModelElement Class for which a constructor is required
Returns:
the constructor, or null if there is no suitable constructor for meClass
See Also:
getConstructor(ru.novosoft.uml.foundation.core.MModelElement)

lookupConstructor

protected java.lang.reflect.Constructor lookupConstructor(java.lang.String stereotypeName)
Look up a constructor for a ModelElement subclass by stereotype name. The constructor must have been registered using setClass( StandardStereotypeDef, Class )

Parameters:
stereotypeName - the name of the stereotype for which a class is required
Returns:
the constructor, or null if there is no suitable constructor for stereotypeName
See Also:
getConstructor(ru.novosoft.uml.foundation.core.MModelElement)

setClass

protected void setClass(java.lang.Class nsumlElementClass,
                        java.lang.Class modelElementClass)
Set a ModelElement subclass to be created for a subclass of MModelElement.

Parameters:
nsumlElementClass - the MModelElement interface - this must be an interface, not a class
modelElementClass - the ModelElement class to construct, for nsumlElementClass This class must have a constructor with two parameters, the first a subclass of MModelElement and the second a subclass of ModelElementThrows:
java.lang.IllegalArgumentException - if nsumlElementClass does not have the correct constructor
See Also:
lookupConstructor(java.lang.Class)

setClass

protected void setClass(StandardStereotypeDef stereotypeDef,
                        java.lang.Class modelElementClass)
Set a ModelElement subclass to be created for a particular stereotype.

Parameters:
stereotypeDef - the definition of the stereotype for which a class is being set
modelElementClass - the ModelElement class to construct, for the Stereotype defined by stereotypeDef This class must have a constructor with two parameters, the first a subclass of MModelElement and the second a subclass of ModelElementThrows:
java.lang.IllegalArgumentException - if modelElementClass does not have the correct constructor
See Also:
setClass(StandardStereotypeDef), lookupConstructor(java.lang.Class)

setClass

protected void setClass(StandardStereotypeDef stereotypeDef)
Set a ModelElement subclass to be created for a particular stereotype. If stereotypeDef returns null from StandardStereotypeDef.getElementClass(), no class is set.

Parameters:
stereotypeDef - the definition of the stereotype for which a class is being set for stereotypeName
Throws:
java.lang.IllegalArgumentException - if the Class returned by StandardStereotypeDef.getElementClass() does not have the correct constructor

setClassesForStereotypes

protected void setClassesForStereotypes(java.lang.Class stereotypeConstantClass)
Set the ModelElement subclass to be created for the StandardStereotypeDef constants in a given class.

Parameters:
stereotypeConstantClass - the class containing the definitions of the stereotypes for which a class is being set. The values of all the public static variables of this class with a type of StandardStereotypeDef will be used to call setClass(StandardStereotypeDef).
Throws:
java.lang.IllegalArgumentException - if any StandardStereotypeDef's modelElementClass does not have the correct constructor
See Also:
setClass(StandardStereotypeDef)


Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.