Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Re: Obtaing Value
Re: Obtaing Value [message #42072] Thu, 21 February 2008 07:55 Go to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

Raphael,

Is this a question about JET? It's best to ask on the M2T newsgroup
about it. I've added it to the "to" list of this reply so Paul should
see it.


Raphael wrote:
> Hello my friends,
>
> I have the following XMI code:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Package xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmi:id="_L37e0NiWEdyDI-twlSn5BQ" >
> <ownedMember xmi:type="uml20:Classe" xmi:id="_NsTmgNiWEdyDI-twlSn5BQ"
> name="People" package="_L37e0NiWEdyDI-twlSn5BQ">
> </ownedMember>
> </Package>
>
> When I use the command <c:get select="Package/ownedMember/@name" /> I
> got the result: People
>
> But, IŽm trying to obtain the xmi:id from ownedMember. IŽm using the
> following command <c:get select="Package/ownedMember/@xmi:id" /> , but
> this return no value.
>
> Has anyone here know what command should I use?!?
>
> Thanks,
> Raphael
>
Re: Obtaing Value [message #42165 is a reply to message #42072] Fri, 22 February 2008 09:03 Go to previous message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Raphael:

You'll have to implement a custom XPath function to get the XMI ID - the
XPath engine doesn't know how to extract this directly, and the ID is not
reflected in the EMF-metadata.

The function is pretty simple. Here's its implementation:

/*********************************************************** ********************
* Copyright (c) 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* /
************************************************************ *******************/package org.eclipse.jet.examples.functions;import java.util.List;import org.eclipse.emf.ecore.EObject;import org.eclipse.emf.ecore.resource.Resource;import org.eclipse.emf.ecore.util.EcoreUtil;import org.eclipse.jet.xpath.NodeSet;import org.eclipse.jet.xpath.XPathFunction;/** * XPath function implementation that returns the EObject ID of an EObject.For * non-eObjects, it returns the empty string * */public class EObjectIDFunction implements XPathFunction { /* (non-Javadoc) * @see org.eclipse.jet.xpath.XPathFunction#evaluate(java.util.List) */ public Object evaluate(List args) { Object object = null; final Object objectArg = args.get(0); if(objectArg instanceof NodeSet) { NodeSet nodeSet = (NodeSet) objectArg; object = nodeSet.size() > 0 ? nodeSet.iterator().next() : null; } else { object = objectArg; } if(object instanceof EObject) { final EObject eObject = (EObject) object; final Resource resource = eObject.eResource(); return resource != null ? resource.getURIFragment(eObject) :EcoreUtil.getID(eObject); } else { return ""; } }}"Ed Merks" <merks@ca.ibm.com> wrote in messagenews:fpjsd6$crl$1@build.eclipse.org...> Raphael,>> Is this a question about JET? It's best to ask on the M2T newsgroup aboutit. I've added it to the "to" list of this reply so Paul should see it.>>> Raphael wrote:>> Hello my friends,>>>> I have the following XMI code:>>>> <?xml version="1.0" encoding="UTF-8"?>>> <Package xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"xmi:id="_L37e0NiWEdyDI-twlSn5BQ" >>> <ownedMember xmi:type="uml20:Classe" xmi:id="_NsTmgNiWEdyDI-twlSn5BQ"name="People" package="_L37e0NiWEdyDI-twlSn5BQ">>> </ownedMember>>> </Package>>>>> When I use the command <c:get select="Package/ownedMember/@name" /> I gotthe result: People>>>> But, I
Previous Topic:model instance retrieval with ref to schema?
Next Topic:simple JET2 example?
Goto Forum:
  


Current Time: Sun Apr 20 09:34:38 EDT 2014

Powered by FUDForum. Page generated in 0.01723 seconds