Dresden OCL Toolkit

tudresden.ocl
Class NameCreator

java.lang.Object
  extended bytudresden.ocl.NameCreator

public class NameCreator
extends Object

A class that provides unique names for the processing of OCL expressions. Such names are necessary for normalization and for generating Java code. A generated name consist of three parts: a prefix which is usually "tuddOcl", a part called infix that can be set by the caller (might be something like "Var" or "Inv", and a postfix part chosen by NameCreator to make the name unique. A special instance of this class can be accessed through the getInstance method, but a strict singleton pattern is not enforced to allow several name spaces.

Author:
Frank Finger

Nested Class Summary
(package private)  class NameCreator.NameReserver
          This inner class is used by the method reserveAllNames.
 
Field Summary
static String defaultPrefix
           
protected  HashMap fixmap
          maps infixes (Strings) to Integers that will become postfixes
protected  HashSet names
          contains all registered names
protected  String prefix
          the prefix String, by default "tuddOcl"
protected static NameCreator theInstance
           
 
Constructor Summary
NameCreator()
          creates a new NameCreator with the default prefix String, "tuddOcl"; consider using the getInstance method if you don't need seperate name spaces
NameCreator(String prefix)
          creates a new NameCreator with the given prefix String; consider using the getInstance method if you don't need seperate name spaces
 
Method Summary
 void clear()
          re-initialize this name creator, that means delete all registered names and restart postfix count
static NameCreator getInstance()
           
 String getPrefix()
           
 String getUniqueName()
           
 String getUniqueName(String infix)
          create a new unique name (unique wrt.
 void reserveAllNames(OclTree tree)
          Register all names used as variables in the OCL constraint represented by the given OclTree object as reserved, including self and, if the constraint contains a post condition, result.
 boolean reserveName(String s)
          register the name given as parameter as reserved; this name will not be returned as a new unique name in further calls to getUniqueName
 void setPrefix(String prefix)
          changes the prefix to the given String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultPrefix

public static String defaultPrefix

theInstance

protected static NameCreator theInstance

names

protected HashSet names
contains all registered names


fixmap

protected HashMap fixmap
maps infixes (Strings) to Integers that will become postfixes


prefix

protected String prefix
the prefix String, by default "tuddOcl"

Constructor Detail

NameCreator

public NameCreator(String prefix)
creates a new NameCreator with the given prefix String; consider using the getInstance method if you don't need seperate name spaces


NameCreator

public NameCreator()
creates a new NameCreator with the default prefix String, "tuddOcl"; consider using the getInstance method if you don't need seperate name spaces

Method Detail

getInstance

public static NameCreator getInstance()
Returns:
the special name creator object that is intended to be used for a single name space

setPrefix

public void setPrefix(String prefix)
changes the prefix to the given String


getPrefix

public String getPrefix()
Returns:
this NameCreators prefix

getUniqueName

public String getUniqueName()
Returns:
an unique name with empty infix part

getUniqueName

public String getUniqueName(String infix)
create a new unique name (unique wrt. the names registered with this name creator) with the given String as infix part


reserveName

public boolean reserveName(String s)
register the name given as parameter as reserved; this name will not be returned as a new unique name in further calls to getUniqueName

Returns:
true if the reservation was successful, i.e. if the name was not already reserved

reserveAllNames

public void reserveAllNames(OclTree tree)
Register all names used as variables in the OCL constraint represented by the given OclTree object as reserved, including self and, if the constraint contains a post condition, result. This method does not report an error if one of the names was reserved before.


clear

public void clear()
re-initialize this name creator, that means delete all registered names and restart postfix count


Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.