public class OCL
extends java.lang.Object
OCL
façade that binds the
Ecore metamodel to the superclass's generic type parameters. This frees
client code from the long list of parameter substitutions. This subclass
also provides a shortcut to creating an OCL
on the shared
EnvironmentFactoryInternal
instance.EnvironmentFactoryInternal
Modifier and Type | Field and Description |
---|---|
static ProjectManager |
CLASS_PATH
A heavyweight shared read-only ProjectManager that provides access to all external projects.
|
protected EnvironmentFactoryInternal |
environmentFactory
The EnvironmentFactory that can create objects and which provides the MetamodelManager, CompleteEnvironment and StandardLibrary.
|
static ProjectManager |
NO_PROJECTS
A very lightweight ProjectManager that provodes no access to external projects.
|
Modifier | Constructor and Description |
---|---|
protected |
OCL(EnvironmentFactoryInternal environmentFactory)
Initializes me with my environment factory and root environment.
|
Modifier and Type | Method and Description |
---|---|
void |
as2cs(ASResource asResource,
CSResource csResource)
Update the CS resource from a asResource.
|
org.eclipse.emf.ecore.resource.Resource |
as2ecore(org.eclipse.emf.ecore.resource.Resource asResource,
org.eclipse.emf.common.util.URI uri)
Return the Ecore resource counterpart of a asResource, specifying the uri of the resulting Ecore resource.
|
boolean |
check(java.lang.Object context,
Constraint constraint)
Checks whether a constraint is satisfied by an object.
|
boolean |
check(java.lang.Object context,
ExpressionInOCL specification)
Checks whether a constraint, specified simply as an OCL expression, is
satisfied by an object.
|
EvaluationVisitor |
createEvaluationVisitor(java.lang.Object context,
ExpressionInOCL expression)
Creates a new evaluation visitor, for the evaluation of an OCL expression in a context.
|
ExpressionInOCL |
createInvariant(org.eclipse.emf.ecore.EObject contextElement,
java.lang.String oclExpression)
Parse oclExpression using selfType as the type of each run-time self object.
|
OCLHelper |
createOCLHelper(org.eclipse.emf.ecore.EObject contextElement)
Creates a new
OCLHelper instance for convenient parsing of
embedded constraints and query expressions for the specified context
which may be an Ecore EClassifier/EOperation/EStructuralFeature or
or Pivot Class/Operation/Property. |
ExpressionInOCL |
createPostcondition(org.eclipse.emf.ecore.EOperation contextOperation,
java.lang.String oclExpression) |
Query |
createQuery(Constraint constraint)
Creates a new
Query encapsulating a constraint with the current
environment and extent map. |
ExpressionInOCL |
createQuery(org.eclipse.emf.ecore.EObject contextElement,
java.lang.String oclExpression) |
Query |
createQuery(ExpressionInOCL query)
Creates a new
Query encapsulating a query expression with the
current environment and extent map. |
ASResource |
cs2as(CSResource csResource)
Return the Pivot resource counterpart of an Xtext csResource.
|
void |
dispose()
Disposes any objects that I have created while I have been in use.
|
ASResource |
ecore2as(org.eclipse.emf.ecore.resource.Resource ecoreResource)
Return the Pivot resource counterpart of an ecoreResource.
|
java.lang.Object |
evaluate(java.lang.Object context,
ExpressionInOCL expression)
Evaluates a query expression on a context object (which is bound to the
self variable).
|
void |
finalize()
If the user neglects to dispose(), then detach() the EnvironmentFactory to give it a chance to clean up.
|
CompleteEnvironment |
getCompleteEnvironment() |
Class |
getContextType(java.lang.Object contextObject) |
CSResource |
getCSResource(org.eclipse.emf.common.util.URI uri) |
CSResource |
getCSResource(org.eclipse.emf.common.util.URI uri,
java.io.InputStream inputStream) |
CSResource |
getCSResource(org.eclipse.emf.common.util.URI uri,
java.lang.String testDocument) |
EnvironmentFactory |
getEnvironmentFactory() |
IdResolver |
getIdResolver() |
MetamodelManager |
getMetamodelManager() |
ModelManager |
getModelManager()
Obtains the model manager, if any, provided by the client to customize the
evaluation of constraints.
|
org.eclipse.emf.ecore.EPackage.Registry |
getPackageRegistry() |
ProjectManager |
getProjectManager() |
org.eclipse.emf.ecore.resource.ResourceSet |
getResourceSet() |
ExpressionInOCL |
getSpecification(Constraint constraint)
Return the Constraint specification as an ExpressionInOCL, parsing any OpaqueExpression
that may be encountered.
|
StandardLibrary |
getStandardLibrary() |
boolean |
isEvaluationTracingEnabled()
Deprecated.
|
CSResource |
load(org.eclipse.emf.common.util.URI uri)
Deprecated.
|
static OCL |
newInstance()
Creates a new
OCL with a new heavyweight ProjectManager and a new
ResourceSet for loaded models. |
static OCL |
newInstance(EnvironmentFactory environmentFactory)
Deprecated.
use environmentFactory.createOCL()
|
static OCL |
newInstance(org.eclipse.emf.ecore.EPackage.Registry ePackageRegistry)
Creates a new
OCL instance using the specified Ecore package registry. |
static OCL |
newInstance(ProjectManager projectManager)
Creates a new
OCL using the specified ProjectManager and a new
ResourceSet for loaded models. |
static OCL |
newInstance(ProjectManager projectManager,
org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Creates a new
OCL using the specified ProjectManager and exploiting the
already loaded models and configuration of ResourceSet. |
static OCL |
newInstance(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Creates a new
OCL with a new heavyweight ProjectManager and exploiting the
already loaded models and configuration of ResourceSet. |
ASResource |
parse(org.eclipse.emf.common.util.URI uri)
Load the Complete OCL document specified by the URI into the external ResourceSet and
parse the concrete syntax resource returning the resulting abstract syntax resource.
|
ExpressionInOCL |
parseSpecification(LanguageExpression specification)
Convert the specification of an OCL expression from textual CS form to parsed executable AS form.
|
ExpressionInOCL |
parseSpecification(java.lang.Object unusedObject,
LanguageExpression specification)
Deprecated.
use parseSpecification(specification)
|
void |
setEvaluationTracingEnabled(boolean b)
Deprecated.
|
void |
setModelManager(ModelManager modelManager)
Assigns a custom extent map to define the extents of classes in
evaluation of OCL constraints.
|
void |
validate(Constraint constraint)
Deprecated.
|
void |
validate(OCLExpression expression)
Deprecated.
|
@NonNull public static final ProjectManager NO_PROJECTS
@NonNull public static final ProjectManager CLASS_PATH
protected EnvironmentFactoryInternal environmentFactory
protected OCL(@NonNull EnvironmentFactoryInternal environmentFactory)
environmentFactory
- my environment factory@NonNull public static OCL newInstance()
OCL
with a new heavyweight ProjectManager and a new
ResourceSet for loaded models.@NonNull public static OCL newInstance(@NonNull ProjectManager projectManager)
OCL
using the specified ProjectManager and a new
ResourceSet for loaded models.@NonNull public static OCL newInstance(@NonNull ProjectManager projectManager, @NonNull org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
OCL
using the specified ProjectManager and exploiting the
already loaded models and configuration of ResourceSet.@NonNull public static OCL newInstance(@NonNull org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
OCL
with a new heavyweight ProjectManager and exploiting the
already loaded models and configuration of ResourceSet.@NonNull public static OCL newInstance(@NonNull org.eclipse.emf.ecore.EPackage.Registry ePackageRegistry)
OCL
instance using the specified Ecore package registry.
Note that the returned OCL
instance will use their own clean ResourceSet
getResourceSet()
@Deprecated @NonNull public static OCL newInstance(@NonNull EnvironmentFactory environmentFactory)
OCL
using the specified Ecore environment
factory.environmentFactory
- an environment factory for EcoreOCL
public void as2cs(@NonNull ASResource asResource, @NonNull CSResource csResource)
(BaseResource) resourceSet.createResource(outputURI, OCLinEcoreCSPackage.eCONTENT_TYPE);
@NonNull public org.eclipse.emf.ecore.resource.Resource as2ecore(@NonNull org.eclipse.emf.ecore.resource.Resource asResource, @NonNull org.eclipse.emf.common.util.URI uri) throws java.io.IOException
java.io.IOException
public boolean check(java.lang.Object context, @NonNull Constraint constraint)
context
- the self object of the constraintconstraint
- the constraint to checkcheck(Object, ExpressionInOCL)
,
evaluate(Object, ExpressionInOCL)
public boolean check(java.lang.Object context, @NonNull ExpressionInOCL specification)
context
- the self object of the constraintspecification
- the constraint to check, which must be a boolean-valued
expressionjava.lang.IllegalArgumentException
- if the constraint expression is not boolean-valuedcheck(Object, ExpressionInOCL)
,
evaluate(Object, ExpressionInOCL)
@NonNull public EvaluationVisitor createEvaluationVisitor(@Nullable java.lang.Object context, @NonNull ExpressionInOCL expression)
@NonNull public ExpressionInOCL createInvariant(@NonNull org.eclipse.emf.ecore.EObject contextElement, @NonNull java.lang.String oclExpression) throws ParserException
ParserException
public ExpressionInOCL createPostcondition(@NonNull org.eclipse.emf.ecore.EOperation contextOperation, @NonNull java.lang.String oclExpression) throws ParserException
ParserException
@NonNull public OCLHelper createOCLHelper(@Nullable org.eclipse.emf.ecore.EObject contextElement)
OCLHelper
instance for convenient parsing of
embedded constraints and query expressions for the specified context
which may be an Ecore EClassifier/EOperation/EStructuralFeature or
or Pivot Class/Operation/Property.@NonNull public ExpressionInOCL createQuery(@Nullable org.eclipse.emf.ecore.EObject contextElement, @NonNull java.lang.String oclExpression) throws ParserException
ParserException
@NonNull public Query createQuery(@NonNull ExpressionInOCL 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-valuedpublic Query createQuery(@NonNull Constraint constraint) throws ParserException
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 constraintParserException
createQuery(ExpressionInOCL)
@NonNull public ASResource cs2as(@NonNull CSResource csResource)
public void dispose()
Disposes any objects that I have created while I have been in use. This
detaches the OCL
instance from the corresponding environment
factory which will release its resources once there are no further
attached OCL clients.
dispose() should be invoked to release resources promptly. If a call to dispose() is omitted, finalize() will detach() when garbage collection of the OCL instance occurs.
@NonNull public ASResource ecore2as(@NonNull org.eclipse.emf.ecore.resource.Resource ecoreResource) throws ParserException
ParserException
@Nullable public java.lang.Object evaluate(@Nullable java.lang.Object context, @NonNull ExpressionInOCL expression)
context
- the context (self) objectexpression
- the OCL expression to evaluatecheck(Object, ExpressionInOCL)
public void finalize()
finalize
in class java.lang.Object
@NonNull public CSResource getCSResource(@NonNull org.eclipse.emf.common.util.URI uri) throws java.io.IOException
java.io.IOException
@NonNull public CSResource getCSResource(@NonNull org.eclipse.emf.common.util.URI uri, @NonNull java.io.InputStream inputStream) throws java.io.IOException
java.io.IOException
@NonNull public CSResource getCSResource(@NonNull org.eclipse.emf.common.util.URI uri, @NonNull java.lang.String testDocument) throws java.io.IOException
java.io.IOException
@NonNull public CompleteEnvironment getCompleteEnvironment()
@NonNull public EnvironmentFactory getEnvironmentFactory()
@NonNull public IdResolver getIdResolver()
@NonNull public MetamodelManager getMetamodelManager()
@Nullable public ModelManager getModelManager()
null
if
thie OCL is using the default dynamic extent map implementation@NonNull public org.eclipse.emf.ecore.EPackage.Registry getPackageRegistry()
@NonNull public ProjectManager getProjectManager()
@NonNull public org.eclipse.emf.ecore.resource.ResourceSet getResourceSet()
@Nullable public ExpressionInOCL getSpecification(@NonNull Constraint constraint) throws ParserException
ParserException
@NonNull public StandardLibrary getStandardLibrary()
@Deprecated public boolean isEvaluationTracingEnabled()
In an Eclipse environment, tracing is also enabled by turning on the org.eclipse.ocl/debug/evaluation debug option.
setEvaluationTracingEnabled(boolean)
@Deprecated @Nullable public CSResource load(@NonNull org.eclipse.emf.common.util.URI uri)
@Nullable public ASResource parse(@NonNull org.eclipse.emf.common.util.URI uri)
@NonNull public ExpressionInOCL parseSpecification(@NonNull LanguageExpression specification) throws ParserException
The returned object may be the same object as the specification, but with the more derived type to signify successful conversion from textual to executable form. Redundant re-invocation of parseSpecification is harmless.
The specification's container, typically a Constraint or Operation is used as the contextElement to determine self within the expression.
ParserException
- if text parsing fails@Deprecated @NonNull public ExpressionInOCL parseSpecification(@Nullable java.lang.Object unusedObject, @NonNull LanguageExpression specification) throws ParserException
ParserException
@Deprecated 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 void setModelManager(@Nullable ModelManager modelManager)
modelManager
- a custom extent map, or null
to use the default
dynamic extent map implementation@Deprecated public void validate(@NonNull OCLExpression expression) throws SemanticException
expression
- an expression to validateSemanticException
- on detection of any well-formedness problem in the expressionvalidate(Constraint)
@Deprecated public void validate(@NonNull Constraint constraint) throws SemanticException
constraint
- a constraint to validateSemanticException
- on detection of any well-formedness problem in the constraint