[364797] - [environment]
http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore times out
- Making the Ecore OCL.initialize util use the true model
- Minor OCLStandardLibraryImpl fix
diff --git a/plugins/org.eclipse.ocl.ecore/src/org/eclipse/ocl/ecore/OCL.java b/plugins/org.eclipse.ocl.ecore/src/org/eclipse/ocl/ecore/OCL.java
index 1626cac..f92fbf1 100644
--- a/plugins/org.eclipse.ocl.ecore/src/org/eclipse/ocl/ecore/OCL.java
+++ b/plugins/org.eclipse.ocl.ecore/src/org/eclipse/ocl/ecore/OCL.java
@@ -27,6 +27,7 @@
 import org.eclipse.emf.ecore.EPackage;
 import org.eclipse.emf.ecore.EParameter;
 import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.ResourceSet;
 import org.eclipse.emf.ecore.resource.URIConverter;
@@ -34,7 +35,9 @@
 import org.eclipse.ocl.Environment;
 import org.eclipse.ocl.EnvironmentFactory;
 import org.eclipse.ocl.ParserException;
+import org.eclipse.ocl.ecore.internal.OCLEcorePlugin;
 import org.eclipse.ocl.helper.OCLHelper;
+import org.eclipse.ocl.internal.helper.PluginFinder;
 
 /**
  * Convenient subclass of the <code>OCL</code> fa&ccedil;ade that binds the
@@ -76,13 +79,41 @@
 			: Resource.Factory.Registry.INSTANCE;
 		resourceFactoryRegistry.getExtensionToFactoryMap().put(
 			"ecore", new EcoreResourceFactoryImpl()); //$NON-NLS-1$
+		
+		EPackage.Registry packageRegistry = resourceSet == null
+				? EPackage.Registry.INSTANCE
+				: resourceSet.getPackageRegistry();
+		packageRegistry.put(org.eclipse.ocl.ecore.EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE);
+		
+		final String oclEcorePluginId = OCLEcorePlugin.getPluginId();		
+		String oclLocation = System.getProperty(oclEcorePluginId);		
+		if (oclLocation == null) {
+			PluginFinder pluginFinder = new PluginFinder(oclEcorePluginId);
+			pluginFinder.resolve();
+			oclLocation = pluginFinder.get(oclEcorePluginId);
+			if (oclLocation == null) {
+				return "'" + oclEcorePluginId + "' not found on class-path"; //$NON-NLS-1$ //$NON-NLS-2$
+			}
+		}
 		Map<URI,URI> uriMap = resourceSet != null
 				? resourceSet.getURIConverter().getURIMap()
 				: URIConverter.URI_MAP;
-		uriMap.put(URI.createURI(EcoreEnvironment.OCL_STANDARD_LIBRARY_NS_URI),
-			URI.createURI("no-such-protocol:/this/does/not/exist")); //$NON-NLS-1$
+		uriMap.put(URI.createURI(EcoreEnvironment.OCL_STANDARD_LIBRARY_NS_URI),			
+			createURI(oclLocation, "/model/oclstdlib.ecore")); //$NON-NLS-1$
 		return null;
 	}
+	
+	private static URI createURI(String locationURI, String string) {
+		while (locationURI.endsWith("/") //$NON-NLS-1$
+				|| locationURI.endsWith("\\")) { //$NON-NLS-1$
+			locationURI = locationURI.substring(0, locationURI.length()-1);
+		}
+		if (locationURI.endsWith(".jar!")) { //$NON-NLS-1$
+			return URI.createURI(locationURI + string);
+		} else {
+			return URI.createFileURI(locationURI + string);
+		}
+	}
 
 	/**
      * Initializes me with an environment factory for the Ecore metamodel.
diff --git a/plugins/org.eclipse.ocl.uml/src/org/eclipse/ocl/uml/internal/OCLStandardLibraryImpl.java b/plugins/org.eclipse.ocl.uml/src/org/eclipse/ocl/uml/internal/OCLStandardLibraryImpl.java
index 59b2868..1d98cc6 100644
--- a/plugins/org.eclipse.ocl.uml/src/org/eclipse/ocl/uml/internal/OCLStandardLibraryImpl.java
+++ b/plugins/org.eclipse.ocl.uml/src/org/eclipse/ocl/uml/internal/OCLStandardLibraryImpl.java
@@ -201,7 +201,7 @@
         ResourceSet rset = new ResourceSetImpl();
         // Ensure that a UMLResource factory is registered for the uml extension.
         // Note that when running standalone, a registration in the global registry is not certain.
-        OCL.initialize(null);
+        OCL.initialize(rset);
         Resource res = null;
         
         try {