Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [CompleteOCL] Programmatically register ocl file with EMF model
[CompleteOCL] Programmatically register ocl file with EMF model [message #1715129] Thu, 19 November 2015 13:15 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 30
Registered: January 2015
Member
Hi there,

I followed the CompleteOCL tutorial to succesfully load an ocl file
"core.ocl" in the Sample Ecore editor for my own EMF-model. Validation
works fine; however, I always have to use the Dialogs to manually load
the registered OCL file.

Now I try to do this programmatically.
I created an OSGi Service that gets informed about all EMF-Models that
get loaded for my Metamodel. In such event I want to programmatically
load the OCL files into the corresponding resource set in Order to
trigger EMF validation just the standard EMF way. (If this is not a good
idea, please correct me!)

I copied the code from
org.eclipse.ocl.xtext.completeocl.ui.commands.LoadCompleteOCLResourceHandler$DeferredLoadDocumentJob.processResources()


// Registering OLC components taken from
//
org.eclipse.ocl.xtext.completeocl.ui.commands.LoadCompleteOCLResourceHandler$DeferredLoadDocumentJob.processResources()
ResourceSet modelResources = model.eResource().getResourceSet();
OCLAdapter oclAdapter = OCLAdapter.getAdapter(modelResources);
CompleteOCLLoader helper = new
CompleteOCLLoader(oclAdapter.getEnvironmentFactory()) {
@Override
protected boolean error(String primaryMessage, String detailMessage) {
LOGGER.error("{} {}", primaryMessage, detailMessage);
return false;
}
};
if (!helper.loadMetamodels()) {
return;
}
//
// Load all the documents
//
for (String uriString : OCL_FILES) {
URI oclURI = URI.createPlatformPluginURI(uriString,false);
try {
if (!helper.loadDocument(oclURI)) {
continue;
}
LOGGER.debug("Register OCL file: {}", oclURI);
} catch (Throwable e) {
LOGGER.error("Error loading OCL-File: {} Message: {}, Exception:
{}", uriString, e.getMessage(), e);
}
}
helper.installPackages();

I added all required dependencies such that this compiles. But I guess
that's not enough.

At helper.loadMetamodels() I get exceptions like

13:24:37.748 [ main] INFO
o.e.o.p.i.r.StandaloneProjectMap - Failed to parse
'platform:/plugin/net.ogdf.ogml/model/ogml.genmodel'
java.io.FileNotFoundException: /model/ogml.genmodel
at
org.eclipse.osgi.storage.url.bundleentry.Handler.findBundleEntry(Handler.java:37)
~[na:na]
at
org.eclipse.osgi.storage.url.BundleResourceHandler.openConnection(BundleResourceHandler.java:169)
~[na:na]
at java.net.URL.openConnection(Unknown Source) ~[na:1.8.0_05]
at
org.eclipse.core.internal.boot.PlatformURLConnection.connect(PlatformURLConnection.java:112)
~[org.eclipse.equinox.common_3.7.0.v20150402-1709.jar:na]
at
org.eclipse.core.internal.boot.PlatformURLConnection.connect(PlatformURLConnection.java:93)
~[org.eclipse.equinox.common_3.7.0.v20150402-1709.jar:na]
at
org.eclipse.core.internal.boot.PlatformURLConnection.getInputStream(PlatformURLConnection.java:235)
~[org.eclipse.equinox.common_3.7.0.v20150402-1709.jar:na]
at
org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.createInputStream(URIHandlerImpl.java:207)
~[org.eclipse.emf.ecore_2.11.0.v20150512-0501.jar:na]
at
org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:360)
~[org.eclipse.emf.ecore_2.11.0.v20150512-0501.jar:na]
at
org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:354)
~[org.eclipse.emf.ecore_2.11.0.v20150512-0501.jar:na]
at
org.eclipse.ocl.pivot.internal.resource.ProjectMap.scanGenModels(ProjectMap.java:219)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.pivot.internal.resource.ProjectMap.scanClassPath(ProjectMap.java:178)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.pivot.internal.resource.StandaloneProjectMap.getProjectDescriptors(StandaloneProjectMap.java:2440)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.pivot.internal.resource.StandaloneProjectMap.initializeURIMap(StandaloneProjectMap.java:2569)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.pivot.internal.resource.ProjectMap.initializeURIMap(ProjectMap.java:156)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.pivot.internal.resource.StandaloneProjectMap.initializeResourceSet(StandaloneProjectMap.java:2545)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.pivot.utilities.AbstractEnvironmentFactory.createASResourceSet(AbstractEnvironmentFactory.java:225)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.pivot.utilities.AbstractEnvironmentFactory.createMetamodelManager(AbstractEnvironmentFactory.java:296)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.pivot.utilities.AbstractEnvironmentFactory.getMetamodelManager(AbstractEnvironmentFactory.java:551)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.pivot.internal.ecore.es2as.AbstractExternal2AS.findAdapter(AbstractExternal2AS.java:37)
[org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
at
org.eclipse.ocl.xtext.completeocl.utilities.CompleteOCLLoader.loadMetamodels(CompleteOCLLoader.java:76)
[org.eclipse.ocl.xtext.completeocl_1.0.0.v20150529-1942.jar:na]
[...]

At helper.loadDocument(oclURI) I get
Error loading OCL-File: /src/core.ocl Message:
org.xml.sax.SAXParseExceptionpublicId: /src/core.ocl; systemId:
/src/core.ocl; lineNumber: 1; columnNumber: 1; Content ist nicht
zulässig in Prolog., Exception:
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
org.xml.sax.SAXParseExceptionpublicId: /src/core.ocl; systemId:
platform:/src/core.ocl; lineNumber: 1; columnNumber: 1; Content ist
nicht zulässig in Prolog.

I debugged the loadDocument and it ultimately uses an XmiResourceFactory
to load my file "core.ocl" which obviously fails because it's not XML.
So I guess the OCL Resource factory is not registered in the background.
Maybe I am missing some dependencies?

these are the dependencies I use:

org.eclipse.ocl.pivot,
org.eclipse.ui,
org.eclipse.ocl.xtext.base.ui,
org.eclipse.emf.validation.ocl;bundle-version="1.4.0",
org.eclipse.ocl.ecore;bundle-version="3.5.0",
org.slf4j.api;bundle-version="1.7.2",
org.eclipse.ocl.xtext.completeocl,
org.eclipse.e4.ui.workbench;bundle-version="1.3.0",
org.eclipse.e4.core.services;bundle-version="2.0.0",
org.eclipse.e4.core.contexts;bundle-version="1.4.0",
org.eclipse.e4.core.di;bundle-version="1.5.0",
org.eclipse.osgi.services;bundle-version="3.5.0"

Any hints?

Cheers,
Hauke
Re: [CompleteOCL] Programmatically register ocl file with EMF model [message #1715136 is a reply to message #1715129] Thu, 19 November 2015 14:07 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Please use the OCL newsgroup/forum for OCL issues.

You might find the org.eclipse.ocl.pivot.complete_ocl_registry extension
point helpful for registering your document sp that it is automatocally
visible in the OCL->Load dialog.

Unfortunately EMF provides no EPackage loading delegate so there is no
hook available to load a Complete OCL document automatically. I don;t
know anything about OSGI services; how do they help?

The file access failure is loilely becuase no ProjectMap has initialized
the path sysnonyms, or because your target model is not in a plugin on
the class path or your plugin registrations are erroneous.

https://wiki.eclipse.org/OCL/New_and_Noteworthy/Mars#SR1 shows a couple
of fixes that might be relevant to you.

Regards

Ed Willink


On 19/11/2015 13:15, Hauke Fuhrmann wrote:
> Hi there,
>
> I followed the CompleteOCL tutorial to succesfully load an ocl file
> "core.ocl" in the Sample Ecore editor for my own EMF-model. Validation
> works fine; however, I always have to use the Dialogs to manually load
> the registered OCL file.
>
> Now I try to do this programmatically.
> I created an OSGi Service that gets informed about all EMF-Models that
> get loaded for my Metamodel. In such event I want to programmatically
> load the OCL files into the corresponding resource set in Order to
> trigger EMF validation just the standard EMF way. (If this is not a
> good idea, please correct me!)
>
> I copied the code from
> org.eclipse.ocl.xtext.completeocl.ui.commands.LoadCompleteOCLResourceHandler$DeferredLoadDocumentJob.processResources()
>
>
> // Registering OLC components taken from
> //
> org.eclipse.ocl.xtext.completeocl.ui.commands.LoadCompleteOCLResourceHandler$DeferredLoadDocumentJob.processResources()
> ResourceSet modelResources =
> model.eResource().getResourceSet();
> OCLAdapter oclAdapter =
> OCLAdapter.getAdapter(modelResources);
> CompleteOCLLoader helper = new
> CompleteOCLLoader(oclAdapter.getEnvironmentFactory()) {
> @Override
> protected boolean error(String primaryMessage, String
> detailMessage) {
> LOGGER.error("{} {}", primaryMessage, detailMessage);
> return false;
> }
> };
> if (!helper.loadMetamodels()) {
> return;
> }
> //
> // Load all the documents
> //
> for (String uriString : OCL_FILES) {
> URI oclURI =
> URI.createPlatformPluginURI(uriString,false);
> try {
> if (!helper.loadDocument(oclURI)) {
> continue;
> }
> LOGGER.debug("Register OCL file: {}", oclURI);
> } catch (Throwable e) {
> LOGGER.error("Error loading OCL-File: {} Message:
> {}, Exception: {}", uriString, e.getMessage(), e);
> }
> }
> helper.installPackages();
>
> I added all required dependencies such that this compiles. But I guess
> that's not enough.
>
> At helper.loadMetamodels() I get exceptions like
>
> 13:24:37.748 [ main] INFO
> o.e.o.p.i.r.StandaloneProjectMap - Failed to parse
> 'platform:/plugin/net.ogdf.ogml/model/ogml.genmodel'
> java.io.FileNotFoundException: /model/ogml.genmodel
> at
> org.eclipse.osgi.storage.url.bundleentry.Handler.findBundleEntry(Handler.java:37)
> ~[na:na]
> at
> org.eclipse.osgi.storage.url.BundleResourceHandler.openConnection(BundleResourceHandler.java:169)
> ~[na:na]
> at java.net.URL.openConnection(Unknown Source) ~[na:1.8.0_05]
> at
> org.eclipse.core.internal.boot.PlatformURLConnection.connect(PlatformURLConnection.java:112)
> ~[org.eclipse.equinox.common_3.7.0.v20150402-1709.jar:na]
> at
> org.eclipse.core.internal.boot.PlatformURLConnection.connect(PlatformURLConnection.java:93)
> ~[org.eclipse.equinox.common_3.7.0.v20150402-1709.jar:na]
> at
> org.eclipse.core.internal.boot.PlatformURLConnection.getInputStream(PlatformURLConnection.java:235)
> ~[org.eclipse.equinox.common_3.7.0.v20150402-1709.jar:na]
> at
> org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.createInputStream(URIHandlerImpl.java:207)
> ~[org.eclipse.emf.ecore_2.11.0.v20150512-0501.jar:na]
> at
> org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:360)
> ~[org.eclipse.emf.ecore_2.11.0.v20150512-0501.jar:na]
> at
> org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:354)
> ~[org.eclipse.emf.ecore_2.11.0.v20150512-0501.jar:na]
> at
> org.eclipse.ocl.pivot.internal.resource.ProjectMap.scanGenModels(ProjectMap.java:219)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.pivot.internal.resource.ProjectMap.scanClassPath(ProjectMap.java:178)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.pivot.internal.resource.StandaloneProjectMap.getProjectDescriptors(StandaloneProjectMap.java:2440)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.pivot.internal.resource.StandaloneProjectMap.initializeURIMap(StandaloneProjectMap.java:2569)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.pivot.internal.resource.ProjectMap.initializeURIMap(ProjectMap.java:156)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.pivot.internal.resource.StandaloneProjectMap.initializeResourceSet(StandaloneProjectMap.java:2545)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.pivot.utilities.AbstractEnvironmentFactory.createASResourceSet(AbstractEnvironmentFactory.java:225)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.pivot.utilities.AbstractEnvironmentFactory.createMetamodelManager(AbstractEnvironmentFactory.java:296)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.pivot.utilities.AbstractEnvironmentFactory.getMetamodelManager(AbstractEnvironmentFactory.java:551)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.pivot.internal.ecore.es2as.AbstractExternal2AS.findAdapter(AbstractExternal2AS.java:37)
> [org.eclipse.ocl.pivot_1.0.0.v20150603-1503.jar:na]
> at
> org.eclipse.ocl.xtext.completeocl.utilities.CompleteOCLLoader.loadMetamodels(CompleteOCLLoader.java:76)
> [org.eclipse.ocl.xtext.completeocl_1.0.0.v20150529-1942.jar:na]
> [...]
>
> At helper.loadDocument(oclURI) I get
> Error loading OCL-File: /src/core.ocl Message:
> org.xml.sax.SAXParseExceptionpublicId: /src/core.ocl; systemId:
> /src/core.ocl; lineNumber: 1; columnNumber: 1; Content ist nicht
> zulässig in Prolog., Exception:
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
> org.xml.sax.SAXParseExceptionpublicId: /src/core.ocl; systemId:
> platform:/src/core.ocl; lineNumber: 1; columnNumber: 1; Content ist
> nicht zulässig in Prolog.
>
> I debugged the loadDocument and it ultimately uses an
> XmiResourceFactory to load my file "core.ocl" which obviously fails
> because it's not XML.
> So I guess the OCL Resource factory is not registered in the
> background. Maybe I am missing some dependencies?
>
> these are the dependencies I use:
>
> org.eclipse.ocl.pivot,
> org.eclipse.ui,
> org.eclipse.ocl.xtext.base.ui,
> org.eclipse.emf.validation.ocl;bundle-version="1.4.0",
> org.eclipse.ocl.ecore;bundle-version="3.5.0",
> org.slf4j.api;bundle-version="1.7.2",
> org.eclipse.ocl.xtext.completeocl,
> org.eclipse.e4.ui.workbench;bundle-version="1.3.0",
> org.eclipse.e4.core.services;bundle-version="2.0.0",
> org.eclipse.e4.core.contexts;bundle-version="1.4.0",
> org.eclipse.e4.core.di;bundle-version="1.5.0",
> org.eclipse.osgi.services;bundle-version="3.5.0"
>
> Any hints?
>
> Cheers,
> Hauke
Previous Topic:[EMF Forms] how to localize the built in controls (e.g. the Date Renderer)?
Next Topic:[Texo] NoSuchMethodError
Goto Forum:
  


Current Time: Thu Apr 18 20:45:52 GMT 2024

Powered by FUDForum. Page generated in 0.01766 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top