public class OCL<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
extends java.lang.Object
The Façade for parsing and evaluation of OCL documents and
constraints. The OCL
is initialized with an environment factory
that supports the metamodel of the model to which the OCL constraints are to
be applied.
Since 1.2, the helper supplies diagnostics indicating any problems encountered while parsing. The diagnostics pertain always to the most recently executed parse operation.
See the Environment
class for a description of the generic type
parameters of this class.
Providers of OCL bindings for metamodels may extend this class for the convenience of their clients, to specify the type parameter substitutions.
Modifier | Constructor and Description |
---|---|
protected |
OCL(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env)
Initializes me with a root environment.
|
protected |
OCL(EnvironmentFactory<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> envFactory)
Initializes me with an environment factory, which I will use to create a
root environment.
|
protected |
OCL(EnvironmentFactory<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> envFactory,
Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> rootEnv)
Initializes me with my environment factory and root environment.
|
protected |
OCL(EnvironmentFactory<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> envFactory,
org.eclipse.emf.ecore.resource.Resource resource)
Initializes me with an environment factory and a resource in which my
environment is to be persisted, or from which it may be loaded if the
resource already has content.
|
Modifier and Type | Method and Description |
---|---|
boolean |
check(java.lang.Object context,
CT constraint)
Checks whether a constraint is satisfied by an object.
|
boolean |
check(java.lang.Object context,
OCLExpression<C> constraint)
Checks whether a constraint, specified simply as an OCL expression, is
satisfied by an object.
|
OCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> |
createAnalyzer(java.lang.String input)
Return an analyzer configured ready to parse an input string.
|
OCLHelper<C,O,P,CT> |
createOCLHelper()
Creates a new
OCLHelper instance for convenient parsing of
embedded constraints and query expressions in this environment. |
Query<C,CLS,E> |
createQuery(CT constraint)
Creates a new
Query encapsulating a constraint with the current
environment and extent map. |
Query<C,CLS,E> |
createQuery(OCLExpression<C> query)
Creates a new
Query encapsulating a query expression with the
current environment and extent map. |
void |
dispose()
Disposes any objects that I have created while I have been in use.
|
java.lang.Object |
evaluate(java.lang.Object context,
OCLExpression<C> expression)
Evaluates a query expression on a context object (which is bound to the
self variable).
|
java.util.List<CT> |
getConstraints()
Obtains all of the constraints parsed hitherto by this OCL instance.
|
Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> |
getEnvironment()
Obtains the OCL parsing environment.
|
EvaluationEnvironment<C,O,P,CLS,E> |
getEvaluationEnvironment()
Obtains the OCL evaluation environment.
|
org.eclipse.emf.common.util.Diagnostic |
getEvaluationProblems()
Obtains problems, if any, occurred during evaluation of the last OCL
constraint or query expression.
|
java.util.Map<CLS,? extends java.util.Set<? extends E>> |
getExtentMap()
Obtains the extent map, if any, provided by the client to customize the
evaluation of constraints.
|
int |
getParserRepairCount()
Queries the number of repairs to be made by the parser.
|
org.eclipse.emf.common.util.Diagnostic |
getProblems()
Obtains problems, if any, found in parsing the last OCL constraint or
query expression.
|
boolean |
isEvaluationTracingEnabled()
Queries whether tracing of evaluation is enabled.
|
boolean |
isInvalid(java.lang.Object value)
Queries whether a value is the special invalid token.
|
boolean |
isParseTracingEnabled()
Queries whether tracing of parsingis enabled.
|
static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> |
newInstance(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env)
Creates a new
OCL on the specified root environment. |
static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> |
newInstance(EnvironmentFactory<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> envFactory)
Creates a new
OCL with an environment factory, which it will
use to create a root environment. |
static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> |
newInstance(EnvironmentFactory<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> envFactory,
org.eclipse.emf.ecore.resource.Resource resource)
Creates a new
OCL with an environment factory and a resource
in which its environment is to be persisted, or from which it may be
loaded if the resource already has content. |
java.util.List<CT> |
parse(OCLInput input)
Parses an OCL document, returning the constraints parsed from it.
|
void |
setEvaluationTracingEnabled(boolean b)
Sets whether tracing of evaluation is enabled.
|
void |
setExtentMap(java.util.Map<CLS,? extends java.util.Set<? extends E>> extentMap)
Assigns a custom extent map to define the extents of classes in
evaluation of OCL constraints.
|
void |
setParserRepairCount(int parserRepairCount)
Sets the number of repairs to be made by the parser.
|
void |
setParseTracingEnabled(boolean b)
Sets whether tracing of parsing is enabled.
|
void |
validate(CT constraint)
Validates an OCL constraint, which may have been loaded from some
resource or constructed via the API (perhaps by translation from some
other language).
|
void |
validate(OCLExpression<C> expression)
Validates an OCL expression, which may have been loaded from some
resource or constructed via the API (perhaps by translation from some
other language).
|
protected OCL(EnvironmentFactory<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> envFactory)
envFactory
- my environment factoryprotected OCL(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env)
env
- my root environmentprotected OCL(EnvironmentFactory<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> envFactory, org.eclipse.emf.ecore.resource.Resource resource)
envFactory
- an environment factoryresource
- a resource in which the root environment is persistedpublic static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> OCL<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> newInstance(EnvironmentFactory<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> envFactory)
OCL
with an environment factory, which it will
use to create a root environment.envFactory
- an environment factorypublic static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> OCL<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> newInstance(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env)
OCL
on the specified root environment.env
- the root environmentpublic static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> OCL<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> newInstance(EnvironmentFactory<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> envFactory, org.eclipse.emf.ecore.resource.Resource resource)
OCL
with an environment factory and a resource
in which its environment is to be persisted, or from which it may be
loaded if the resource already has content.envFactory
- an environment factoryresource
- a resource in which the root environment is persistedpublic Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> getEnvironment()
getEvaluationEnvironment()
public EvaluationEnvironment<C,O,P,CLS,E> getEvaluationEnvironment()
getEnvironment()
public java.util.Map<CLS,? extends java.util.Set<? extends E>> getExtentMap()
null
if
thie OCL is using the default dynamic extent map implementationpublic void setExtentMap(java.util.Map<CLS,? extends java.util.Set<? extends E>> extentMap)
extentMap
- a custom extent map, or null
to use the default
dynamic extent map implementationpublic OCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> createAnalyzer(java.lang.String input)
input
- the input to parsepublic java.util.List<CT> parse(OCLInput input) throws ParserException
OCL
instance remembers these constraints; they can be
retrieved later via the getConstraints()
method.input
- an OCL document as either a string or a streamParserException
- on failure to parse, either because of a syntactic or
semantic problem or because of an I/O failuregetConstraints()
public java.util.List<CT> getConstraints()
parse(OCLInput)
public void validate(OCLExpression<C> expression) throws SemanticException
expression
- an expression to validateSemanticException
- on detection of any well-formedness problem in the expressionvalidate(Object)
public void validate(CT constraint) throws SemanticException
constraint
- a constraint to validateSemanticException
- on detection of any well-formedness problem in the constraintpublic java.lang.Object evaluate(java.lang.Object context, OCLExpression<C> expression)
isInvalid(Object)
method to check whether the evaluation result
is OclInvalid.context
- the context (self) objectexpression
- the OCL expression to evaluateisInvalid(Object)
,
check(Object, Object)
public boolean isInvalid(java.lang.Object value)
value
- some OCL valuetrue
if it is the invalid;
false
, otherwiseevaluate(Object, OCLExpression)
public boolean check(java.lang.Object context, CT constraint)
context
- the self object of the constraintconstraint
- the constraint to checkcheck(Object, OCLExpression)
,
evaluate(Object, OCLExpression)
public boolean check(java.lang.Object context, OCLExpression<C> constraint)
context
- the self object of the constraintconstraint
- the constraint to check, which must be a boolean-valued
expressionjava.lang.IllegalArgumentException
- if the constraint expression is not boolean-valuedcheck(Object, Object)
,
evaluate(Object, OCLExpression)
public OCLHelper<C,O,P,CT> createOCLHelper()
OCLHelper
instance for convenient parsing of
embedded constraints and query expressions in this environment. The
helper is particulary useful for parsing constraints embedded in the
model, in which case the context of a constraint is determined by its
placement and the textual context declarations are unnecessary.public Query<C,CLS,E> createQuery(OCLExpression<C> query)
Query
encapsulating a query expression with the
current environment and extent map. This is convenient for repeated
evaluation of expressions and for filtering/transforming objects using a
query or constraint expression.
Every query maintains its own evaluation environment, which enables concurrent evaluation (where this may be safe in an EMF-based model) and different bindings for client-supplied "global" variables.
query
- the OCL query expression, which may be interpreted as a
constraint if it is boolean-valuedcreateQuery(Object)
public Query<C,CLS,E> createQuery(CT constraint)
Query
encapsulating a constraint with the current
environment and extent map. This is convenient for repeated evaluation of
constraints and for filtering objects using the constraint expression.
Every query maintains its own evaluation environment, which enables concurrent evaluation (where this may be safe in an EMF-based model) and different bindings for client-supplied "global" variables.
constraint
- the OCL constraintcreateQuery(OCLExpression)
public boolean isParseTracingEnabled()
In an Eclipse environment, tracing is also enabled by turning on the org.eclipse.ocl/debug/parsing debug option.
setParseTracingEnabled(boolean)
public void setParseTracingEnabled(boolean b)
In an Eclipse environment, tracing is also enabled by turning on the org.eclipse.ocl/debug/parsing debug option.
param b whether parsing tracing is enabledisParseTracingEnabled()
public int getParserRepairCount()
Queries the number of repairs to be made by the parser.
The default zero value selects use of the deterministic parser, which terminates after one serious syntax error is detected.
A non-zero value selects the backtracking parser. The backtracking parser may be about three times slower.
setParserRepairCount(int)
public void setParserRepairCount(int parserRepairCount)
Sets the number of repairs to be made by the parser.
The default zero value selects use of the deterministic parser, which terminates after one serious syntax error is detected.
A non-zero value selects the backtracking parser. The backtracking parser may be about three times slower.
parserRepairCount
- whether evaluation tracing is enabledjava.lang.IllegalArgumentException
- if the parserRepairCount is negativegetParserRepairCount()
public boolean isEvaluationTracingEnabled()
In an Eclipse environment, tracing is also enabled by turning on the org.eclipse.ocl/debug/evaluation debug option.
setEvaluationTracingEnabled(boolean)
public void setEvaluationTracingEnabled(boolean b)
In an Eclipse environment, tracing is also enabled by turning on the org.eclipse.ocl/debug/evaluation debug option.
b
- whether evaluation tracing is enabledisEvaluationTracingEnabled()
public org.eclipse.emf.common.util.Diagnostic getProblems()
null
if all was OKpublic org.eclipse.emf.common.util.Diagnostic getEvaluationProblems()
null
if all was OKpublic void dispose()
constraints
that I
have parsed and disposing of
my environment.