org.eclipse.ocl
Class AbstractEvaluationEnvironment<C,O,P,CLS,E>

java.lang.Object
  extended by org.eclipse.ocl.AbstractEvaluationEnvironment<C,O,P,CLS,E>
All Implemented Interfaces:
EvaluationEnvironment<C,O,P,CLS,E>
Direct Known Subclasses:
EcoreEvaluationEnvironment, UMLEvaluationEnvironment

public abstract class AbstractEvaluationEnvironment<C,O,P,CLS,E>
extends Object
implements EvaluationEnvironment<C,O,P,CLS,E>

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.


Constructor Summary
protected AbstractEvaluationEnvironment()
           
protected AbstractEvaluationEnvironment(EvaluationEnvironment<C,O,P,CLS,E> parent)
           
 
Method Summary
 void add(String name, Object value)
          Adds the supplied name and value binding to the environment
 Object callOperation(O operation, int opcode, Object source, Object[] args)
          Implements the inherited method by attempting to find an appropriate Java method in the actual type of the source object and invoking it.
 void clear()
          Clears the environment of variables.
protected abstract  Object getInvalidResult()
          Obtains the language-binding-specific representation of the predefined OclInvalid object.
protected abstract  Method getJavaMethodFor(O operation, Object receiver)
          Returns the java method that corresponds to the supplied EOperation
protected  EvaluationEnvironment<C,O,P,CLS,E> getParent()
          Obtains my parent (nesting) environment.
 Object getValueOf(String name)
          Returns the value associated with the supplied name
 boolean overrides(O operation, int opcode)
          By default, a subclass will not support overriding the operations defined by the OCL Standard Library.
 Object remove(String name)
          Removes the supplied name and binding from the environment (if it exists) and returns it.
 void replace(String name, Object value)
          Replaces the current value of the supplied name with the supplied value.
 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.EvaluationEnvironment
createExtentMap, createTuple, getType, isKindOf, isTypeOf, navigateAssociationClass, navigateProperty
 

Constructor Detail

AbstractEvaluationEnvironment

protected AbstractEvaluationEnvironment()

AbstractEvaluationEnvironment

protected AbstractEvaluationEnvironment(EvaluationEnvironment<C,O,P,CLS,E> parent)
Method Detail

getParent

protected EvaluationEnvironment<C,O,P,CLS,E> getParent()
Obtains my parent (nesting) environment.

Returns:
my parent environment, or null if none

getValueOf

public Object getValueOf(String name)
Returns the value associated with the supplied name

Specified by:
getValueOf in interface EvaluationEnvironment<C,O,P,CLS,E>
Parameters:
name - the name whose value is to be returned
Returns:
the value associated with the name

replace

public void replace(String name,
                    Object value)
Replaces the current value of the supplied name with the supplied value.

Specified by:
replace in interface EvaluationEnvironment<C,O,P,CLS,E>
Parameters:
name - the name
value - the new value

add

public void add(String name,
                Object value)
Adds the supplied name and value binding to the environment

Specified by:
add in interface EvaluationEnvironment<C,O,P,CLS,E>
Parameters:
name - the name to add
value - the associated binding
See Also:
EvaluationEnvironment.replace(String, Object)

remove

public Object remove(String name)
Removes the supplied name and binding from the environment (if it exists) and returns it.

Specified by:
remove in interface EvaluationEnvironment<C,O,P,CLS,E>
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<C,O,P,CLS,E>

toString

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

Overrides:
toString in class Object

overrides

public boolean overrides(O 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<C,O,P,CLS,E>
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:
EvaluationEnvironment.callOperation(O, int, java.lang.Object, java.lang.Object[])

callOperation

public Object callOperation(O operation,
                            int opcode,
                            Object source,
                            Object[] args)
                     throws IllegalArgumentException
Implements the inherited method by attempting to find an appropriate Java method in the actual type of the source object and invoking it. On failure to find or invoke the method (e.g., an exception), the OclInvalid result is returned.

Specified by:
callOperation in interface EvaluationEnvironment<C,O,P,CLS,E>
Parameters:
operation - the operation to invoke
opcode - the operation code, if this is an OCL Standard Library operation (which this environment overrides)
source - the source element on which the operation is invoked
args - the arguments, or an empty array if none
Returns:
the result of the Java method invocation, or OclInvalid on failure of the method invocation
Throws:
IllegalArgumentException - if the operation is not supported by this environment

getJavaMethodFor

protected abstract Method getJavaMethodFor(O operation,
                                           Object receiver)
Returns the java method that corresponds to the supplied EOperation

Parameters:
operation - the operation
Returns:
a java method

getInvalidResult

protected abstract Object getInvalidResult()
Obtains the language-binding-specific representation of the predefined OclInvalid object.

Returns:
OclInvalid

Copyright 2002, 2007 IBM Corporation and others.
All Rights Reserved.