Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Accessing References inside model element
Accessing References inside model element [message #1080752] Tue, 06 August 2013 10:43 Go to next message
bim boh is currently offline bim bohFriend
Messages: 11
Registered: July 2013
Junior Member
Hello ,

I have a question, Not sure if its the right forum to post.I have a Metamodel like this,
1.
Report1:
Element ----> EObject
0..*

Now I can create a model element of this.

- I need to access this element and store it inside another model element (2) which is displayed at bottom.
2.
Report2:
newElement --> EObject
1
anotherElement : EString


Currently I am trying to do the following way in the code :

List<Report2> parse(Report1 r1) {

List<Report2> rep2elements = new ArrayList<Report2>();
List<EObject> parsedElement;
pE = r1.Element();

Report2 rep2element;
for (i=0; i<pE.size();i++){
   rep2element = reportFactoryImpl.eINSTANCE.createReport2();
   // I can get the values contained inside report1  as a string
    rep2element.setAnotherElement(pE.get(i).getClass().toString());
    rep2elements.add(rep2element);   
}
  return rep2elements;
}


Now i need to get the element inside report1 as a reference inside my report2 :

i tried something like this but it does not work.

rep2element.setnewElement((EObject)affectedElements.get(i));

Any suggestions.
Re: Accessing References inside model element [message #1080762 is a reply to message #1080752] Tue, 06 August 2013 10:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Comments below.

On 06/08/2013 12:43 PM, bim boh wrote:
> Hello ,
>
> I have a question, Not sure if its the right forum to post.I have a
> Metamodel like this,
> 1. Report1:
> Element ----> EObject
> 0..*
>
> Now I can create a model element of this.
>
> - I need to access this element and store it inside another model
> element (2) which is displayed at bottom.
> 2.
> Report2:
> newElement --> EObject
> 1
> anotherElement : EString
>
>
> Currently I am trying to do the following way in the code :
>
>
> List<Report2> parse(Report1 r1) {
>
> List<Report2> rep2elements = new ArrayList<Report2>();
> List<EObject> parsedElement;
> pE = r1.Element();
Is this real code? Isn't it r1.getElement()?
>
> Report2 rep2element;
> for (i=0; i<pE.size();i++){
> rep2element = reportFactoryImpl.eINSTANCE.createReport2();
eINSTANCE is declared on reportFactory, so why access it via the
implementation class of the factor? Did you make the Model Prefix
"report" rather than "Report"? That's a bad idea given that Java naming
conventions dictates that class names should start with an upper case
letter...
> // I can get the values contained inside report1 as a string
> rep2element.setAnotherElement(pE.get(i).getClass().toString());
> rep2elements.add(rep2element); }
> return rep2elements;
> }
>
>
> Now i need to get the element inside report1 as a reference inside my
> report2 :
>
> i tried something like this but it does not work.
>
> rep2element.setnewElement((EObject)affectedElements.get(i));
Where does affectedElements come from? Wouldn't you just do
rep2element.setNewElement(pE.get(i)) inside the loop of your
parse(Report1) method?
>
> Any suggestions.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Accessing References inside model element [message #1080770 is a reply to message #1080762] Tue, 06 August 2013 11:03 Go to previous messageGo to next message
bim boh is currently offline bim bohFriend
Messages: 11
Registered: July 2013
Junior Member
Sorry there where couple of typo's ,

rep2element = ReportFactoryImpl.eINSTANCE.createReport2();

The model prefix is in uppercase.

Regarding the second

rep2element.setNewElement(pE.get(i)) ( i tried to do this way as well )

The problem is i have many metamodels which have many Eobjects inside my project. I re-coded to just give an example of the thing i am trying.
Now, after each execution it is not getting me the Eobject(xyz) that i have need from report1. It will give me an Eobject but a different one from my metamodel.
Re: Accessing References inside model element [message #1080787 is a reply to message #1080770] Tue, 06 August 2013 11:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Comments below.

On 06/08/2013 1:03 PM, bim boh wrote:
> Sorry there where couple of typo's ,
So, please copy and paste actual code that compiles without errors, so
I'm not wasting my time looking at typos.
> rep2element = ReportFactoryImpl.eINSTANCE.createReport2();
>
> The model prefix is in uppercase.
>
> Regarding the second
>
> rep2element.setNewElement(pE.get(i)) ( i tried to do this way as well )
>
> The problem is i have many metamodels which have many Eobjects inside
> my project. I re-coded to just give an example of the thing i am
> trying. Now, after each execution it is not getting me the
> Eobject(xyz) that i have need from report1. It will give me an Eobject
> but a different one from my metamodel.
How can I make sense of what you're doing from such a sentence? Any one
of a thousand things could be wrong for all I know from this...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Accessing References inside model element [message #1081593 is a reply to message #1080787] Wed, 07 August 2013 12:31 Go to previous message
bim boh is currently offline bim bohFriend
Messages: 11
Registered: July 2013
Junior Member
Ed, Thanks.

There is some issue internally and when I tried to debug I realized this. Data coming into it is a wrong data.

Thanks for your guidance.

Next time will make sure there aren't any typo's. Smile
Previous Topic:EMF and XML: list serialization
Next Topic:Deserialization issue if attribute value is higher than 8000 characters
Goto Forum:
  


Current Time: Fri Apr 26 13:18:24 GMT 2024

Powered by FUDForum. Page generated in 0.03241 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top