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 |
Wilbert Alberts Messages: 210 Registered: June 2010 |
Senior 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 |
Ed Willink Messages: 7670 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 #692366 is a reply to message #692344] |
Mon, 04 July 2011 09:58 |
Wilbert Alberts Messages: 210 Registered: June 2010 |
Senior 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 |
Ed Willink Messages: 7670 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.
>
|
|
| | | | |
Goto Forum:
Current Time: Wed Sep 25 23:32:23 GMT 2024
Powered by FUDForum. Page generated in 0.04390 seconds
|