Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [emf-dev] searching the object by id



Martin,

Resource.getEObject() locates an object by URI fragment which can either be
a path or an ID. You can set ID's for objects using XMLResource.setID() or
you can set the isID attribute of a feature itself. This is all covered in
Chapter 13 of the EMF book.

You should ask this kind of question on the EMF newsgroup instead of here.
Actually, there have already been various discussions on the topic of IDs
there, which you should find helpful.

Frank.




                                                                                                                                          
                      Martin Zdila                                                                                                        
                      <zdila@xxxxxxxx>         To:       emf-dev@xxxxxxxxxxx                                                              
                      Sent by:                 cc:       l.fasianok@xxxxxxxxxxxxxxx                                                       
                      emf-dev-admin@ecl        Subject:  [emf-dev] searching the object by id                                             
                      ipse.org                                                                                                            
                                                                                                                                          
                                                                                                                                          
                      01/14/2004 05:49                                                                                                    
                      AM                                                                                                                  
                      Please respond to                                                                                                   
                      emf-dev                                                                                                             
                                                                                                                                          
                                                                                                                                          



Hello

I am using EMF for serialization / deserialization of data holding
objects into / from a XML file.

Suppose, I have a XML file:

<project>
      <someItem id='345' value='a' />
      <someItem id='666' value='b' />
      <someItem id='12' value='c' />
</project>

I am possile to get the correct SomeItem object:

Project project = (Project) resource.getContents().get(0);

Iterator iter = project.iterator();
while (iter.hasNext()) {
      SomeItem item = (SomeItem) iter.next();

      if (item.getId().equals("666")) {
         System.out.println("Found: value = " + item.getValue());
         break;
      }
}

My answer is: it is possible to find value of that item if I know the
id directly - something like this?:

Project project = (Project) resource.getContents().get(0);
SomeItem item = project.getItemById("666");
...

I al looking for a method like getItemById - can EMF generate one for
me - if yes, then how can I achieve this?
Has an id some special meaning or is it jus a normal attribute? I am
expecting that the id attribute has to be unique, of course.
Or is there (somewhere) some another method which helps me in to find that
item?

--
Thanks in advance

Martin Zdila
Developer
EpiSoftware Slovakia Ltd.
Prazska 4, 040 11  Kosice
cellular: +421 908 363 848
phone: +421 55 643 9954
fax: +421 55 643 9954
mailto:m.zdila@xxxxxxxxxxxxxxx
http://www.episoftware.com

_______________________________________________
emf-dev mailing list
emf-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/emf-dev





Back to the top