org.eclipse.ocl.uml
Class UMLEvaluationEnvironment

java.lang.Object
  extended by org.eclipse.ocl.AbstractEvaluationEnvironment<Classifier,Operation,Property,Class,EObject>
      extended by org.eclipse.ocl.uml.UMLEvaluationEnvironment
All Implemented Interfaces:
EvaluationEnvironment<Classifier,Operation,Property,Class,EObject>

public class UMLEvaluationEnvironment
extends AbstractEvaluationEnvironment<Classifier,Operation,Property,Class,EObject>

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


Constructor Summary
UMLEvaluationEnvironment(EvaluationEnvironment<Classifier,Operation,Property,Class,EObject> parent)
          Initializes me with my parent evaluation environment (nesting scope).
UMLEvaluationEnvironment(UMLEnvironmentFactory factory)
          Initializes me.
 
Method Summary
 Object callOperation(Operation 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.
 Map<Class,Set<EObject>> createExtentMap(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<Operation,Property> createTuple(Classifier type, Map<Property,Object> values)
          Creates a new tuple instance.
protected  EClassifier getEClassifier(Classifier umlClassifier, Object element)
          Looks up the Ecore definition of the specified UML classifier, using the specified element as a context for finding profile applications in the case that the classifier is a stereotype or some other type in a Profile.
protected  EPackage getEPackage(Package pkg)
          Looks up the Ecore definition of the specified UML package.
protected  EPackage.Registry getEPackageRegistry()
          Obtains my package registry for looking up the Ecore definitions of UML packages.
protected  Object getInvalidResult()
          Obtains the language-binding-specific representation of the predefined OclInvalid object.
protected  Method getJavaMethodFor(Operation operation, Object receiver)
          Returns the java method that corresponds to the supplied EOperation
 Classifier getType(Object object)
          Queries the type of the specified object.
 boolean isKindOf(Object object, Classifier classifier)
          Queries whether an object is an instance of the specified classifier or some specialization thereof.
 boolean isTypeOf(Object object, Classifier classifier)
          Queries whether an object's type is the specified classifier.
 Object navigateAssociationClass(Classifier associationClass, Property navigationSource, Object source)
          Obtains the instance of the specified association class that links the specified source element, optionally via the specified property.
 Object navigateProperty(Property property, List<?> qualifiers, Object source)
          Obtains the value of the specified operation, for the given source element, according to the particular metamodel semantics.
 
Methods inherited from class org.eclipse.ocl.AbstractEvaluationEnvironment
add, clear, getParent, getValueOf, overrides, remove, replace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UMLEvaluationEnvironment

public UMLEvaluationEnvironment(UMLEnvironmentFactory factory)
Initializes me.


UMLEvaluationEnvironment

public UMLEvaluationEnvironment(EvaluationEnvironment<Classifier,Operation,Property,Class,EObject> parent)
Initializes me with my parent evaluation environment (nesting scope).

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

getEPackageRegistry

protected final EPackage.Registry getEPackageRegistry()
Obtains my package registry for looking up the Ecore definitions of UML packages.

Returns:
my package registry

callOperation

public Object callOperation(Operation operation,
                            int opcode,
                            Object source,
                            Object[] args)
                     throws 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<Classifier,Operation,Property,Class,EObject>
Overrides:
callOperation in class AbstractEvaluationEnvironment<Classifier,Operation,Property,Class,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:
IllegalArgumentException - if the operation is not supported by this environment

getJavaMethodFor

protected Method getJavaMethodFor(Operation operation,
                                  Object receiver)
Description copied from class: AbstractEvaluationEnvironment
Returns the java method that corresponds to the supplied EOperation

Specified by:
getJavaMethodFor in class AbstractEvaluationEnvironment<Classifier,Operation,Property,Class,EObject>
Parameters:
operation - the operation
Returns:
a java method

getInvalidResult

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

Specified by:
getInvalidResult in class AbstractEvaluationEnvironment<Classifier,Operation,Property,Class,EObject>
Returns:
OclInvalid

navigateProperty

public Object navigateProperty(Property property,
                               List<?> qualifiers,
                               Object source)
                        throws IllegalArgumentException
Description copied from interface: EvaluationEnvironment
Obtains the value of the specified operation, for the given source element, according to the particular metamodel semantics.

Parameters:
property - the property to navigate
qualifiers - the association-end qualifier values, or an empty list if none
source - the source element owning the property value
Returns:
the property value
Throws:
IllegalArgumentException - if the property is not supported by the element or by this environment

navigateAssociationClass

public Object navigateAssociationClass(Classifier associationClass,
                                       Property navigationSource,
                                       Object source)
                                throws 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.

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
source - the source element from which to navigate
Returns:
the association class instance
Throws:
IllegalArgumentException - if the association class is not associated with the source element, or is not supported by this environment

createTuple

public Tuple<Operation,Property> createTuple(Classifier type,
                                             Map<Property,Object> values)
Description copied from interface: EvaluationEnvironment
Creates a new tuple instance.

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 Map<Class,Set<EObject>> createExtentMap(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.

Parameters:
object - a context object in the scope that covers the OCL classifier extents
Returns:
the extent map

isKindOf

public boolean isKindOf(Object object,
                        Classifier classifier)
Description copied from interface: EvaluationEnvironment
Queries whether an object is an instance of the specified classifier or some specialization thereof.

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(Object object,
                        Classifier classifier)
Description copied from interface: EvaluationEnvironment
Queries whether an object's type is the specified classifier.

Parameters:
object - an object
classifier - a classifier
Returns:
true if ths specified classifier is the object's type; false, otherwise

getType

public Classifier getType(Object object)
Description copied from interface: EvaluationEnvironment
Queries the type of the specified object.

Parameters:
object - an object
Returns:
its type

getEPackage

protected EPackage getEPackage(Package pkg)
Looks up the Ecore definition of the specified UML package.

Parameters:
pkg - a UML package
Returns:
its Ecore definition, or null if not found

getEClassifier

protected EClassifier getEClassifier(Classifier umlClassifier,
                                     Object element)
Looks up the Ecore definition of the specified UML classifier, using the specified element as a context for finding profile applications in the case that the classifier is a stereotype or some other type in a Profile. Finding the Ecore definition of a profile type requires finding the actual applied version of the profile.

Parameters:
umlClassifier - a UML classifier
element - an element in the context of which the OCL evaluation is being performed
Returns:
the corresponding Ecore classifier, or null if not found

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