Home » Modeling » M2T (model-to-text transformation) » [JET2] - Is there a way to check if a variable has been defined
| |
Re: [JET2] - Is there a way to check if a variable has been defined [message #18336 is a reply to message #18284] |
Fri, 01 June 2007 09:55   |
Eclipse User |
|
|
|
Originally posted by: evaandoli.dodo.com.au
I had a go at creating the new function wit the extention point but I'm
getting the following when I launch to test:-
Plug-in "Jet.Custom" was unable to instantiate class
"jetcustom.IsDefinedFunction".
The following is my MANIFEST.MF, Plugin.xml and Buld.properties:-
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Custom Plug-in
Bundle-SymbolicName: Jet.Custom;singleton:=true
Bundle-Version: 1.0.0
Require-Bundle: org.eclipse.jet
Export-Package: jetcustom;uses:="org.eclipse.jet.xpath"
Eclipse-LazyStart: false
Plugin.xml
========
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension
point="org.eclipse.jet.xpathFunctions">
<function
implementation="jetcustom.IsDefinedFunction"
maxArgs="1"
minArgs="1"
name="isDefined">
</function>
</extension>
</plugin>
build.properties
============
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
..,\
plugin.xml
Java Class:-
package jetcustom;
import java.util.List;
import org.eclipse.jet.xpath.Context;
import org.eclipse.jet.xpath.XPathFunction;
import org.eclipse.jet.xpath.XPathFunctionMetaData;
import org.eclipse.jet.xpath.XPathFunctionWithContext;
import org.eclipse.jet.xpath.XPathUtil;
public class IsDefinedFunction implements XPathFunctionWithContext {
public static final XPathFunctionMetaData FUNCTION_META_DATA = new
XPathFunctionMetaData(
"isDefined", null, (XPathFunction) new IsDefinedFunction(), 1, 1);
//$NON-NLS-1$
/**
*
*/
public IsDefinedFunction() {
super();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jet.xpath.XPathFunction#evaluate(java.util.List)
*/
@SuppressWarnings("unchecked")
public boolean evaluate(List args) {
String varName = XPathUtil.xpathString(args.get(0));
return currentContext.getVariableResolver().resolveVariable(varName ) !=
null;
}
Context currentContext;
public void setContext(Context aContext) {
currentContext = aContext;
}
}
"Paul Elder" <pelder@ca.ibm.com> wrote in message
news:f3mh7r$es2$1@build.eclipse.org...
> Stu:
>
> Sadly, there is no predefined function. You have a number of choices:
>
> 1) Write the following Java scriptlet:
>
> <% if(context.hasVariable("...name without $...")) { %>
> ...
> <% } %>
>
> 2) Write a isDefined XPath function.
>
> a) Create a plug-in, add a depencency on org.eclipse.jet. Create an
> extension on org.eclipse.jet.xpathFunctions
> b) Define your function in the extension: it would have min/max arguments
> of 1
> c) In the function class, add an
> org.eclipse.jet.xpath.XPathFunctionWithContext - this creates a method
> setContext() with delivers the current XPath context object (from which
> you can extract variables). Save the passed context to an instance
> variable
> d) In the function class's evaluate method, write something like:
>
> String varName = XPathUtil.xpathString(args.get(0));
> return context.getVariableResolver().resolveVariable(varName) != null;
>
> Of course, if you write such a function, why not submit a bugzilla
> enhancement, and contribute it back to JET :-)
>
> Paul
>
|
|
| | | | | | | | | | |
Re: [JET2] - Is there a way to check if a variable has been defined [message #25003 is a reply to message #24860] |
Wed, 04 July 2007 11:14   |
Eclipse User |
|
|
|
Tex:
I can image two possibilities:
1) You added the XPath function to JET transformation plug-in.
Unfortunately, this appears to be a bug in the dynamic loading of JET
transformation projects from the workspace:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=195397
Possible work arounds:
a) Define the function in a separate plug-in, and install it into your
development workbench
b) Test the JET transformation from a runtime workbench in which the JET
transformation is included.
2) You already have defined the Xpath function is a separate plug-in
project, but that project is in your workspace. JET will load a JET
transformation plug-in from the workspace, but it will not load any
dependent plug-ins. In this case, you could use either of the above work
arounds.
Paul
"Tex Twil" <chaljan@hotmail.com> wrote in message
news:f6fmi8$u5k$1@build.eclipse.org...
> Hi,
> I added an extension point as explained in this enhancement i.e.
> - define the class IsVarDefinedFunction in the JET project
> - add the extension to the plugin.xml referencing this class
>
> Everything seems ok, but JET keeps saying "Error: Unknown function name:
> isVarDefined " during execution. What did I do wrong ?
>
> Tex.
>
> Paul Elder wrote:
>> Tex:
>>
>> JET 0.8.0 is in the final moments of shut down. I am just now starting to
>> the plan the next release.
>>
>> In the meantime, the enhancement request is recorded in bugzilla 190650
>> (https://bugs.eclipse.org/bugs/show_bug.cgi?id=190650), complete with a
>> proposed implementation.
>>
>> Paul
>>
>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>> news:c6c9dcd5d447f981213f3a98af862c33$1@www.eclipse.org...
>>> Hi,
>>> where can I get this enhancement ?
>>>
>>> Tex.
>>>
>>
|
|
|
Re: [JET2] - Is there a way to check if a variable has been defined [message #25044 is a reply to message #25003] |
Wed, 04 July 2007 11:34  |
Eclipse User |
|
|
|
Ok, thank you, I will try.
Paul Elder wrote:
> Tex:
>
> I can image two possibilities:
>
> 1) You added the XPath function to JET transformation plug-in.
> Unfortunately, this appears to be a bug in the dynamic loading of JET
> transformation projects from the workspace:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=195397
>
> Possible work arounds:
> a) Define the function in a separate plug-in, and install it into your
> development workbench
>
> b) Test the JET transformation from a runtime workbench in which the JET
> transformation is included.
>
>
> 2) You already have defined the Xpath function is a separate plug-in
> project, but that project is in your workspace. JET will load a JET
> transformation plug-in from the workspace, but it will not load any
> dependent plug-ins. In this case, you could use either of the above work
> arounds.
>
> Paul
>
> "Tex Twil" <chaljan@hotmail.com> wrote in message
> news:f6fmi8$u5k$1@build.eclipse.org...
>> Hi,
>> I added an extension point as explained in this enhancement i.e.
>> - define the class IsVarDefinedFunction in the JET project
>> - add the extension to the plugin.xml referencing this class
>>
>> Everything seems ok, but JET keeps saying "Error: Unknown function name:
>> isVarDefined " during execution. What did I do wrong ?
>>
>> Tex.
>>
>> Paul Elder wrote:
>>> Tex:
>>>
>>> JET 0.8.0 is in the final moments of shut down. I am just now starting to
>>> the plan the next release.
>>>
>>> In the meantime, the enhancement request is recorded in bugzilla 190650
>>> (https://bugs.eclipse.org/bugs/show_bug.cgi?id=190650), complete with a
>>> proposed implementation.
>>>
>>> Paul
>>>
>>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>>> news:c6c9dcd5d447f981213f3a98af862c33$1@www.eclipse.org...
>>>> Hi,
>>>> where can I get this enhancement ?
>>>>
>>>> Tex.
>>>>
>
|
|
|
Goto Forum:
Current Time: Sun May 11 18:09:35 EDT 2025
Powered by FUDForum. Page generated in 0.03957 seconds
|