
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/ocl/javadoc/6.4.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: "

!{width:70%}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 ignored 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/ocl/javadoc/6.4.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: "

!{width:70%}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.

!{width:70%}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.
