Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » model instance retrieval with ref to schema?
model instance retrieval with ref to schema? [message #41977] Fri, 15 February 2008 14:49 Go to next message
Eclipse User
Originally posted by: hsulos.gmail.com

Hi,

We are looking at code generation from an instance of a model. We have
the model schema in ecore and an instance html based on the model schema.
Using JET2 transformation, both the ecore and instance html can be loaded
easily in the template, and I can access in each file independently using
xpath but how do I retrieve the elements in the model instance with
reference back to the schema?

-Sandra
Re: model instance retrieval with ref to schema? [message #42134 is a reply to message #41977] Fri, 22 February 2008 08:36 Go to previous message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Sandra:

I'm not sure I understand the question. Are you asking how to find a the
type of an object selected by an XPath expression?

If so, then, out-of-the-box, JET doesn't do it (XPath is a particularly
metadata unaware language). But, with the creation of a few custom XPath
functions, I think you could bridge the gap. The first one that comes to
mind is a function to get the eClass of an object. You'd have to define this
function in a plug-in, and install it in the workbench you want to run.

Here's the declaration for plugin.xml:

<plugin>
<extension
point="org.eclipse.jet.xpathFunctions">
<function
implementation="org.eclipse.jet.examples.functions.EClassFunction "
maxArgs="1"
minArgs="1"
name="eClass">
</function>
</extension>

</plugin>

And here's the actual function:

/*********************************************************** ********************
* 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.jet.xpath.NodeSet;import org.eclipse.jet.xpath.XPathFunction;/** * Implement an XPath function that returns the EClass of an object (if itis an EObject). * */public class EClassFunction 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; } return object instanceof EObject ? ((EObject)object).eClass() : null; }}You'd it returns the actual EClass instance (which the XPath engine canhandle). Some examples:<c:get select="eClass($someObject)/@name"/> returns the eClassName<c:get select="eClass(eClass($someObject))/@name"/> returns EClass assumingsomeObject is an EObject.Good luck,Paul"Sandra" <hsulos@gmail.com> wrote in messagenews:c2aa1559e2dd9d88ecf60d232e1109b9$1@www.eclipse.org...> Hi,>> We are looking at code generation from an instance of a model. We havethe model schema in ecore and an instance html based on the model schema.Using JET2 transformation, both the ecore and instance html can be loadedeasily in the template, and I can access in each file independently usingxpath but how do I retrieve the elements in the model instance withreference back to the schema?> -Sandra
Previous Topic:How to test an element specified in the input xml or not?
Next Topic:Re: Obtaing Value
Goto Forum:
  


Current Time: Fri Aug 01 02:04:55 EDT 2014

Powered by FUDForum. Page generated in 0.09412 seconds