org.eclipse.ocl.examples.pivot
Class AbstractEnvironment

java.lang.Object
  extended by org.eclipse.ocl.examples.pivot.AbstractBasicEnvironment
      extended by org.eclipse.ocl.examples.pivot.AbstractEnvironment
All Implemented Interfaces:
Adaptable, BasicEnvironment, Customizable, Environment, Environment.Internal
Direct Known Subclasses:
PivotEnvironment

public abstract class AbstractEnvironment
extends AbstractBasicEnvironment
implements Environment.Internal

A partial implementation of the Environment interface providing some useful common behavior for providers of metamodel bindings. It is recommended to extend this class rather than to implement the Environment interface from scratch.

In particular, this class provides:

along with some subclass hook methods and convenience methods.

See the Environment class for a description of the generic type parameters of this class.

Author:
Christian W. Damus (cdamus)

Nested Class Summary
protected  class AbstractEnvironment.VariableEntry
          Wrapper for OCL variable declarations that additionally tracks whether they are explicit or implicit variables.
 
Nested classes/interfaces inherited from interface org.eclipse.ocl.examples.pivot.Environment
Environment.Internal, Environment.Registry
 
Field Summary
 
Fields inherited from interface org.eclipse.ocl.examples.pivot.Environment
OCL_NAMESPACE_URI, RESULT_VARIABLE_NAME, SELF_VARIABLE_NAME
 
Constructor Summary
protected AbstractEnvironment()
          Initializes me without a parent environment.
protected AbstractEnvironment(AbstractEnvironment parent)
          Initializes me with the specified parent environment, which should be of the same type as me.
protected AbstractEnvironment(Environment.Internal parent)
          Initializes me with the specified parent environment.
 
Method Summary
 boolean addElement(java.lang.String name, Variable elem, boolean isExplicit)
          Adds a variable declaration to the environment.
 void dispose()
          I dispose my type resolver, if it is an AbstractTypeResolver and I am the root environment (which owns the resolver).
 Type getContextClassifier()
           
 Package getContextPackage()
          Obtains my context package, if any.
 Environment.Internal getInternalParent()
          Obtains my parent environment after construction.
 AbstractEnvironment getParent()
          Deprecated. Since 1.2, use the getInternalParent() method, instead.
 Variable getSelfVariable()
          Gets the self variable, looking it up in a parent environment if necessary.
 boolean notOK(Option<ProblemHandler.Severity> option)
          Queries whether I have a non-OK setting for the specified problem option.
protected  void setContextOperation(Operation contextOperation)
          Assigns my context operation.
protected  void setContextPackage(Package contextPackage)
          Assigns my context package.
protected  void setContextProperty(Property contextProperty)
          Assigns my context property.
 void setInternalParent(Environment.Internal parent)
          Assigns me a parent environment after construction.
protected  void setParent(AbstractEnvironment parent)
          Assigns me a parent environment after construction.
 void setSelfVariable(Variable var)
          Sets the "self" variable that is the implicit source of any property, operation, or association class call.
 
Methods inherited from class org.eclipse.ocl.examples.pivot.AbstractBasicEnvironment
basicGetOptions, clearOptions, getAdapter, getOptions, getValue, isEnabled, putOptions, removeOption, removeOptions, setOption, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.ocl.examples.pivot.Adaptable
getAdapter
 
Methods inherited from interface org.eclipse.ocl.examples.pivot.Customizable
clearOptions, getOptions, getValue, isEnabled, putOptions, removeOption, removeOptions, setOption
 
Methods inherited from interface org.eclipse.ocl.examples.pivot.Environment
getDefinition, getFactory, getOCLFactory, getOCLStandardLibrary, getStates, getTypeManager
 

Constructor Detail

AbstractEnvironment

protected AbstractEnvironment()
Initializes me without a parent environment.


AbstractEnvironment

protected AbstractEnvironment(Environment.Internal parent)
Initializes me with the specified parent environment.

Parameters:
parent - an environment (or null)

AbstractEnvironment

protected AbstractEnvironment(AbstractEnvironment parent)
Initializes me with the specified parent environment, which should be of the same type as me.

Parameters:
parent - an environment of the same type as me (or null)
Method Detail

getInternalParent

public Environment.Internal getInternalParent()
Description copied from interface: Environment.Internal
Obtains my parent environment after construction.

Specified by:
getInternalParent in interface Environment.Internal
Returns:
my parent

getParent

@Deprecated
public AbstractEnvironment getParent()
Deprecated. Since 1.2, use the getInternalParent() method, instead.

Description copied from interface: Environment
Obtains my parent environment, if I have one. My parent environment implements a nesting scope of variable names, some of which names may be shadowed by variables in my scope.

Specified by:
getParent in interface Environment
Overrides:
getParent in class AbstractBasicEnvironment
Returns:
my parent, or null if I am a root environment

setInternalParent

public void setInternalParent(Environment.Internal parent)
Assigns me a parent environment after construction. It is not advisable to set the parent to null if I previously had one.

Specified by:
setInternalParent in interface Environment.Internal
Parameters:
parent - my new parent

setParent

protected void setParent(AbstractEnvironment parent)
Assigns me a parent environment after construction. It is not advisable to set the parent to null if I previously had one.

Parameters:
parent - my new parent

getContextPackage

public Package getContextPackage()
Description copied from interface: Environment
Obtains my context package, if any. The constraints in an OCL document need not declare a package context, but it is at least implicit as the nearest package containing the context classifier.

Specified by:
getContextPackage in interface Environment
Returns:
my context package
See Also:
#getContextClassifier()

setContextPackage

protected void setContextPackage(Package contextPackage)
Assigns my context package.

Parameters:
contextPackage - my new context package

getContextClassifier

public Type getContextClassifier()

setContextOperation

protected void setContextOperation(Operation contextOperation)
Assigns my context operation. This method does not create the variables for parameters and the return result.

Parameters:
contextOperation - my context operation

setContextProperty

protected void setContextProperty(Property contextProperty)
Assigns my context property.

Parameters:
contextProperty - my context property

addElement

public boolean addElement(java.lang.String name,
                          Variable elem,
                          boolean isExplicit)
Description copied from interface: Environment
Adds a variable declaration to the environment. If the name is null, then a new unique temporary name is generated (this is useful for implicit variables).

Specified by:
addElement in interface Environment
Parameters:
name - the name of the variable, or null
elem - a variable declaration
isExplicit - whether this is an explicitly declared variable
Returns:
true if the variable was successfully added because it wasn't already declared locally in this environment; false, otherwise

setSelfVariable

public void setSelfVariable(Variable var)
Description copied from interface: Environment
Sets the "self" variable that is the implicit source of any property, operation, or association class call.

Specified by:
setSelfVariable in interface Environment
Parameters:
var - the "self" variable

getSelfVariable

public Variable getSelfVariable()
Description copied from interface: Environment
Gets the self variable, looking it up in a parent environment if necessary.

Specified by:
getSelfVariable in interface Environment
Returns:
the self variable, or null if none (which should only be the case in a root environment having only a package context, if even that)

notOK

public boolean notOK(Option<ProblemHandler.Severity> option)
Queries whether I have a non-OK setting for the specified problem option. In such cases, I will need to be concerned with reporting the problem.

Parameters:
option - the problem option
Returns:
whether I have a setting for it that is not OK
See Also:
ProblemHandler.Severity.OK

dispose

public void dispose()
I dispose my type resolver, if it is an AbstractTypeResolver and I am the root environment (which owns the resolver).

Specified by:
dispose in interface Environment.Internal
Since:
1.2