If you are using EMF standalone, i.e. you are not running it in an Eclipse-based environment, and you want to use OCL some additional steps have to be performed besides registering your resource factory.
This description is for the MDT OCL project which can be found and installed from the Juno update site under Modeling > OCL Examples and Editors.
For the sake of completeness this is the code necessary to register a resource factory to be able to load your model files:
// Register the XMI resource factory for the any extension Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE; Map<String, Object> map = registry.getExtensionToFactoryMap(); map.put("*", new XMIResourceFactoryImpl()); // or specifically state your file extension // initialize your package YourPackage.eINSTANCE.eClass();
If you are using your own resource factory, e.g. to force generation of unique IDs when serializing your model, replace XMIResourceFactoryImpl with your own.
To use OCL additionally use the following:
// register Pivot globally (resourceSet == null) org.eclipse.ocl.examples.pivot.OCL.initialize(null); 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()); OCLinEcoreStandaloneSetup.doSetup(); // install the OCL standard library OCLstdlib.install();
This requires dependencies to org.eclipse.ocl.examples.xtext.oclinecore and com.google.log4j (as David pointed out in the comments, thanks!). EMF itself requires org.eclipse.emf.ecore and org.eclipse.emf.ecore.xmi.
Update 07.12.2012: Added missing call to install the OCL standard library and dependencies.