Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Unable to perform OCL validation outside eclipse
Unable to perform OCL validation outside eclipse [message #691471] Fri, 01 July 2011 14:16 Go to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 99
Registered: June 2010
Member
Hi,

I'm trying to create a class that is capable of loading a model (conforming to a specific metamodel) and an OCL document. The purpose of the class is to validate the ocl constraints (from the OCL document) on the model.

The class is based on the CompleteOCLEObjectValidator as shown in this presentation: http://www.slideshare.net/EdWillink/enriching-withocl

Note that in my case, I'm not using some kind of an XText based editor. Therefore, I think that I can not completely copy the example as found in the presentation.

However, my code looks like this:

public class MyValidator extends CompleteOCLEObjectValidator {

	public MyValidator(EPackage ePackage, URI oclURI) {
		super(ePackage, oclURI);
	}

	public static void main(String[] args) {
		ResourceSet resourceSet = new ResourceSetImpl();
		Resource model;
		URI oclURI = URI.createFileURI(args[0]);
		URI modelURI = URI.createFileURI(args[1]);

		EXTLibraryPackage.eINSTANCE.eClass();

		// register XMI resource factory for all other extensions
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
				Resource.Factory.Registry.DEFAULT_EXTENSION,
				new XMIResourceFactoryImpl());


		model = resourceSet.getResource(modelURI, true);
		EObject rootObject = model.getContents().get(0);

		MyValidator myValidator = new MyValidator(EXTLibraryPackage.eINSTANCE,
				oclURI);

		myValidator.validate(rootObject, null,null);
	}

}



However, when I try to run it (started as a run configuration from eclipse), I get the following message:

Exception in thread "main" java.lang.ExceptionInInitializerError
	at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot$Factory.<init>(Ecore2Pivot.java:72)
	at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot$Factory.<init>(Ecore2Pivot.java:71)
...
Caused by: java.lang.NullPointerException
	at org.eclipse.ocl.examples.pivot.utilities.TypeManager.<clinit>(TypeManager.java:200)


I think I'm doing something wrong regarding the initialization. Any ideas?

Greetings,
Wilbert.
Re: Unable to perform OCL validation outside eclipse [message #691559 is a reply to message #691471] Fri, 01 July 2011 17:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi

Have you not done any of the initialization in
http://help.eclipse.org/indigo/topic/org.eclipse.ocl.doc/help/Standalone.html
and none of the initialization omitted.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=350955 raised to improve
the API and documentation.

The following has the required init and works for me.

public class MyValidator {

public static void main(String[] args) throws ParserException {
// Initialize OCL
CompleteOCLStandaloneSetup.doSetup();
OCLstdlib.install();

URI oclURI = URI.createFileURI(args[0]);
URI modelURI = URI.createFileURI(args[1]);

// Register path in *.ocl for use standalone
// FIXME (Bug 350955) it should be possible to do this in a
local ResourceSet

EPackage.Registry.INSTANCE.put("platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore",
EXTLibraryPackage.eINSTANCE);
CompleteOCLEObjectValidator myValidator = new
CompleteOCLEObjectValidator(EXTLibraryPackage.eINSTANCE, oclURI);

// register XMI resource factory for all other extensions
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());

ResourceSet resourceSet = new ResourceSetImpl();
Resource model = resourceSet.getResource(modelURI, true);
EObject rootObject = model.getContents().get(0);
BasicDiagnostic diagnostics = new BasicDiagnostic();
myValidator.validate(rootObject, diagnostics, null);
// FIXME Should install a Composite EObjectValidator to do both OCL and
EMF validation
// EValidator.Registry.INSTANCE.put(EXTLibraryPackage.eINSTANCE,
myValidator);
// Diagnostic diagnostics =
Diagnostician.INSTANCE.validate(rootObject);
// System.out.println(diagnostics.getMessage());
for (Object object : diagnostics.getChildren()) {
System.out.println(object);
}
}

}

Regards

Ed Willink

On 01/07/2011 16:16, Wilbert Alberts wrote:
> Hi,
>
> I'm trying to create a class that is capable of loading a model
> (conforming to a specific metamodel) and an OCL document. The purpose
> of the class is to validate the ocl constraints (from the OCL
> document) on the model.
>
> The class is based on the CompleteOCLEObjectValidator as shown in this
> presentation: http://www.slideshare.net/EdWillink/enriching-withocl
>
> Note that in my case, I'm not using some kind of an XText based
> editor. Therefore, I think that I can not completely copy the example
> as found in the presentation.
> However, my code looks like this:
>
> public class MyValidator extends CompleteOCLEObjectValidator {
>
> public MyValidator(EPackage ePackage, URI oclURI) {
> super(ePackage, oclURI);
> }
>
> public static void main(String[] args) {
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource model;
> URI oclURI = URI.createFileURI(args[0]);
> URI modelURI = URI.createFileURI(args[1]);
>
> EXTLibraryPackage.eINSTANCE.eClass();
>
> // register XMI resource factory for all other extensions
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
> Resource.Factory.Registry.DEFAULT_EXTENSION,
> new XMIResourceFactoryImpl());
>
>
> model = resourceSet.getResource(modelURI, true);
> EObject rootObject = model.getContents().get(0);
>
> MyValidator myValidator = new
> MyValidator(EXTLibraryPackage.eINSTANCE,
> oclURI);
>
> myValidator.validate(rootObject, null,null);
> }
>
> }
>
>
>
> However, when I try to run it (started as a run configuration from
> eclipse), I get the following message:
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
> at
> org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot$Factory.<init>(Ecore2Pivot.java:72)
> at
> org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot$Factory.<init>(Ecore2Pivot.java:71)
> ...
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.ocl.examples.pivot.utilities.TypeManager.<clinit>(TypeManager.java:200)
>
>
> I think I'm doing something wrong regarding the initialization. Any
> ideas?
>
> Greetings,
> Wilbert.
>
Re: Unable to perform OCL validation outside eclipse [message #692305 is a reply to message #691559] Mon, 04 July 2011 07:32 Go to previous messageGo to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 99
Registered: June 2010
Member
Hi Ed,

Thanks for your reply. The code is running now. However, I get an error which I don't quite understand.

The ocl file containing the constraints I'm trying to validate looks like:

import 'platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore'

package extlibrary

context Library

inv NameShouldBeWilbert: self.name = 'Wilbert'

endpackage


Running the validator leads to the following message:

0    [main] ERROR idation.CompleteOCLEObjectValidator  - Failed to load 'Library.ocl
Unresolved import 'platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore' : resolve against non-hierarchical or relative base
Unresolved Package 'extlibrary'
Unresolved Type 'Library'
Diagnosis of org.eclipse.emf.examples.extlibrary.impl.LibraryImpl@e1f305{Library.xmi#/}


The editor inside eclipse signals no errors in the OCL file, so it recognizes the extlibrary.ecore. I even tried to deploy the extlibrary project as a plugin and replaced the platform based URI by a http uri (as given by the properties of teh extlibrary package in the ecore file. Unfortunately that doesn't help.

Another suggestion would be helpful,

Greetings,
Wilbert.


Re: Unable to perform OCL validation outside eclipse [message #692344 is a reply to message #692305] Mon, 04 July 2011 09:00 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi
>
> Thanks for your reply. The code is running now. However, I get an
> error which I don't quite understand.
>
It cannot both be running and getting an error.

Please check that you are using my code; the initialization order is
important.

Please post examples rather than indications of your problems.

Regards

Ed Willink
Re: Unable to perform OCL validation outside eclipse [message #692366 is a reply to message #692344] Mon, 04 July 2011 09:58 Go to previous messageGo to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 99
Registered: June 2010
Member
Hi Ed,

Indeed, running and giving an error sounds contradictory.

OK, the code:

	public static void main(String[] args) {
		// Initialize OCL
		CompleteOCLStandaloneSetup.doSetup();
		OCLstdlib.install();

		URI oclURI = URI.createFileURI(args[0]);
		URI modelURI = URI.createFileURI(args[1]);

		// Register path in *.ocl for use standalone
		// FIXME (Bug 350955) it should be possible to do this in a local
		// ResourceSet

		EPackage.Registry.INSTANCE
				.put("platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore",
						EXTLibraryPackage.eINSTANCE);
		CompleteOCLEObjectValidator myValidator = new CompleteOCLEObjectValidator(
				EXTLibraryPackage.eINSTANCE, oclURI);

		// register XMI resource factory for all other extensions
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
				Resource.Factory.Registry.DEFAULT_EXTENSION,
				new XMIResourceFactoryImpl());

		ResourceSet resourceSet = new ResourceSetImpl();
		Resource model = resourceSet.getResource(modelURI, true);
		EObject rootObject = model.getContents().get(0);

		EValidator.Registry.INSTANCE.put(EXTLibraryPackage.eINSTANCE,
				myValidator);

		Diagnostic diagnostics = Diagnostician.INSTANCE.validate(rootObject);

		System.out.println(diagnostics.getMessage());
		for (Object object : diagnostics.getChildren()) {
			System.out.println(object);

		}
	}


As I don't understand the 'FIXME' comment you added, it might be that I was expected to modify something there.

The OCL file containing the constraints:

import 'platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore'

package extlibrary

context Library

inv NameShouldBeWilbert: self.name = 'Wilbert'

endpackage


The error message:

0 [main] ERROR idation.CompleteOCLEObjectValidator - Failed to load 'Library.ocl
Unresolved import 'platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore' : resolve against non-hierarchical or relative base
Unresolved Package 'extlibrary'
Unresolved Type 'Library'
Diagnosis of org.eclipse.emf.examples.extlibrary.impl.LibraryImpl@232697{Library.xmi#/}

I checked that the 'unresolved import' URI refers to the one given in the OCL file.

Hope this helps.

Greetings,
Wilbert.
Re: Unable to perform OCL validation outside eclipse [message #692537 is a reply to message #692366] Mon, 04 July 2011 16:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi

You did'n't provide your command line/launch config or XMI file.

It looks as if you haven't provided a full absolute path to Library.ocl
on your args. Your processing certainly has nothing to apply default paths.

Regards

Ed Willink


On 04/07/2011 10:58, Wilbert Alberts wrote:
> Hi Ed,
>
> Indeed, running and giving an error sounds contradictory.
>
> OK, the code:
>
> public static void main(String[] args) {
> // Initialize OCL
> CompleteOCLStandaloneSetup.doSetup();
> OCLstdlib.install();
>
> URI oclURI = URI.createFileURI(args[0]);
> URI modelURI = URI.createFileURI(args[1]);
>
> // Register path in *.ocl for use standalone
> // FIXME (Bug 350955) it should be possible to do this in a local
> // ResourceSet
>
> EPackage.Registry.INSTANCE
>
> .put("platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore",
> EXTLibraryPackage.eINSTANCE);
> CompleteOCLEObjectValidator myValidator = new
> CompleteOCLEObjectValidator(
> EXTLibraryPackage.eINSTANCE, oclURI);
>
> // register XMI resource factory for all other extensions
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
> Resource.Factory.Registry.DEFAULT_EXTENSION,
> new XMIResourceFactoryImpl());
>
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource model = resourceSet.getResource(modelURI, true);
> EObject rootObject = model.getContents().get(0);
>
> EValidator.Registry.INSTANCE.put(EXTLibraryPackage.eINSTANCE,
> myValidator);
>
> Diagnostic diagnostics =
> Diagnostician.INSTANCE.validate(rootObject);
>
> System.out.println(diagnostics.getMessage());
> for (Object object : diagnostics.getChildren()) {
> System.out.println(object);
>
> }
> }
>
> As I don't understand the 'FIXME' comment you added, it might be that
> I was expected to modify something there.
> The OCL file containing the constraints:
>
> import
> 'platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore'
>
> package extlibrary
>
> context Library
>
> inv NameShouldBeWilbert: self.name = 'Wilbert'
>
> endpackage
>
> The error message:
> 0 [main] ERROR idation.CompleteOCLEObjectValidator - Failed to
> load 'Library.ocl
> Unresolved import
> 'platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore'
> : resolve against non-hierarchical or relative base
> Unresolved Package 'extlibrary'
> Unresolved Type 'Library'
> Diagnosis of
> mailto:org.eclipse.emf.examples.extlibrary.impl.LibraryImpl@232697{Library.xmi#/}
>
> I checked that the 'unresolved import' URI refers to the one given in
> the OCL file.
> Hope this helps.
>
> Greetings,
> Wilbert.
>
Re: Unable to perform OCL validation outside eclipse [message #692747 is a reply to message #692537] Tue, 05 July 2011 07:08 Go to previous messageGo to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 99
Registered: June 2010
Member
Hi Ed,

GREAT!

I modified the command line arguments (in the launch configuration) such that they have an absolute path. Now it works!

The only thing I would like to know now is: why? Note that when I changed the import 'platform:/resource/or...del/extlibrary.ecore' line, I saw the change reflected in the error message so I had the impression that the OCL file had been read (although I didn't understand what was meant with: 'resolve against non-hierarchical or relative base'). But clearly your suggestion helped.

I appreciate your help and would even be more thankful in case you could point me to some clue to the 'why' part.

Thanks!

Wilbert
Re: Unable to perform OCL validation outside eclipse [message #693016 is a reply to message #692747] Tue, 05 July 2011 16:13 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi
> The only thing I would like to know now is: why? Note that when I
> changed the import 'platform:/resource/or...del/extlibrary.ecore' line,
which line? there's at least: one in the *.ocl and one in the *.java
> I saw the change reflected in the error message
what error message? from the editor or from running the program?
> so I had the impression that the OCL file had been read
Regards

Ed Willink
Re: Unable to perform OCL validation outside eclipse [message #694202 is a reply to message #693016] Fri, 08 July 2011 05:22 Go to previous messageGo to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 99
Registered: June 2010
Member
Quote:

> The only thing I would like to know now is: why? Note that when I
> changed the import 'platform:/resource/or...del/extlibrary.ecore' line,
which line? there's at least: one in the *.ocl and one in the *.java

I meant the *.ocl line.

Quote:
> I saw the change reflected in the error message
what error message? from the editor or from running the program?

The error from running the program:

0    [main] ERROR idation.CompleteOCLEObjectValidator  - Failed to load 'Library.ocl
Unresolved import 'platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore' : resolve against non-hierarchical or relative base
Unresolved Package 'extlibrary'
Unresolved Type 'Library'
Diagnosis of org.eclipse.emf.examples.extlibrary.impl.LibraryImpl@e1f305{Library.xmi#/}


The line starting with Unresolved import changed according to the content of the ocl file. So putting import foo.ecore in the ocl file lead to Unresolved import 'foo.ecore'

My apologies for being so ambiguous.

Greetings,
Wilbert
Re: Unable to perform OCL validation outside eclipse [message #694397 is a reply to message #692747] Fri, 08 July 2011 13:34 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi

The "import
'platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore'"
within the *.ocl can be resolved by the editor using Eclipse plugin
registrations.

The corresponding standalone functionality requires manual assistance to
make the 'platform:' scheme work. This is what

// Register path in *.ocl for use standalone
// FIXME (Bug 350955) it should be possible to do this in a
local ResourceSet

EPackage.Registry.INSTANCE.put("platform:/resource/org.eclipse.emf.examples.library/model/extlibrary.ecore",
EXTLibraryPackage.eINSTANCE);

(together with my note to myself to improve the API).

If you change the import you will need to ensure that the standalone
functionality is able to resolve the URI used in the *.ocl file.

Regards

Ed Willink

On 05/07/2011 08:08, Wilbert Alberts wrote:
> Hi Ed,
>
> GREAT!
>
> I modified the command line arguments (in the launch configuration)
> such that they have an absolute path. Now it works!
>
> The only thing I would like to know now is: why? Note that when I
> changed the import 'platform:/resource/or...del/extlibrary.ecore'
> line, I saw the change reflected in the error message so I had the
> impression that the OCL file had been read (although I didn't
> understand what was meant with: 'resolve against non-hierarchical or
> relative base'). But clearly your suggestion helped.
>
> I appreciate your help and would even be more thankful in case you
> could point me to some clue to the 'why' part.
>
> Thanks!
>
> Wilbert
>
Previous Topic:can ocl validate runtimeobjects against their classes
Next Topic:Validating superclass constraints in OCL
Goto Forum:
  


Current Time: Fri Dec 19 21:41:05 GMT 2014

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

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