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

Implementation of the OclMetaModel.Helper convenience interface.

Author:
Christian W. Damus (cdamus)

Constructor Summary
OCLHelperImpl(OCL ocl)
           
 
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)
           
 Environment getEnvironment()
          Obtains the environment defining my current classifier, operation, or attribute context.
 OCLBase 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 setAttributeContext(Type context, Property property)
          Sets the attribute 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 setInstanceAttributeContext(java.lang.Object instance, Property property)
          Sets the operation context implied by the specified instance.
 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 setOperationContext(Type context, Operation operation)
          Sets the operation 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
 

Constructor Detail

OCLHelperImpl

public OCLHelperImpl(OCL ocl)
Method Detail

createBodyCondition

public ExpressionInOcl createBodyCondition(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.

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

public ExpressionInOcl createDerivedValueExpression(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.

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:
#setAttributeContext(Object, Object)

createInvariant

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

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

public ExpressionInOcl createPostcondition(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.

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

public ExpressionInOcl createPrecondition(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.

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

public ExpressionInOcl createQuery(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.

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

protected ExpressionInOcl createSpecification(java.lang.String expression)
                                       throws ParserException
Throws:
ParserException

getEnvironment

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), #setAttributeContext(Object, Object)

getOCL

public OCLBase 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

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

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

setContext

public void setContext(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), #setAttributeContext(Object, Object)

setOperationContext

public void setOperationContext(Type context,
                                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)

setAttributeContext

public void setAttributeContext(Type context,
                                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:
setAttributeContext in interface OCLHelper
Parameters:
context - the OCL context classifier
property - the OCL context attribute
See Also:
#setContext(Object)

setInstanceContext

public void setInstanceContext(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(java.lang.Object instance,
                                        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)

setInstanceAttributeContext

public void setInstanceAttributeContext(java.lang.Object instance,
                                        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:
setInstanceAttributeContext in interface OCLHelper
Parameters:
instance - the OCL context instance
property - the OCL context attribute
See Also:
#setAttributeContext(Object, Object)

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