blob: d93f9b33f0c74e5095dc56fc0910fa4b803c66ee [file] [log] [blame]
h2(#ParsingDocuments). Parsing OCL Documents
As we saw in the "Parsing Constraints and Queries":#ParsingConstraints topic, the OCL parser provides an "@OCLHelper@":http://download.eclipse.org/modeling/mdt/ocl/javadoc/3.1.0/org/eclipse/ocl/helper/OCLHelper.html API for parsing constraints embedded in models. OCL also permits constraints
to be specified in a text document, as an adjunct to the model. In this case,
the concrete syntax for context declarations indicates the context of
constraints, equivalent to their placement in models.
As an example, consider the following Complete OCL document: "
!images/5120-extlibrary.png(External Library)!
"[Text for cut and paste]":../references/5120-extlibrary.ocl
bq..
The _import_ on the first line is an extension supported by the Complete OCL editor for use with the Pivot meta-model. The _import_ is not supported by the parsers for the Ecore or UML bindings, which assume that the relevant metamodels have been registered in either the global EPackage.Registry or the local EPackage.Registry passed to the EnvironmentFactory..
p.
h3. The OCL Input
The "@OCLInput@":http://download.eclipse.org/modeling/mdt/ocl/javadoc/3.1.0/org/eclipse/ocl/OCLInput.html class encapsulates an OCL document. An input can be created from a string or an
input stream.
!{width:100%}images/5120-input.png(OCL Input API)!
Given an @OCLInput@, simply ask an @OCL@ to parse it: "
!images/5120-parsing.png(Parsing the Constraints)!
"[Text for cut and paste]":../references/5120-parsing.txt
h3. Accessing the Constraints
The @OCL@ returns the list of constraints if they were
successfully parsed. They are retained by the OCL (available via the
@getConstraints()@ method at any time), and in particular,
any definitions of additional operations or attributes are available for
subsequent constraint parsing. Any number of OCL documents may be parsed by
the same @OCL@ instance, combined also with constraints
parsed by @OCLHelpers@. All of these constraints are
retained by the @OCL@ environment.
!images/5120-accessing.png(Accessing the Constraints)!
"[Text for cut and paste]":../references/5120-accessing.txt
The source for these examples may be found in the org.eclipse.ocl.ecore.tests plugin in model/parsingDocumentsExample.ocl and in src/org/eclipse/ocl/ecore/tests/DocumentationExamples.java.