be.ac.vub.cocompose.lang.impl.core
Class DefaultNamespace

java.lang.Object
  extended bybe.ac.vub.cocompose.lang.impl.DefaultElement
      extended bybe.ac.vub.cocompose.lang.impl.core.DefaultModelElement
          extended bybe.ac.vub.cocompose.lang.impl.core.DefaultNamespace
All Implemented Interfaces:
Cloneable, Element, ModelElement, Namespace, VisitedElement
Direct Known Subclasses:
DefaultConstraint, DefaultImplementationRolePart, DefaultModel, DefaultProperty, DefaultRefinement, DefaultRelationElement

public abstract class DefaultNamespace
extends DefaultModelElement
implements Namespace

Default container and namespace mechanism for all CoCompose language elements.

Since:
0.2.0
Version:
0.2.9, 27/04/2004
Author:
Dennis Wagelaar

Constructor Summary
DefaultNamespace()
           
 
Method Summary
 void accept(ModelVisitor modelVisitor)
          Accepts a visitor.
 void addOwnedElement(int index, ModelElement modelElement)
          Adds an element to this namespace.
 void addOwnedElement(ModelElement modelElement)
          Adds an element to this namespace.
 ModelElement getDeepOwnedElement(ModelElement copy)
          Retrieves an owned element in this namespace or a nested namespace.
 List getDeepOwnedElements(Class elementClass)
          Returns the elements of a given class within this namespace and nested namespaces.
 ModelElement getOwnedElement(String name)
          Retrieves an owned element by its name.
 String getOwnedElementId(ModelElement modelElement)
          Returns a new Id for the given ModelElement.
 List getOwnedElements()
          Returns the elements within this namespace.
 List getOwnedElements(Class elementClass)
          Returns the elements of a given class within this namespace.
 Set getOwnedIds()
          Returns the global ids for the root namespace.
 boolean isRegistered(String name)
          Checks whether a name is already registered within this namespace.
 void registerNameChange(String oldName, String newName)
          Registers an element name within this namespace.
 void removeOwnedElement(ModelElement modelElement)
          Removes a element from this namespace.
protected  int translateIndex(int index, List otherList)
          Translates the given ownedElements index to an otherList index.
protected  int translateIndex(int index, List sourceList, List otherList)
          Translates the given ownedElements index to an otherList index.
 
Methods inherited from class be.ac.vub.cocompose.lang.impl.core.DefaultModelElement
getId, getModel, getName, getNamespace, getRootNamespace, setId, setName, setNamespace, toString
 
Methods inherited from class be.ac.vub.cocompose.lang.impl.DefaultElement
addPropertyChangeListener, firePropertyChange, fireStructureChange, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface be.ac.vub.cocompose.lang.core.ModelElement
getId, getModel, getName, getNamespace, getRootNamespace, setId, setName, setNamespace
 
Methods inherited from interface be.ac.vub.cocompose.lang.Element
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

DefaultNamespace

public DefaultNamespace()
Method Detail

accept

public void accept(ModelVisitor modelVisitor)
            throws ModelElementException
Accepts a visitor.

Specified by:
accept in interface VisitedElement
Overrides:
accept in class DefaultModelElement
Parameters:
modelVisitor - The visitor to accept.
Throws:
ModelElementException

addOwnedElement

public void addOwnedElement(ModelElement modelElement)
                     throws ModelElementException
Adds an element to this namespace.

Specified by:
addOwnedElement in interface Namespace
Parameters:
modelElement - - the element to add.
Throws:
ModelElementException - - if the name of the element is already used within this namespace.

addOwnedElement

public void addOwnedElement(int index,
                            ModelElement modelElement)
                     throws ModelElementException
Adds an element to this namespace.

Specified by:
addOwnedElement in interface Namespace
Parameters:
index - - the index at which to add the element.
modelElement - - the element to add.
Throws:
ModelElementException - - if the name of the element is already used within this namespace.

removeOwnedElement

public void removeOwnedElement(ModelElement modelElement)
Removes a element from this namespace.

Specified by:
removeOwnedElement in interface Namespace
Parameters:
modelElement - - the element to remove.

getOwnedElements

public List getOwnedElements()
Returns the elements within this namespace.

Specified by:
getOwnedElements in interface Namespace
Returns:
a copy of the List of owned elements.

getOwnedElements

public List getOwnedElements(Class elementClass)
Returns the elements of a given class within this namespace.

Specified by:
getOwnedElements in interface Namespace
Parameters:
elementClass - the element class.
Returns:
the List of owned elements.

getDeepOwnedElements

public List getDeepOwnedElements(Class elementClass)
Returns the elements of a given class within this namespace and nested namespaces.

Specified by:
getDeepOwnedElements in interface Namespace
Parameters:
elementClass - the element class.
Returns:
the List of owned elements.

getOwnedElement

public ModelElement getOwnedElement(String name)
Retrieves an owned element by its name.

Specified by:
getOwnedElement in interface Namespace
Parameters:
name - - the name of the element to retrieve.
Returns:
the element with the given name or null if it doesn't exist.

getDeepOwnedElement

public ModelElement getDeepOwnedElement(ModelElement copy)
Retrieves an owned element in this namespace or a nested namespace.

Specified by:
getDeepOwnedElement in interface Namespace
Parameters:
copy - - the (remote) copy of the element to retrieve.
Returns:
the owned element or null if it doesn't exist.

isRegistered

public boolean isRegistered(String name)
Checks whether a name is already registered within this namespace.

Specified by:
isRegistered in interface Namespace
Parameters:
name - - the name to check.
Returns:
true if and only if the name is already registered.

registerNameChange

public void registerNameChange(String oldName,
                               String newName)
                        throws ModelElementException
Registers an element name within this namespace.

Specified by:
registerNameChange in interface Namespace
Parameters:
oldName - - the name to change.
newName - - the name to change into.
Throws:
ModelElementException - - if the new name is already used or if the old name does not exist in this namespace.

getOwnedElementId

public String getOwnedElementId(ModelElement modelElement)
Returns a new Id for the given ModelElement.

Specified by:
getOwnedElementId in interface Namespace
Parameters:
modelElement - - the element to get the Id for.
Returns:
The element Id or null.

getOwnedIds

public Set getOwnedIds()
Returns the global ids for the root namespace.

Specified by:
getOwnedIds in interface Namespace
Returns:
the global ids for the root namespace.

translateIndex

protected int translateIndex(int index,
                             List otherList)
Translates the given ownedElements index to an otherList index.

Parameters:
index - - the index to translate.
otherList - - the other list to which the index should be translated.
Returns:
the translated index.

translateIndex

protected int translateIndex(int index,
                             List sourceList,
                             List otherList)
Translates the given ownedElements index to an otherList index.

Parameters:
index - - the index to translate.
sourceList - - the list to which the index refers.
otherList - - the other list to which the index should be translated.
Returns:
the translated index.