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 09:49  |
Eclipse User |
|
|
|
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 10:02] by 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 16:33   |
Eclipse User |
|
|
|
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 16:39] by 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 05:01   |
Eclipse User |
|
|
|
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
|
|
| | | |
Re: Ecore element related to a Pivot typed element [message #1115274 is a reply to message #1114984] |
Mon, 23 September 2013 19:11  |
Eclipse User |
|
|
|
Hi
Your comments make no sense to me. You seem to be confusing metalevels.
The Ecore/UML to Pivot conversions occur to normalize the metamodel
representations. Your models are a different issue.
Regards
Ed Willink
On 23/09/2013 09:58, John Guerson wrote:
> Hi,
>
> I just forgot to add getContext() after the constraint, sorry for
> that. But, here is the doubt:
>
> I transform a custom model into Ecore programatically saving a
> Map<CustomObject,EObject> which has all the mappings of my custom
> transformation.
> These objects returned from getEcoreOfPivot() seems not to be those in
> the transformation Map above. That's my real question. I thought that
> getETarget() and getEcoreOfPivot() would get me those exact same
> objects, but getETarget is returning null and the object returned by
> getEcoreOfPivot() seems to be different from those.
> Regards
> John
>
>
|
|
|
Goto Forum:
Current Time: Tue Jul 22 22:40:09 EDT 2025
Powered by FUDForum. Page generated in 0.29680 seconds
|