org.eclipse.ocl.ecore
Class EcoreEvaluationEnvironment

java.lang.Object
  extended by org.eclipse.ocl.AbstractEvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
      extended by org.eclipse.ocl.ecore.EcoreEvaluationEnvironment
All Implemented Interfaces:
EvaluationEnvironmentWithHiddenOpposites, EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>, EvaluationEnvironment.Enumerations<org.eclipse.emf.ecore.EEnumLiteral>, Customizable, Adaptable
Direct Known Subclasses:
EcoreEvaluationEnvironmentWithScopedExtentMap

public class EcoreEvaluationEnvironment
extends AbstractEvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
implements EvaluationEnvironment.Enumerations<org.eclipse.emf.ecore.EEnumLiteral>, EvaluationEnvironmentWithHiddenOpposites

Implementation of the EvaluationEnvironment for evaluation of OCL expressions on instances of Ecore models (i.e., on M0 models).

Author:
Tim Klinger (tklinger), Christian W. Damus (cdamus)

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.ocl.AbstractEvaluationEnvironment
AbstractEvaluationEnvironment.AbstractTuple<O,P>
 
Nested classes/interfaces inherited from interface org.eclipse.ocl.EvaluationEnvironment
EvaluationEnvironment.Enumerations<EL>
 
Constructor Summary
EcoreEvaluationEnvironment()
          Deprecated. A root evaluation environment should be created through the correspondent EcoreEnvironmentFactory
EcoreEvaluationEnvironment(EcoreEnvironmentFactory factory)
          Initializes me.
EcoreEvaluationEnvironment(EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject> parent)
          Initializes me with my parent evaluation environment (nesting scope).
 
Method Summary
 java.lang.Object callOperation(org.eclipse.emf.ecore.EOperation operation, int opcode, java.lang.Object source, java.lang.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.
protected  java.lang.Exception checkOperationReflectionConsistency(java.lang.Object source)
          Check if the provided source object has support for a delegated invocation of an OCL expression body.
protected  java.lang.Object coerceValue(org.eclipse.emf.ecore.ETypedElement element, java.lang.Object value, boolean copy)
          Coerces the value of the specified typed element into the appropriate representation, derived from the supplied value template.
 java.util.Map<org.eclipse.emf.ecore.EClass,java.util.Set<org.eclipse.emf.ecore.EObject>> createExtentMap(java.lang.Object object)
          Creates an extent map for invocation of OclType.allInstances() using the specified object as a context from which to find the scope in which OCL classifier extents are defined.
 Tuple<org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature> createTuple(org.eclipse.emf.ecore.EClassifier type, java.util.Map<org.eclipse.emf.ecore.EStructuralFeature,java.lang.Object> values)
          Creates a new tuple instance.
protected static CollectionKind getCollectionKind(org.eclipse.emf.ecore.ETypedElement element)
          Obtains the collection kind appropriate for representing the values of the specified typed element.
protected  java.lang.Object getInvalidResult()
          Obtains the language-binding-specific representation of the predefined OclInvalid object.
protected  java.lang.reflect.Method getJavaMethodFor(org.eclipse.emf.ecore.EOperation operation, java.lang.Object receiver)
          Returns the java method that corresponds to the supplied EOperation
 org.eclipse.emf.ecore.EClassifier getType(java.lang.Object object)
          Queries the type of the specified object.
 org.eclipse.emf.common.util.Enumerator getValue(org.eclipse.emf.ecore.EEnumLiteral enumerationLiteral)
          Ecore implementation of the enumeration literal value.
 boolean isKindOf(java.lang.Object object, org.eclipse.emf.ecore.EClassifier classifier)
          Queries whether an object is an instance of the specified classifier or some specialization thereof.
 boolean isTypeOf(java.lang.Object object, org.eclipse.emf.ecore.EClassifier classifier)
          Queries whether an object's type is the specified classifier.
 java.lang.Object navigateAssociationClass(org.eclipse.emf.ecore.EClassifier associationClass, org.eclipse.emf.ecore.EStructuralFeature navigationSource, java.lang.Object target)
          Obtains the instance of the specified association class that links the specified source element, optionally via the specified property.
 java.lang.Object navigateOppositeProperty(org.eclipse.emf.ecore.EReference property, java.lang.Object target)
          Obtains the value of the specified operation, for the given source element, according to the particular metamodel semantics.
 java.lang.Object navigateProperty(org.eclipse.emf.ecore.EStructuralFeature property, java.util.List<?> qualifiers, java.lang.Object target)
          Obtains the value of the specified operation, for the given source element, according to the particular metamodel semantics.
 void setOperationReflectionCheckDisabled(boolean checkDisabled)
          Configure the check that an incorrect usage of "Operation Reflection" false in a genmodel has omitted the eInvoke override.
 
Methods inherited from class org.eclipse.ocl.AbstractEvaluationEnvironment
add, basicGetOptions, clear, clearOptions, getAdapter, getOptions, getParent, getValue, getValueOf, isEnabled, overrides, putOptions, remove, removeOption, removeOptions, replace, setOption, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EcoreEvaluationEnvironment

public EcoreEvaluationEnvironment()
Deprecated. A root evaluation environment should be created through the correspondent EcoreEnvironmentFactory

Initializes me.


EcoreEvaluationEnvironment

public EcoreEvaluationEnvironment(EcoreEnvironmentFactory factory)
Initializes me.

Since:
3.1

EcoreEvaluationEnvironment

public EcoreEvaluationEnvironment(EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject> parent)
Initializes me with my parent evaluation environment (nesting scope).

Parameters:
parent - my parent (nesting scope); must not be null
Method Detail

callOperation

public java.lang.Object callOperation(org.eclipse.emf.ecore.EOperation operation,
                                      int opcode,
                                      java.lang.Object source,
                                      java.lang.Object[] args)
                               throws java.lang.IllegalArgumentException
Description copied from class: AbstractEvaluationEnvironment
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<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Overrides:
callOperation in class AbstractEvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
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:
java.lang.IllegalArgumentException - if the operation is not supported by this environment

getJavaMethodFor

protected java.lang.reflect.Method getJavaMethodFor(org.eclipse.emf.ecore.EOperation operation,
                                                    java.lang.Object receiver)
Description copied from class: AbstractEvaluationEnvironment
Returns the java method that corresponds to the supplied EOperation

Specified by:
getJavaMethodFor in class AbstractEvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Parameters:
operation - the operation
Returns:
a java method

getInvalidResult

protected java.lang.Object getInvalidResult()
Description copied from class: AbstractEvaluationEnvironment
Obtains the language-binding-specific representation of the predefined OclInvalid object.

Specified by:
getInvalidResult in class AbstractEvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Returns:
OclInvalid

navigateProperty

public java.lang.Object navigateProperty(org.eclipse.emf.ecore.EStructuralFeature property,
                                         java.util.List<?> qualifiers,
                                         java.lang.Object target)
                                  throws java.lang.IllegalArgumentException
Description copied from interface: EvaluationEnvironment
Obtains the value of the specified operation, for the given source element, according to the particular metamodel semantics.

Specified by:
navigateProperty in interface EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Parameters:
property - the property to navigate
qualifiers - the association-end qualifier values, or an empty list if none
target - the source element owning the property value
Returns:
the property value
Throws:
java.lang.IllegalArgumentException - if the property is not supported by the element or by this environment

getCollectionKind

protected static CollectionKind getCollectionKind(org.eclipse.emf.ecore.ETypedElement element)
Obtains the collection kind appropriate for representing the values of the specified typed element.

Parameters:
element - a typed element (property, operation, etc.)
Returns:
the collection kind appropriate to the multiplicity, orderedness, and uniqueness of the element, or null if it is not many
Since:
3.2

coerceValue

protected java.lang.Object coerceValue(org.eclipse.emf.ecore.ETypedElement element,
                                       java.lang.Object value,
                                       boolean copy)
Coerces the value of the specified typed element into the appropriate representation, derived from the supplied value template. The value is coerced to the appropriate collection kind for this element (or scalar if not multi-valued). The original value may either be used as is where possible or, optionally, copied into the new collection (if multi-valued).

Parameters:
element - a typed element (property, operation, etc.)
value - the computed value of the element
copy - whether to copy the specified value into the resulting collection/scalar value
Returns:
the value, in the appropriate OCL collection type or scalar form as required
Since:
3.2
See Also:
getCollectionKind(ETypedElement)

navigateAssociationClass

public java.lang.Object navigateAssociationClass(org.eclipse.emf.ecore.EClassifier associationClass,
                                                 org.eclipse.emf.ecore.EStructuralFeature navigationSource,
                                                 java.lang.Object target)
                                          throws java.lang.IllegalArgumentException
Description copied from interface: EvaluationEnvironment
Obtains the instance of the specified association class that links the specified source element, optionally via the specified property.

Specified by:
navigateAssociationClass in interface EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Parameters:
associationClass - the association class to navigate to
navigationSource - in case of ambiguity, the property of the source element's classifier through which to navigate to the association class
target - the source element from which to navigate
Returns:
the association class instance
Throws:
java.lang.IllegalArgumentException - if the association class is not associated with the source element, or is not supported by this environment

createTuple

public Tuple<org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature> createTuple(org.eclipse.emf.ecore.EClassifier type,
                                                                                                    java.util.Map<org.eclipse.emf.ecore.EStructuralFeature,java.lang.Object> values)
Description copied from interface: EvaluationEnvironment
Creates a new tuple instance.

Specified by:
createTuple in interface EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Parameters:
type - the type (a TupleType) of the tuple to be created
values - a mapping of the tuple parts
Returns:
the new tuple instance

createExtentMap

public java.util.Map<org.eclipse.emf.ecore.EClass,java.util.Set<org.eclipse.emf.ecore.EObject>> createExtentMap(java.lang.Object object)
Description copied from interface: EvaluationEnvironment
Creates an extent map for invocation of OclType.allInstances() using the specified object as a context from which to find the scope in which OCL classifier extents are defined. This scope may be a resource, resource set, or some metamodel-specific scope. Note that in the case that the object is not an EObject but is, instead, some primitive type, then this may be difficult to determine.

Clients are encouraged to do what they can to optimize this mapping, by lazy initialization of key-value pairs, workspace indices, or whatever means is available. Note that the map will only ever be accessed by key (Map.get(java.lang.Object)); it will never be queried for all entries, all keys, all values, etc. This knowledge could help optimization.

Specified by:
createExtentMap in interface EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Parameters:
object - a context object in the scope that covers the OCL classifier extents
Returns:
the extent map

isKindOf

public boolean isKindOf(java.lang.Object object,
                        org.eclipse.emf.ecore.EClassifier classifier)
Description copied from interface: EvaluationEnvironment
Queries whether an object is an instance of the specified classifier or some specialization thereof.

Specified by:
isKindOf in interface EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Parameters:
object - an object
classifier - a classifier
Returns:
true if the specified classifier is the object's type or some supertype thereof; false, otherwise

isTypeOf

public boolean isTypeOf(java.lang.Object object,
                        org.eclipse.emf.ecore.EClassifier classifier)
Description copied from interface: EvaluationEnvironment
Queries whether an object's type is the specified classifier.

Specified by:
isTypeOf in interface EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Parameters:
object - an object
classifier - a classifier
Returns:
true if ths specified classifier is the object's type; false, otherwise

getType

public org.eclipse.emf.ecore.EClassifier getType(java.lang.Object object)
Description copied from interface: EvaluationEnvironment
Queries the type of the specified object.

Specified by:
getType in interface EvaluationEnvironment<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EClass,org.eclipse.emf.ecore.EObject>
Parameters:
object - an object
Returns:
its type

getValue

public org.eclipse.emf.common.util.Enumerator getValue(org.eclipse.emf.ecore.EEnumLiteral enumerationLiteral)
Ecore implementation of the enumeration literal value.

Specified by:
getValue in interface EvaluationEnvironment.Enumerations<org.eclipse.emf.ecore.EEnumLiteral>
Parameters:
enumerationLiteral - the enumeration literal model element
Returns:
the corresponding run-time instance
Since:
1.2

setOperationReflectionCheckDisabled

public void setOperationReflectionCheckDisabled(boolean checkDisabled)
Configure the check that an incorrect usage of "Operation Reflection" false in a genmodel has omitted the eInvoke override. Disabling the check eliminates the overhead of using Java Reflection to perform run-time code checking but incurs the risk of mysterious evaluation malfunctions if the genmodel is wrong.

The check is enabled by default.

Parameters:
checkDisabled - true to disable the check
Since:
3.1

checkOperationReflectionConsistency

protected java.lang.Exception checkOperationReflectionConsistency(java.lang.Object source)
Check if the provided source object has support for a delegated invocation of an OCL expression body.

Missing support is the result of a failure to change the default genmodel 'Operation Reflection' setting to true.

Lack of support is tested by checking for a missing override of EOperationImpl.eInvoke(int, EList).

Parameters:
source - the object to check
Since:
3.1

navigateOppositeProperty

public java.lang.Object navigateOppositeProperty(org.eclipse.emf.ecore.EReference property,
                                                 java.lang.Object target)
                                          throws java.lang.IllegalArgumentException
Description copied from interface: EvaluationEnvironmentWithHiddenOpposites
Obtains the value of the specified operation, for the given source element, according to the particular metamodel semantics.

Specified by:
navigateOppositeProperty in interface EvaluationEnvironmentWithHiddenOpposites
Parameters:
property - the property to navigate in reverse direction
target - the source element from where to start navigating / querying
Returns:
the property value
Throws:
java.lang.IllegalArgumentException - if the property is not supported by the element or by this environment
Since:
3.1