(Pivot) Parsing OCL Document which complements a UML model [message #1098370] |
Sat, 31 August 2013 01:28 |
John Guerson Messages: 51 Registered: August 2011 |
Member |
|
|
Hi,
I was trying to replicate the tutorial: Parsing OCL Documents - Pivot Guide - Juno
Using a UML model instead of an Ecore one.
http://help.eclipse.org/juno/topic/org.eclipse.ocl.doc/help/PivotParsingDocuments.html?cp=49_6_5
However, I'm unable to get it running.
It seems that the EObject returned in the iteration over "pivotResource.getAllContents()" isn't an "ocl.examples.pivot.Constraint".
I would really appreciate any help!
Here is my code: (models attached)
Best Regards!
public static void main(String[]args)
{
String oclPath = "C:\\Users\\John\\myProject\\model\\project.ocl";
URI oclURI = URI.createFileURI(oclPath);
String umlPath = "C:\\Users\\John\\myProject\\model\\project.uml";
URI umlURI = URI.createFileURI(umlPath);
ResourceSet resourceSet = new ResourceSetImpl();
// ==== Configurations ===
OCLstdlib.install();
org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup.doSetup();
org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup.doSetup();
org.eclipse.ocl.examples.xtext.oclstdlib.OCLstdlibStandaloneSetup.doSetup();
UMLResourcesUtil.init(resourceSet);
org.eclipse.ocl.examples.pivot.uml.UML2Pivot.initialize(resourceSet);
OCL.initialize(resourceSet);
org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.getAdapter(resourceSet);
org.eclipse.ocl.examples.pivot.delegate.OCLDelegateDomain.initialize(resourceSet);
// === Loading UML Model to Resource ===
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE
);
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
Resource umlResource = resourceSet.getResource(umlURI,true);
org.eclipse.uml2.uml.Package umlmodel = (org.eclipse.uml2.uml.Package) umlResource.getContents().get(0);
umlResource.getResourceSet().getPackageRegistry().put(null,umlmodel);
// ==== Parsing OCL ====
PivotEnvironmentFactory environmentFactory = new PivotEnvironmentFactory(
umlResource.getResourceSet().getPackageRegistry(), null);
OCL ocl = OCL.newInstance(environmentFactory);
Resource pivotResource = ocl.parse(oclURI);
// ==== Printing ====
for(TreeIterator<EObject> tit = pivotResource.getAllContents(); tit.hasNext();){
EObject next = tit.next();
System.out.println(next); // printing for test
if(next instanceof Constraint){
System.out.println(next); //printing for test
}
}
System.out.println("done");
}
[Updated on: Mon, 16 September 2013 14:14] Report message to a moderator
|
|
|
Re: (Pivot) Parsing OCL Document complementing a UML model [message #1098562 is a reply to message #1098370] |
Sat, 31 August 2013 08:59 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
HI<br>
<br>
It is much easier if you supply a zipped project. You save me 5 to
15 minutes recreating what you already have. You also avoid me
making incorrect assumptions about how you have configured your
dependencies.<br>
<br>
I cannot find anything resembling "Using a UML model instead of an
Ecore one" in the Juno documentation.<br>
<br>
You are using file URIs. Never use these with EMF except for final
export that will never be used another Eclipse tool.<br>
<br>
You will see that at the bottom of the example it says:<br>
<br>
<i>The source for these examples may be found in the
org.eclipse.ocl.examples.xtext.tests plugin in
model/parsingDocumentsExample.ocl and in
src/org/eclipse/ocl/examples/test/xtext/PivotDocumentationExamples.java.<br>
</i><br>
The referenced file provides code that really works and is part of a
JUnit test suite, so it is regularly tested. When each new release
documentation is produced, I can check whether
PivotDocumentationExamples.java got refactored during the year and
update the documentation accordingly. So again it really works.<br>
<br>
I suggest you look at the working example to learn how to get your
URIs right.<br>
<br>
Since you're using StandaloneProjectMap,
URI.createPlatformResourceURI("/myProject/model/project.ocl") might
be good.<br>
<br>
Regards<br>
<br>
Ed Willink<br>
<br>
On 31/08/2013 02:28, John Guerson wrote:
<blockquote cite="mid:kvrgsm$3gh$1@xxxxxxxxe.org" type="cite">
<pre wrap="">Hi,
I was trying to replicate the tutorial: Parsing OCL Documents - Pivot Guide - Juno
Using a UML model instead of an Ecore one.
<a class="moz-txt-link-freetext" href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FCompleteOCLTutorial.html">http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FCompleteOCLTutorial.html</a>
However, I'm unable to get it running.
It seems that the EObject returned in the iteration over "pivotResource.getAllContents()" isn't an "ocl.examples.pivot.Constraint".
I would really appreciate any help!
Here is my code: (models attached)
Best Regards!
public static void main(String[]args)
{
String oclPath = "C:\\Users\\John\\myProject\\model\\project.ocl";
URI oclURI = URI.createFileURI(oclPath);
String umlPath = "C:\\Users\\John\\myProject\\model\\project.uml";
URI umlURI = URI.createFileURI(umlPath);
ResourceSet resourceSet = new ResourceSetImpl();
// ==== Configurations ===
OCLstdlib.install();
org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup.doSetup();
org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup.doSetup();
org.eclipse.ocl.examples.xtext.oclstdlib.OCLstdlibStandaloneSetup.doSetup();
UMLResourcesUtil.init(resourceSet);
org.eclipse.ocl.examples.pivot.uml.UML2Pivot.initialize(resourceSet);
OCL.initialize(resourceSet);
org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.getAdapter(resourceSet);
org.eclipse.ocl.examples.pivot.delegate.OCLDelegateDomain.initialize(resourceSet);
// === Loading UML Model to Resource ===
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE
);
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
Resource umlResource = resourceSet.getResource(umlURI,true);
org.eclipse.uml2.uml.Package umlmodel = (org.eclipse.uml2.uml.Package) umlResource.getContents().get(0);
umlResource.getResourceSet().getPackageRegistry().put(null,umlmodel);
// ==== Parsing OCL ====
PivotEnvironmentFactory environmentFactory = new PivotEnvironmentFactory(
umlResource.getResourceSet().getPackageRegistry(), null);
OCL ocl = OCL.newInstance(environmentFactory);
Resource pivotResource = ocl.parse(oclURI);
// ==== Printing ====
for(TreeIterator<EObject> tit = pivotResource.getAllContents(); tit.hasNext();){
EObject next = tit.next();
System.out.println(next); // printing for test
if(next instanceof Constraint){
System.out.println(next); //printing for test
}
}
System.out.println("done");
}
</pre>
</blockquote>
<br>
</body>
</html>
|
|
|
Powered by
FUDForum. Page generated in 0.01977 seconds