org.eclipse.ocl.examples.pivot
Class AbstractEnvironment

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

public abstract class AbstractEnvironment
extends AbstractBasicEnvironment<Environment>
implements Environment

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.Registry
 
Field Summary
 
Fields inherited from class org.eclipse.ocl.examples.pivot.AbstractBasicEnvironment
parent
 
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(Environment 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()
          Dispose of any owned objects.
 Type getContextClassifier()
          Obtains the context classifier of this environment.
 Operation getContextOperation()
          Obtains the context operation of this environment, if it is an operation context.
 Package getContextPackage()
          Obtains my context package, if any.
 Property getContextProperty()
          Obtains the context property of this environment, if it is a property context.
 Variable getSelfVariable()
          Gets the self variable, looking it up in a parent environment if necessary.
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 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, getParent, getValue, isEnabled, notOK, 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.Environment
getDefinition, getFactory, getMetaModelManager, getOCLFactory, getOCLStandardLibrary, getParent, getStates
 
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
 

Constructor Detail

AbstractEnvironment

protected AbstractEnvironment()
Initializes me without a parent environment.


AbstractEnvironment

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

Parameters:
parent - an environment (or null)
Method Detail

addElement

public boolean addElement(@NonNull
                          java.lang.String name,
                          @NonNull
                          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

dispose

public void dispose()
Dispose of any owned objects.

Specified by:
dispose in interface Environment

getContextPackage

@Nullable
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:
Environment.getContextClassifier()

getContextClassifier

@Nullable
public Type getContextClassifier()
Description copied from interface: Environment
Obtains the context classifier of this environment. This is the type of the self context variable.

Specified by:
getContextClassifier in interface Environment
Returns:
the context classifier

getContextOperation

@Nullable
public Operation getContextOperation()
Description copied from interface: Environment
Obtains the context operation of this environment, if it is an operation context.

Specified by:
getContextOperation in interface Environment
Returns:
the context operation, or null if this is not an operation environment

getContextProperty

@Nullable
public Property getContextProperty()
Description copied from interface: Environment
Obtains the context property of this environment, if it is a property context.

Specified by:
getContextProperty in interface Environment
Returns:
the context property, or null if this is not a property environment

getSelfVariable

@Nullable
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)

setContextOperation

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

Parameters:
contextOperation - my context operation

setContextPackage

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

Parameters:
contextPackage - my new context package

setContextProperty

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

Parameters:
contextProperty - my context property

setSelfVariable

public void setSelfVariable(@NonNull
                            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