Home » Modeling » OCL » Visiting OCL: Getting the Ecore element related to a Pivot typed element
Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1110181] |
Mon, 16 September 2013 13:49 |
John Guerson Messages: 51 Registered: August 2011 |
Member |
|
|
Hi everyone,
In the context of visiting a pivot constraint (extending AbstractExtendingVisitor),
Is there a way to get the Ecore model element related to a pivot typed element?
More specifically, how can I get the Ecore element related to a context (Constraint.getContext():NamedElement)?
I guess there's probably a Map somewhere containing the mapping from Ecore to Pivot.
I already tried Ecore2Pivot.getAdapter() and then getCreated() but the Pivot elements seems to be different from those in the visitor.
Thanks a lot
John
[Updated on: Mon, 16 September 2013 14:02] Report message to a moderator
|
|
| |
Re: Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1112593 is a reply to message #1110181] |
Thu, 19 September 2013 23:17 |
John Guerson Messages: 51 Registered: August 2011 |
Member |
|
|
Hi Edward,
The method getETarget() is returning null no matter what I do...
So if you could, please, take a look in my project (attached below) I would really appreciate.
The MetaModelManager.getEcoreOfPivot() doesn't exists in Juno (which is not the SR1 or SR2 version) (I need this running in Juno for the sake of compatibility with other custom libraries). So, I am trying with getETarget() in Juno.
I was also trying to run it in Kepler (using the getEcoreOfPivot()) but it seems that beacause getETarget() returns null, the method getEcoreOfPivot() creates another Ecore elements that are not the same as the original ecore ones. This is true?
I am probably doing something wrong, but so far I do not know what else I can do.
Thanks a lot,
John
[Updated on: Fri, 20 September 2013 20:11] Report message to a moderator
|
|
| |
Re: Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1113219 is a reply to message #1112869] |
Fri, 20 September 2013 20:33 |
John Guerson Messages: 51 Registered: August 2011 |
Member |
|
|
Hi,
I just tried with Kepler and Juno-SR2, using their plugins, and still got null's.
I also downloaded the OCL 4.2.0M1 and tried to replace them in Kepler, still didn't work.
The project attached above contains my code. To run it, you need only to import the project into your workspace. I know that you have little time to spend, so I really appreciate your attention.
I guess it could be something with the Ecore that I'm loading. My ecore model is generated by other custom library. I also ran tests with models from the sample ecore editor of eclipse and still got nulls.
Here is the main part of my code:
public PivotOCLTest (String oclPath, String ecorePath) throws IOException, ParserException
{
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();
EPackage ecoreRoot = readEcore(ecorePath);
OCL.initialize(ecoreRoot.eResource().getResourceSet());
MetaModelManager metamodelManager = new MetaModelManager();
PivotEnvironmentFactory pivotEnvFactory = new PivotEnvironmentFactory(
ecoreRoot.eResource().getResourceSet().getPackageRegistry(),
metamodelManager);
ocl = OCL.newInstance(pivotEnvFactory);
URI oclURI = URI.createFileURI(oclPath);
Resource pivotResource = ocl.parse(oclURI);
for (TreeIterator<EObject> tit = pivotResource.getAllContents(); tit.hasNext();){
EObject next = tit.next();
if (next instanceof Constraint){
Constraint constraint = (Constraint)next;
System.out.println("ETarget = "+constraint.getContext().getETarget()); //null???
}
}
and to read the ecore:
public static EPackage readEcore (String ecorePath)
{
URI ecoreURI = URI.createFileURI(ecorePath);
ResourceSet ecoreResourceSet = new ResourceSetImpl();
ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
new EcoreResourceFactoryImpl());
ecoreResourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
Resource ecoreResource = ecoreResourceSet.getResource(ecoreURI,true);
EPackage ecoremodel = (EPackage) ecoreResource.getContents().get(0);
ecoreResource.getResourceSet().getPackageRegistry().put(null,ecoremodel);
return ecoremodel;
}
and to run it:
/** Run a Test */
public static void main (String[] args)
{
String oclPath = "model/project.ocl";
String refPath = "model/project.ecore";
try {
new PivotOCLTest(oclPath,refPath);
System.out.println("OCL parsed.");
} catch (Exception e) {
e.printStackTrace();
}
}
Regards,
John
[Updated on: Fri, 20 September 2013 20:39] Report message to a moderator
|
|
|
Re: Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1113542 is a reply to message #1113219] |
Sat, 21 September 2013 09:01 |
Ed Willink Messages: 7678 Registered: July 2009 |
Senior Member |
|
|
HI
You attachment expects all the libraries to be in the "juno" folder, so
I would have to do a lot of repair to make it work and might repair your
problem by mistake.
Does it work as a normal standalone application? If not please provide
an attachment for that.
You can set up launch configurations for non-Eclipse apps too; see
/org.eclipse.ocl.ecore.tests/launches/org.eclipse.ocl.ecore.tests
(Standalone Classpath).launch for how to get Eclipse to work out many of
the dependencies for you.
Regards
Ed Willink
On 20/09/2013 21:33, John Guerson wrote:
> Hi,
>
> I just tried with Kepler and Juno-SR2, using their plugins, and still
> got null's.
> I also downloaded the OCL 4.2.0M1 and tried to replace them in Kepler,
> still didn't work.
> The project attached above contains my code. To run it, you need only
> to import the project into your workspace. I know that you have little
> time to spend, so I really appreciate your attention.
>
> I guess it could be something with the Ecore that I'm loading. My
> ecore model is generated by other custom library. I also ran tests
> with models from the sample ecore editor of eclipse and still got nulls.
>
> Here is the main part of my code:
>
>
>
> public PivotOCLTest (String oclPath, String ecorePath) throws
> IOException, ParserException
> {
> 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();
>
>
> EPackage ecoreRoot = readEcore(ecorePath);
> OCL.initialize(ecoreRoot.eResource().getResourceSet());
>
> MetaModelManager metamodelManager = new MetaModelManager();
> PivotEnvironmentFactory pivotEnvFactory = new PivotEnvironmentFactory(
> ecoreRoot.eResource().getResourceSet().getPackageRegistry(),
> metamodelManager);
> ocl = OCL.newInstance(pivotEnvFactory);
>
> URI oclURI = URI.createFileURI(oclPath); Resource
> pivotResource = ocl.parse(oclURI);
>
> for (TreeIterator<EObject> tit = pivotResource.getAllContents();
> tit.hasNext();){
> EObject next = tit.next();
> if (next instanceof Constraint){
> Constraint constraint = (Constraint)next;
> System.out.println("ETarget = "+constraint.getETarget());
> //null??? }
> }
>
>
> and to read the ecore:
>
>
> public static EPackage readEcore (String ecorePath)
> {
> URI ecoreURI = URI.createFileURI(ecorePath);
> ResourceSet ecoreResourceSet = new ResourceSetImpl();
>
>
> ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
> new EcoreResourceFactoryImpl());
> ecoreResourceSet.getPackageRegistry().put(EcorePackage.eNS_URI,
> EcorePackage.eINSTANCE);
>
> Resource ecoreResource = ecoreResourceSet.getResource(ecoreURI,true);
> EPackage ecoremodel = (EPackage) ecoreResource.getContents().get(0);
>
> ecoreResource.getResourceSet().getPackageRegistry().put(null,ecoremodel);
>
> return ecoremodel;
> }
>
>
> and to run it:
>
>
> /** Run a Test */
> public static void main (String[] args)
> {
> String oclPath = "model/project.ocl";
> String refPath = "model/project.ecore";
>
> try {
> new PivotOCLTest(oclPath,refPath);
> System.out.println("OCL parsed.");
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
>
> Regards,
> John
|
|
| | | | |
Goto Forum:
Current Time: Sat Oct 19 16:01:56 GMT 2024
Powered by FUDForum. Page generated in 0.04645 seconds
|