eclipse-ocl / org.eclipse.ocl

Eclipse Public License 2.0
0 stars 0 forks source link

[Pivot] Improve MetaModelManager API usage or fix implementations #1199

Open eclipse-ocl-bot opened 3 weeks ago

eclipse-ocl-bot commented 3 weeks ago

| --- | --- | | Bugzilla Link | 417419 | | Status | NEW | | Importance | P3 normal | | Reported | Sep 17, 2013 08:17 EDT | | Modified | Feb 19, 2017 14:29 EDT | | Depends on | 512403 | | Reporter | Adolfo Sanchez-Barbudo Herrera |

Description

While working with the metamodel manager API, I've found inconsistencies while trying to obtain an instance of it.

With the aim of obtaining the metamodel manager to register a GenModel, I've tried two different ways to do so:

a) Way 1:\ MetaModelManager mManager = MetamodelManager.getAdapter(resourceSet);\ mManager.addGenModel(genModel);

b) Way 2:\ MetaModelManager mManager = PivotUtil.getMetamodelManager(genModel.eResource());\ mManager.addGenModel(genModel);

Providing that the resource of the genModel in scenario b) has been loaded in the same resourceSet used in the scenario a) I'd expect the same behaviour for every use case, regardless the way we use existing API to obtain the metamodel manager. However, in the context of the AutoCodeGenerator b) works, whereas the I get some exceptions[1] when using a).

Two options:

  1. Align implementations so that the same steps (registrations, etc.) are done while using API in both ways. Also take into account that a resourceSet is a container of resources (Does make sense that a orphan Resource exists with its own metamodel manager ?, Does make sense that the different resources of the same resourceSet have different metamodel managers ? when getting the adapter from a resource should not try to look up the adapter in the resourceSet ?)
  2. Deprecate API usage of a) in favor of the b) ?
  3. Clarify API documentation to understand why they behaves different and how to properly use it.\ \ Note that I've not studied the implementations, I'm simply describing the issue I've found.

[1] java.lang.RuntimeException: Problems running workflow GenerateAutoCSModels: No registration for content type 'org.eclipse.ocl.examples.oclas.ecore'\ at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:104)\ at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)\ at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)\ at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)\ at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)\ Caused by: java.lang.IllegalStateException: No registration for content type 'org.eclipse.ocl.examples.oclas.ecore'\ at org.eclipse.ocl.examples.pivot.manager.MetaModelManager.getResource(MetaModelManager.java:2060)\ at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.importObjects(Ecore2Pivot.java:406)\ at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.getPivotRoot(Ecore2Pivot.java:374)\ at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.getPivotOfEcore(Ecore2Pivot.java:299)\ at org.eclipse.ocl.examples.pivot.ecore.Ecore2Pivot.getCreated(Ecore2Pivot.java:281)\ at org.eclipse.ocl.examples.pivot.manager.MetaModelManager.getPivotOfEcore(MetaModelManager.java:1863)\ at org.eclipse.ocl.examples.autogen.java.AutoCodeGenerator.generate(AutoCodeGenerator.java:124)\ at org.eclipse.ocl.examples.build.xtend.GenerateAutoCS2ASVisitors.generateVisitors(GenerateAutoCS2ASVisitors.java:32)\ at org.eclipse.ocl.examples.build.xtend.GenerateVisitorsWorkflowComponent.invokeInternal(GenerateVisitorsWorkflowComponent.java:257)\ at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)\ at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)\ at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)\ at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)\ at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)\ at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)\ at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102) ... 4 more

eclipse-ocl-bot commented 3 weeks ago

By Ed Willink on Sep 17, 2013 08:59

PivotUtil.getMetamodelManager is the preferred way.

NB Not all resources are in a useful ResourceSet.

eclipse-ocl-bot commented 3 weeks ago

By Adolfo Sanchez-Barbudo Herrera on Sep 19, 2013 07:18

More information after further investigation.

The exception comes from using a MetaModelManager which was initialized before the proper registrations (e.g. via EssentialOCLStandaloneSetup.doSetup();) were made in standalone executions (i.e MWE scripts). In the two situations (ways) I explained above, different metamodel managers were used and initialized at different times, and therefore the different behaveor.

Regarding MetamodelManager retrieval. As commented, we have:

a) PivotUtil.getMetamodelManager(Resource)\ b) MetamodelManager.getAdapter(ResourceSet)\ \ Indeed, a) retrieves a per-resource metamodel manager, so that if we try to obtain it using two different resources, even though they belong to the same ResourceSet, we obtain two different metamodel managers.

However, I found quite interesting b) because once the adapter is installed at ResourceSet level, using a) with any resource which belongs to it, the same metamodel manager is obtained, which is very convenient.

Now, the main question here is if it makes sense having two different Resources which belong to the same ResourceSet be associated to two different metamodel managers. This might occur if a) is used with different resources (belonging to the same ResourceSet) and b) has not been done before (with the containing ResourceSet).

a) Yes. The implementation seems to be fine. Maybe the documentation needs to be improved to explain these conclusions, and maybe an additional PivotUtil.getMetamodelManager(ResourceSet rSet) could be useful, to always use the PivotUtil when trying to obtain a metamodel manager.

b) No. The implementation could be slightly changed so every time a) is used, and the resource is contained in a ResourceSet it firstly try to get an adapter from the containing ResourceSet (via b) ), so that a per-resource metamodel-manager only makes sense when they are orphan resources (they don't belong to any ResourceSet).

I think that only the impact to be considered is what happens when moving out/in resources from a ResourceSet (which is not common practice by the way).

Regards,\ Adolfo.

eclipse-ocl-bot commented 3 weeks ago

By Ed Willink on Sep 19, 2013 07:38

Potentially two different applications (with distinct ResourceSets and distinct MetaModelManagers) may share the same Resource.

For ASResources such as OCLstdlib or OCLMetaModel finding an ASResource adapter is not adequate; could be someone else. Not all ASResources are even in ResourceSets.

For CSResources, there should be only one editor active so the CSResource adapter can be trusted.

The PivotUtil.getMetaModelManager routines appeared after I got fed up with writing similar but unjustifiably different code in many places. Their divergence has been decreasing, but a further analysis is probably useful.