Home » Modeling » OCL » Unable to perform OCL validation outside eclipse
Unable to perform OCL validation outside eclipse [message #691471] |
Fri, 01 July 2011 10:16  |
Eclipse User |
|
|
|
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 13:55   |
Eclipse User |
|
|
|
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 05:58   |
Eclipse User |
|
|
|
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 12:50   |
Eclipse User |
|
|
|
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 #694397 is a reply to message #692747] |
Fri, 08 July 2011 09:34  |
Eclipse User |
|
|
|
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
>
|
|
|
Goto Forum:
Current Time: Wed Jul 23 00:32:51 EDT 2025
Powered by FUDForum. Page generated in 0.06821 seconds
|