org.eclipse.ocl.examples.pivot.evaluation
Class AbstractEvaluationEnvironment

java.lang.Object
  extended by org.eclipse.ocl.examples.pivot.evaluation.AbstractEvaluationEnvironment
All Implemented Interfaces:
Adaptable, Customizable, EvaluationEnvironment
Direct Known Subclasses:
PivotEvaluationEnvironment

public abstract class AbstractEvaluationEnvironment
extends java.lang.Object
implements EvaluationEnvironment, Adaptable, Customizable

A partial implementation of the EvaluationEnvironment interface, providing some useful common behaviors. Implementors of metamodel-specific environments are encourage to extend this class rather than implement an evaluation environment "from scratch."

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

Since the 1.2 release, this interface is Adaptable to support the optional adapter protocols such as EvaluationEnvironment.Enumerations and Customizable.

Author:
Christian W. Damus (cdamus)

Field Summary
protected  TypeManager typeManager
           
 
Constructor Summary
protected AbstractEvaluationEnvironment(EvaluationEnvironment parent)
           
protected AbstractEvaluationEnvironment(TypeManager typeManager)
           
 
Method Summary
 void add(VariableDeclaration referredVariable, Value value)
          Adds the supplied name and value binding to the environment
protected  java.util.Map<Option<?>,java.lang.Object> basicGetOptions()
           
 void clear()
          Clears the environment of variables.
 java.util.Map<Option<?>,java.lang.Object> clearOptions()
          Clears all options.
<T> T
getAdapter(java.lang.Class<T> adapterType)
          Implements the interface method by testing whether I am an instance of the requested adapter type.
 java.util.Map<Option<?>,java.lang.Object> getOptions()
          Obtains a copy of my map of options.
protected  EvaluationEnvironment getParent()
          Obtains my parent (nesting) environment.
 TypeManager getTypeManager()
          Obtains the Java-language value of the specified enumeration literal.
<T> T
getValue(Option<T> option)
          Obtains the value of the specified option's setting in the my options map.
 Value getValueOf(VariableDeclaration referredVariable)
          Returns the value associated with the supplied name
 boolean isEnabled(Option<java.lang.Boolean> option)
          Queries whether the specified boolean-valued option is enabled.
 boolean overrides(Operation operation, int opcode)
          By default, a subclass will not support overriding the operations defined by the OCL Standard Library.
<T> void
putOptions(java.util.Map<? extends Option<T>,? extends T> options)
          Adds options to apply to my behaviour.
 Value remove(VariableDeclaration referredVariable)
          Deprecated. 
<T> T
removeOption(Option<T> option)
          Removes the specified option.
<T> java.util.Map<Option<T>,T>
removeOptions(java.util.Collection<Option<T>> options)
          Removes the specified options.
 void replace(VariableDeclaration referredVariable, Value value)
          Replaces the current value of the supplied name with the supplied value.
<T> void
setOption(Option<T> option, T value)
          Add an option to apply to my behaviour.
 NullValue throwInvalidEvaluation(InvalidValueException e)
           
 NullValue throwInvalidEvaluation(java.lang.String message)
           
 NullValue throwInvalidEvaluation(java.lang.String message, OclExpression expression)
           
 NullValue throwInvalidEvaluation(java.lang.String message, OclExpression expression, java.lang.Object context)
           
 NullValue throwInvalidEvaluation(java.lang.Throwable e, OclExpression expression, java.lang.Object context, java.lang.String message, java.lang.Object... bindings)
           
 java.lang.String toString()
          Returns a string representation of the bindings
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.ocl.examples.pivot.evaluation.EvaluationEnvironment
createModelManager, getType, getValueFactory, navigateAssociationClass
 

Field Detail

typeManager

protected final TypeManager typeManager
Constructor Detail

AbstractEvaluationEnvironment

protected AbstractEvaluationEnvironment(TypeManager typeManager)

AbstractEvaluationEnvironment

protected AbstractEvaluationEnvironment(EvaluationEnvironment parent)
Method Detail

getParent

protected EvaluationEnvironment getParent()
Obtains my parent (nesting) environment.

Returns:
my parent environment, or null if none

getTypeManager

public TypeManager getTypeManager()
Description copied from interface: EvaluationEnvironment
Obtains the Java-language value of the specified enumeration literal. Often, this is an instance of an EMF-generated enumeration type.

Specified by:
getTypeManager in interface EvaluationEnvironment
Returns:
the corresponding run-time instance

getValueOf

public Value getValueOf(VariableDeclaration referredVariable)
Returns the value associated with the supplied name

Specified by:
getValueOf in interface EvaluationEnvironment
Parameters:
name - the name whose value is to be returned
Returns:
the value associated with the name

replace

public void replace(VariableDeclaration referredVariable,
                    Value value)
Replaces the current value of the supplied name with the supplied value.

Specified by:
replace in interface EvaluationEnvironment
Parameters:
name - the name
value - the new value

add

public void add(VariableDeclaration referredVariable,
                Value value)
Adds the supplied name and value binding to the environment

Specified by:
add in interface EvaluationEnvironment
Parameters:
name - the name to add
value - the associated binding
See Also:
#replace(String, Object)

remove

@Deprecated
public Value remove(VariableDeclaration referredVariable)
Deprecated. 

Removes the supplied name and binding from the environment (if it exists) and returns it.

Specified by:
remove in interface EvaluationEnvironment
Parameters:
name - the name to remove
Returns:
the value associated with the removed name

clear

public void clear()
Clears the environment of variables.

Specified by:
clear in interface EvaluationEnvironment

toString

public java.lang.String toString()
Returns a string representation of the bindings

Overrides:
toString in class java.lang.Object

overrides

public boolean overrides(Operation operation,
                         int opcode)
By default, a subclass will not support overriding the operations defined by the OCL Standard Library. This implementation delegates to the parent environment (if any), otherwise returns false.

Specified by:
overrides in interface EvaluationEnvironment
Parameters:
operation - an OCL operation
opcode - the operation code, if one of the operations pre-defined by OCL. Otherwise, -1
Returns:
true if this evaluation environment provides an implementation of this operation; false, otherwise
See Also:
#callOperation

getAdapter

public <T> T getAdapter(java.lang.Class<T> adapterType)
Implements the interface method by testing whether I am an instance of the requested adapter type.

Specified by:
getAdapter in interface Adaptable
Type Parameters:
T - the requested adapter interface
Parameters:
adapterType - the requested adapter interface
Returns:
an instance of the requested interface, or null if this environment does not adapt to it

basicGetOptions

protected java.util.Map<Option<?>,java.lang.Object> basicGetOptions()

getOptions

public java.util.Map<Option<?>,java.lang.Object> getOptions()
Description copied from interface: Customizable
Obtains a copy of my map of options. Options not explicitly set in an environment are inherited from the parent environment, if any, otherwise they are at their default values.

Specified by:
getOptions in interface Customizable
Returns:
the map of options

setOption

public <T> void setOption(Option<T> option,
                          T value)
Description copied from interface: Customizable
Add an option to apply to my behaviour.

Specified by:
setOption in interface Customizable
Parameters:
option - the option
value - the option's value

putOptions

public <T> void putOptions(java.util.Map<? extends Option<T>,? extends T> options)
Description copied from interface: Customizable
Adds options to apply to my behaviour.

Specified by:
putOptions in interface Customizable
Parameters:
options - the options

removeOption

public <T> T removeOption(Option<T> option)
Description copied from interface: Customizable
Removes the specified option.

Specified by:
removeOption in interface Customizable
Parameters:
option - the option to remove
Returns:
the former value of the option

removeOptions

public <T> java.util.Map<Option<T>,T> removeOptions(java.util.Collection<Option<T>> options)
Description copied from interface: Customizable
Removes the specified options.

Specified by:
removeOptions in interface Customizable
Parameters:
options - the options to remove
Returns:
the former values of the options

clearOptions

public java.util.Map<Option<?>,java.lang.Object> clearOptions()
Description copied from interface: Customizable
Clears all options.

Specified by:
clearOptions in interface Customizable
Returns:
the former values of the options

isEnabled

public boolean isEnabled(Option<java.lang.Boolean> option)
Description copied from interface: Customizable
Queries whether the specified boolean-valued option is enabled. This method essentially just puts a nice "is" name on boolean options. Options not explicitly set in an environment are inherited from the parent environment, if any, otherwise they are at their default values.

Specified by:
isEnabled in interface Customizable
Parameters:
option - an option
Returns:
whether the option is enabled

getValue

public <T> T getValue(Option<T> option)
Description copied from interface: Customizable
Obtains the value of the specified option's setting in the my options map. Options not explicitly set in an environment are inherited from the parent environment, if any, otherwise they are at their default values.

Specified by:
getValue in interface Customizable
Parameters:
option - the option to query
Returns:
value of the option

throwInvalidEvaluation

public NullValue throwInvalidEvaluation(InvalidValueException e)
                                 throws InvalidEvaluationException
Specified by:
throwInvalidEvaluation in interface EvaluationEnvironment
Throws:
InvalidEvaluationException

throwInvalidEvaluation

public NullValue throwInvalidEvaluation(java.lang.String message)
                                 throws InvalidEvaluationException
Specified by:
throwInvalidEvaluation in interface EvaluationEnvironment
Throws:
InvalidEvaluationException

throwInvalidEvaluation

public NullValue throwInvalidEvaluation(java.lang.String message,
                                        OclExpression expression)
                                 throws InvalidEvaluationException
Specified by:
throwInvalidEvaluation in interface EvaluationEnvironment
Throws:
InvalidEvaluationException

throwInvalidEvaluation

public NullValue throwInvalidEvaluation(java.lang.String message,
                                        OclExpression expression,
                                        java.lang.Object context)
                                 throws InvalidEvaluationException
Specified by:
throwInvalidEvaluation in interface EvaluationEnvironment
Throws:
InvalidEvaluationException

throwInvalidEvaluation

public NullValue throwInvalidEvaluation(java.lang.Throwable e,
                                        OclExpression expression,
                                        java.lang.Object context,
                                        java.lang.String message,
                                        java.lang.Object... bindings)
                                 throws InvalidEvaluationException
Specified by:
throwInvalidEvaluation in interface EvaluationEnvironment
Throws:
InvalidEvaluationException