org.eclipse.ocl.examples.pivot.helper
Class OCLHelperImpl

java.lang.Object
  extended by org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl
All Implemented Interfaces:
OCLHelper

public class OCLHelperImpl
extends java.lang.Object
implements OCLHelper

Implementation of the OCLMetaModel.Helper convenience interface.


Field Summary
protected  EnvironmentFactory environmentFactory
           
protected  MetaModelManager metaModelManager
           
protected  Environment rootEnvironment
           
 
Constructor Summary
OCLHelperImpl(OCL ocl)
          Initializes me with my environment.
 
Method Summary
 ExpressionInOCL createBodyCondition(java.lang.String expression)
          Creates an operation body.
 ExpressionInOCL createDerivedValueExpression(java.lang.String expression)
          Creates a property derived value expression.
 ExpressionInOCL createInvariant(java.lang.String expression)
          Creates an invariant constraint in the current classifier context.
 ExpressionInOCL createPostcondition(java.lang.String expression)
          Creates an operation postcondition constraint.
 ExpressionInOCL createPrecondition(java.lang.String expression)
          Creates an operation precondition constraint.
 ExpressionInOCL createQuery(java.lang.String expression)
          Creates a query expression in the current classifier context.
protected  ExpressionInOCL createSpecification(java.lang.String expression)
           
 Type getContextClassifier()
          Obtains my OCL context classifier as a classifier.
 Operation getContextOperation()
          Obtains my context operation, if my environment is an operation context.
 Property getContextProperty()
          Obtains my context attribute, if my environment is an attribute context.
 Environment getEnvironment()
          Obtains the environment defining my current classifier, operation, or attribute context.
 MetaModelManager getMetaModelManager()
           
 OCL getOCL()
          Obtains the OCL instance that created me.
 org.eclipse.emf.common.util.Diagnostic getProblems()
          Obtains problems, if any, found in parsing the last OCL constraint or query expression.
 boolean isValidating()
          Queries whether I validate the expressions that I parse.
 void setContext(org.eclipse.emf.ecore.EClassifier context)
          Sets the classifier context of the OCL expression for which syntax or parsing help is to be provided.
 void setContext(Type context)
          Sets the classifier context of the OCL expression for which syntax or parsing help is to be provided.
 void setInstanceContext(java.lang.Object instance)
          Sets the classifier context implied by the specified instance.
 void setInstanceOperationContext(java.lang.Object instance, Operation operation)
          Sets the operation context implied by the specified instance.
 void setInstancePropertyContext(java.lang.Object instance, Property property)
          Sets the operation context implied by the specified instance.
 void setOperationContext(org.eclipse.emf.ecore.EClassifier context, org.eclipse.emf.ecore.EOperation operation)
          Sets the operation context of the OCL expression for which syntax or parsing help is to be provided.
 void setOperationContext(Type context, Operation operation)
          Sets the operation context of the OCL expression for which syntax or parsing help is to be provided.
 void setPropertyContext(org.eclipse.emf.ecore.EClassifier context, org.eclipse.emf.ecore.EStructuralFeature property)
          Sets the attribute context of the OCL expression for which syntax or parsing help is to be provided.
 void setPropertyContext(Type context, Property property)
          Sets the attribute context of the OCL expression for which syntax or parsing help is to be provided.
 void setValidating(boolean validating)
          Sets whether I should validate the expressions that I parse.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootEnvironment

@NonNull
protected final Environment rootEnvironment

metaModelManager

@NonNull
protected final MetaModelManager metaModelManager

environmentFactory

@NonNull
protected final EnvironmentFactory environmentFactory
Constructor Detail

OCLHelperImpl

public OCLHelperImpl(@NonNull
                     OCL ocl)
Initializes me with my environment.

Parameters:
ocl - the OCL environment
Method Detail

createBodyCondition

@NonNull
public ExpressionInOCL createBodyCondition(@NonNull
                                                   java.lang.String expression)
                                    throws ParserException
Description copied from interface: OCLHelper
Creates an operation body. This is appropriate only if my context is an operation.

Specified by:
createBodyCondition in interface OCLHelper
Parameters:
expression - the constraint expression (without any context declaration). Ordinarily, this is an expression of the same type as the operation, specifying the value of the operation. Alternatively, this may be a boolean-valued expression phrased like a post-condition (according to the well-formedness rules of UML constraints)
Returns:
the body condition
Throws:
ParserException - if the expression fails to parse
See Also:
#setOperationContext(Object, Object)

createDerivedValueExpression

@NonNull
public ExpressionInOCL createDerivedValueExpression(@NonNull
                                                            java.lang.String expression)
                                             throws ParserException
Description copied from interface: OCLHelper
Creates a property derived value expression. This is appropriate only if my context is a property.

Specified by:
createDerivedValueExpression in interface OCLHelper
Parameters:
expression - the derived value expression (without any context declaration). This must conform to my context property type
Returns:
the derived value expression
Throws:
ParserException - if the expression fails to parse or is not valid for my context property
See Also:
#setPropertyContext(Object, Object)

createInvariant

@NonNull
public ExpressionInOCL createInvariant(@NonNull
                                               java.lang.String expression)
                                throws ParserException
Description copied from interface: OCLHelper
Creates an invariant constraint in the current classifier context.

Specified by:
createInvariant in interface OCLHelper
Parameters:
expression - the constraint expression (without any context declaration). This must be a boolean-valued expression
Returns:
the invariant constraint
Throws:
ParserException - if the expression fails to parse

createPostcondition

@NonNull
public ExpressionInOCL createPostcondition(@NonNull
                                                   java.lang.String expression)
                                    throws ParserException
Description copied from interface: OCLHelper
Creates an operation postcondition constraint. This is appropriate only if my context is an operation.

Specified by:
createPostcondition in interface OCLHelper
Parameters:
expression - the constraint expression (without any context declaration). This must be a boolean-valued expression
Returns:
the postcondition
Throws:
ParserException - if the expression fails to parse
See Also:
#setOperationContext(Object, Object)

createPrecondition

@NonNull
public ExpressionInOCL createPrecondition(@NonNull
                                                  java.lang.String expression)
                                   throws ParserException
Description copied from interface: OCLHelper
Creates an operation precondition constraint. This is appropriate only if my context is an operation.

Specified by:
createPrecondition in interface OCLHelper
Parameters:
expression - the constraint expression (without any context declaration). This must be a boolean-valued expression
Returns:
the precondition
Throws:
ParserException - if the expression fails to parse
See Also:
#setOperationContext(Object, Object)

createQuery

@NonNull
public ExpressionInOCL createQuery(@NonNull
                                           java.lang.String expression)
                            throws ParserException
Description copied from interface: OCLHelper
Creates a query expression in the current classifier context. This may be specified, for example, as an expression value in the model.

Specified by:
createQuery in interface OCLHelper
Parameters:
expression - the expression (without any context declaration). This expression can have any result type; it needs not be a boolean
Returns:
the query expression
Throws:
ParserException - if the expression fails to parse

createSpecification

@NonNull
protected ExpressionInOCL createSpecification(@NonNull
                                                      java.lang.String expression)
                                       throws ParserException
Throws:
ParserException

getContextProperty

@Nullable
public Property getContextProperty()
Description copied from interface: OCLHelper
Obtains my context attribute, if my environment is an attribute context.

Specified by:
getContextProperty in interface OCLHelper
Returns:
my context attribute, or null if there is only a classifier or operation context

getContextClassifier

@Nullable
public Type getContextClassifier()
Description copied from interface: OCLHelper
Obtains my OCL context classifier as a classifier.

Specified by:
getContextClassifier in interface OCLHelper
Returns:
my context classifier (never null)

getContextOperation

@Nullable
public Operation getContextOperation()
Description copied from interface: OCLHelper
Obtains my context operation, if my environment is an operation context.

Specified by:
getContextOperation in interface OCLHelper
Returns:
my context operation, or null if there is only a classifier or attribute context

getEnvironment

@NonNull
public Environment getEnvironment()
Description copied from interface: OCLHelper
Obtains the environment defining my current classifier, operation, or attribute context. Accessing the environment is convenient for, e.g., adding variable definitions to insert global objects into the OCL context.

Specified by:
getEnvironment in interface OCLHelper
Returns:
my current context environment, or null if I have not yet been assigned a context
See Also:
#setContext(Object), #setOperationContext(Object, Object), #setPropertyContext(Object, Object)

getMetaModelManager

@NonNull
public final MetaModelManager getMetaModelManager()

getOCL

@NonNull
public OCL getOCL()
Description copied from interface: OCLHelper
Obtains the OCL instance that created me. Note that many of the generic type parameter bindings will not be known, so clients should keep track of the OCL instance themselves where that is a problem.

Specified by:
getOCL in interface OCLHelper
Returns:
the OCL instance that created me

getProblems

public org.eclipse.emf.common.util.Diagnostic getProblems()
Description copied from interface: OCLHelper
Obtains problems, if any, found in parsing the last OCL constraint or query expression.

Specified by:
getProblems in interface OCLHelper
Returns:
parsing problems or null if all was OK

isValidating

public boolean isValidating()
Description copied from interface: OCLHelper
Queries whether I validate the expressions that I parse. Validation applies more well-formedness checks than are implied by parsing, especially because parsing supports partial (incomplete) expressions for syntax completion. Validation adds some amount of processing, which is not necessary in all cases.

Specified by:
isValidating in interface OCLHelper
Returns:
whether I validate the expressions that I parse. Validation is on by default

setContext

public void setContext(@NonNull
                       org.eclipse.emf.ecore.EClassifier context)
Description copied from interface: OCLHelper
Sets the classifier context of the OCL expression for which syntax or parsing help is to be provided.

Specified by:
setContext in interface OCLHelper
Parameters:
context - the OCL context classifier
See Also:
#setOperationContext(Object, Object), #setPropertyContext(Object, Object)

setContext

public void setContext(@NonNull
                       Type context)
Description copied from interface: OCLHelper
Sets the classifier context of the OCL expression for which syntax or parsing help is to be provided.

Specified by:
setContext in interface OCLHelper
Parameters:
context - the OCL context classifier
See Also:
#setOperationContext(Object, Object), #setPropertyContext(Object, Object)

setInstancePropertyContext

public void setInstancePropertyContext(@NonNull
                                       java.lang.Object instance,
                                       @NonNull
                                       Property property)
Description copied from interface: OCLHelper
Sets the operation context implied by the specified instance. The appropriate classifier will be determined from the run-time type of this object, if possible. If not possible, OclAny is assumed.

This method is convenient for ad hoc parsing and evaluation of OCL constraints or expressions in the context of a model instance.

Specified by:
setInstancePropertyContext in interface OCLHelper
Parameters:
instance - the OCL context instance
property - the OCL context attribute
See Also:
#setPropertyContext(Object, Object)

setInstanceContext

public void setInstanceContext(@NonNull
                               java.lang.Object instance)
Description copied from interface: OCLHelper
Sets the classifier context implied by the specified instance. The appropriate classifier will be determined from the run-time type of this object, if possible. If not possible, OclAny is assumed.

This method is convenient for ad hoc parsing and evaluation of OCL constraints or expressions in the context of a model instance.

Specified by:
setInstanceContext in interface OCLHelper
Parameters:
instance - the OCL context instance
See Also:
#setContext(Object)

setInstanceOperationContext

public void setInstanceOperationContext(@NonNull
                                        java.lang.Object instance,
                                        @NonNull
                                        Operation operation)
Description copied from interface: OCLHelper
Sets the operation context implied by the specified instance. The appropriate classifier will be determined from the run-time type of this object, if possible. If not possible, OclAny is assumed.

This method is convenient for ad hoc parsing and evaluation of OCL constraints or expressions in the context of a model instance.

Specified by:
setInstanceOperationContext in interface OCLHelper
Parameters:
instance - the OCL context instance
operation - the OCL context operation
See Also:
#setOperationContext(Object, Object)

setOperationContext

public void setOperationContext(@NonNull
                                org.eclipse.emf.ecore.EClassifier context,
                                @NonNull
                                org.eclipse.emf.ecore.EOperation operation)
Description copied from interface: OCLHelper
Sets the operation context of the OCL expression for which syntax or parsing help is to be provided. The operation is the model element against which the OCL will be parsed as an operation applicable to an OCL type. Note that the operation needs not necessarily be defined by the specified context classifier; it could be inherited.

Specified by:
setOperationContext in interface OCLHelper
Parameters:
context - the OCL context classifier
operation - the OCL context operation
See Also:
#setContext(Object)

setOperationContext

public void setOperationContext(@NonNull
                                Type context,
                                @NonNull
                                Operation operation)
Description copied from interface: OCLHelper
Sets the operation context of the OCL expression for which syntax or parsing help is to be provided. The operation is the model element against which the OCL will be parsed as an operation applicable to an OCL type. Note that the operation needs not necessarily be defined by the specified context classifier; it could be inherited.

Specified by:
setOperationContext in interface OCLHelper
Parameters:
context - the OCL context classifier
operation - the OCL context operation
See Also:
#setContext(Object)

setPropertyContext

public void setPropertyContext(@NonNull
                               org.eclipse.emf.ecore.EClassifier context,
                               @NonNull
                               org.eclipse.emf.ecore.EStructuralFeature property)
Description copied from interface: OCLHelper
Sets the attribute context of the OCL expression for which syntax or parsing help is to be provided. The attribute is the model element against which the OCL will be parsed as an attribute available in an OCL classifier. Note that the attribute needs not necessarily be defined by the specified context classifier; it could be inherited.

Specified by:
setPropertyContext in interface OCLHelper
Parameters:
context - the OCL context classifier
property - the OCL context attribute
See Also:
#setContext(Object)

setPropertyContext

public void setPropertyContext(@NonNull
                               Type context,
                               @NonNull
                               Property property)
Description copied from interface: OCLHelper
Sets the attribute context of the OCL expression for which syntax or parsing help is to be provided. The attribute is the model element against which the OCL will be parsed as an attribute available in an OCL classifier. Note that the attribute needs not necessarily be defined by the specified context classifier; it could be inherited.

Specified by:
setPropertyContext in interface OCLHelper
Parameters:
context - the OCL context classifier
property - the OCL context attribute
See Also:
#setContext(Object)

setValidating

public void setValidating(boolean validating)
Description copied from interface: OCLHelper
Sets whether I should validate the expressions that I parse.

Specified by:
setValidating in interface OCLHelper
Parameters:
validating - whether I should validate parsed expressions