Search code examples
javaeclipseeclipse-rcpemf

Eclipse EMF - Is there a way to reference a class that is part of a model in a different eclipse plugin without having to store the tostring()?


one of the classes in an eclipse plugin model needs to reference another class in a totally different model and plugin.

To do so, I found this thread, that suggests using an edatatype and initialize its instance class with the type I need to link to. However, when I tried to link to my class in a different model, it saves the tostring of the class like in the following example

<tasks description="" id="p1.tsk4" label="1" type="place" time="10">
  <requiredCapabilityDescriptor>cod.gen.impl.CapabilityDescriptorImpl@78483404 (description: , id: cap2, label: ) (parent: null)</requiredCapabilityDescriptor>
  <involvedResource>cod.gen.impl.ResourceDescriptorImpl@2839ac4c (description: null, id: null, label: null) (cad: null, material: null, pointySurface: &lt;unset>, sharpEdges: &lt;unset>, thumbnail: null, weight: &lt;unset>) (changeCost: null, generic: &lt;unset>, investCost: null, manufacturer: null)</involvedResource>
</tasks>

in this example I am linking to two different external classes CapabilityDescriptorImpl and ResourceDescriptorImpl. As you can see the tostring is stored which is inconvenient in terms of storage and readability, also I am not so sure about the consistency handling in such case (I mean deleting, editing of the referenced instance). According to the thread the tostring is written because I chose the data type to be serializable, I have tried making it non serializable, but that did not work .

So I have tried another approach using an eReference, which minimised the string to save to become

<tasks description="" id="p1.tsk4" label="1" type="place" time="10">
 <requiredCapabilityDescriptor xsi:type="CoD:CapabilityDescriptor" description="" id="cap2" label=""/>
  <involvedResource xsi:type="CoD:ResourceDescriptor"/>
</tasks>

which is much better in terms of readability and storage, but I really doubt it is an actual reference it does not contain any thing that can refer to the original instance. Actually I am sure it is not referring to the original object as it does not show any econtainer. And again with the consistency issues.

My last option -that I can think of- is storing the URI of the referenced object but in this case I will have to manage all the consistency issues myself.

So my question is "is there a better way to achieve this external class referencing?"


Solution

  • Inspired by Generating an Extended EMF Model. I have done the following:

    1. First I put all the separate model files into packages of one of the model files.
    2. Exported the genmodel to separate xsds for each package.
    3. Made sure that the import tag in every xsd file point to a valid URL of xsd to the imported model.
    4. Distributed the xsd files across my plugins.
    5. On creation of the genmodel in each plugin I just referenced the genmodel of the imported model (must generate the genmodels in the same sequence of import, the one model that does not import any first and then the ones depending only on it and so on)
    6. Now use a reference to point to classes in different models normally.

    This created an xmI file that looks like

     <c xmlns:c="platform:/resource/my_project/Resource/c.xsd">
      <c:res C:id="r" C:label="r">
        <C:des>My.des#//@rDes.0</C:des>
      </C:resources>
    </C:c>
    

    that points to another XMI file named My.des