Standalone Configuration

Standalone Configuration

If you use Eclipse OCL within Eclipse you should find that the appropriate registrations are provided for you automatically by the plugin registration mechanisms.

However if you use Eclipse OCL outside Eclipse, for instance in JUnit tests, you must provide the corresponding registrations in your code.

Ecore

For the Ecore metamodel, the required registrations should be provided by invoking org.eclipse.ocl.ecore.OCL.initialize(ResourceSet).

This may be invoked with a null argument to install the registrations in the global EPackage.Registry. This is not normally recommended, but since this is for your application, the integrity of the global registry is your responsibility.

It is normally recommended to install the registrations solely for use in your own ResourceSet and to pass that to the initialize routine.

This initialization ensures that *.ecore is understood.

If you want to use EMF delegates to dispatch OCL you also need the following code from org.eclipse.ocl.ecore.tests.DelegatesTest.

import org.eclipse.ocl.ecore.delegate.*;

String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI;
EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put
  (oclDelegateURI, new OCLInvocationDelegateFactory.Global());
EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put
  (oclDelegateURI, new OCLSettingDelegateFactory.Global());
EValidator.ValidationDelegate.Registry.INSTANCE.put
  (oclDelegateURI, new OCLValidationDelegateFactory.Global());
QueryDelegate.Factory.Registry.INSTANCE.put
  (oclDelegateURI, new OCLQueryDelegateFactory.Global());

UML

For the UML metamodel, the required registrations should be provided in a similar way by invoking org.eclipse.ocl.uml.OCL.initialize(ResourceSet).

This initialization ensures that *.uml is understood that http://www.eclipse.org/ocl/1.1.0/oclstdlib.uml is known and that standard pathmap: locations are resolvable.

Pivot

For the Pivot metamodel, the required registrations should be provided in a similar way by invoking org.eclipse.ocl.examples.pivot.OCL.initialize(ResourceSet).

This initialization ensures that *.ecore is understood. If *.uml support is also required, invoke org.eclipse.ocl.examples.pivot.uml.UML2Pivot.initialize(ResourceSet) as well.

If you want to use EMF delegates to dispatch OCL you also need the following code from org.eclipse.ocl.examples.pivot.tests.DelegatesTest. (The same code as for Ecore but from a different package).

import org.eclipse.ocl.examples.pivot.delegate.*;

String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT;
EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put
  (oclDelegateURI, new OCLInvocationDelegateFactory.Global());
EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put
  (oclDelegateURI, new OCLSettingDelegateFactory.Global());
EValidator.ValidationDelegate.Registry.INSTANCE.put
  (oclDelegateURI, new OCLValidationDelegateFactory.Global());
QueryDelegate.Factory.Registry.INSTANCE.put
  (oclDelegateURI, new OCLQueryDelegateFactory.Global());

Xtext Editors

Each of the Xtext editors has a standard Xtext startup that ensures that the appropriate Resource registrations are installed.

org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup.doSetup().
org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup.doSetup().
org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup.doSetup().
org.eclipse.ocl.examples.xtext.oclstdlib.OCLstdlibStandaloneSetup.doSetup().