Skip to main content

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

Martin,

The root of the object is "project".  Should the XPath look like this?:
"//project/@sheets/@sheet[id=sheet1074095906796]/@properties"

Russell J. Nile


                                                                                                                            
              Martin Zdila <zdila@xxxxxxxx>                                                                                 
                                                          To:                                         Frank Budinsky        
              Sent by: emf-dev-admin@xxxxxxxxxxx           <emf-dev@xxxxxxxxxxx>                                            
                                                          cc: l.fasianok@xxxxxxxxxxxxxxx                                    
                                                          Subject:   Re[2]: [emf-dev] searching the object by id            
                                                                                                                            
              Wednesday January 14, 2004 11:35 AM                                                                           
              Please respond to emf-dev                                                                                     
                                                                                                                            
                                                                                                                            




Hello Frank

Sorry that I write here again (and I'll write to newsgroup too), but I
need to solve this problem as soon as possible. So I am asking for
help wherever I can.

Thanks for your useful reply. I've read the chapter 13, but although
I've found there lot of useful information, it has not helped me
solving my problem.

In that book is written that getURIFragment() uses XML-path like
locator. But it seems to be a little different to a W3C XPath, because
instead of node[0] there is @node.0 etc. And the locator written in
the following code is not working:

Java code:
==========
Resource resource = new XMLResourceImpl(URI.createURI(fileName));
XMLResource.XMLMap xmlMap = new XMLMapImpl();
xmlMap.setNoNamespacePackage(ProjectPackage.eINSTANCE);
Map options = new HashMap();
options.put(XMLResource.OPTION_XML_MAP, xmlMap);
resource.load(options);

Project project = (Project) resource.getContents().get(0);
Sheet s = (Sheet) project.getSheets().getSheet().get(0);

// this will print:
// //@sheets/@sheet.0/@properties
System.out.println(resource.getURIFragment(s.getProperties()));

// returns the 's' object
Object o1 = resource.getEObject("//@sheets/@sheet.0/@properties");

// this throws an exception :-( (instead of returning the 's' object)
Object o2 = resource.getEObject
("//@sheets/@sheet[id=sheet1074095906796]/@properties");

XML file:
=========
<?xml version="1.0" encoding="UTF-8"?>
<project id="String" version="String">
  <sheets>
    <sheet id="sheet1074095906796">
      <properties>
        <print/>
        <name>New Sheet</name>
      </properties>
      <panels/>
    </sheet>
    <sheet id="sheet1074095906797">
      <properties>
        <print/>
        <name>New Sheet</name>
      </properties>
      <panels/>
    </sheet>
  </sheets>
</project>


Please help me, how can I solve this problem. I don't want to iterate
through the list of object, because there will be lot of nested lists.

And before I've read about getEObject() method, I've used
org.apache.commons.beanutils.PropertyUtils.getProperty():

Sheet s = (Sheet) PropertyUtils.getProperty(project,
      "sheets.sheet[0].properties.name");

This works exactly like that XPath-like selection - it uses only index
parameters too (sheet[0]).

2. Question: which of those two methots are more effective?

Thanks in advance

--
Best regards

Ing. 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



Dňa 14. januára 2004, 14:53, Frank Budinsky napísal:





FB> Martin,

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

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

FB> Frank.





FB>                       Martin Zdila
FB>                       <zdila@xxxxxxxx>         To:
FB> emf-dev@xxxxxxxxxxx
FB>                       Sent by:                 cc:
FB> l.fasianok@xxxxxxxxxxxxxxx
FB>                       emf-dev-admin@ecl        Subject:
FB> [emf-dev] searching the object by id
FB>                       ipse.org


FB>                       01/14/2004 05:49
FB>                       AM
FB>                       Please respond to
FB>                       emf-dev





FB> Hello

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

FB> Suppose, I have a XML file:

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

FB> I am possile to get the correct SomeItem object:

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

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

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

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

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

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

FB> --
FB> Thanks in advance

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

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



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

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






Back to the top