Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [JET2] - Is there a way to check if a variable has been defined
[JET2] - Is there a way to check if a variable has been defined [message #18233] Mon, 28 May 2007 11:54 Go to next message
Eclipse UserFriend
Originally posted by: evaandoli.dodo.com.au

Hi,
Im looking through the JET docs and Xpath spec and I can't find how to check
if a variable has been defined or not.
I'd like to use it in a <c:if test="isDefined($aVar)"> type idea.

Stu
Re: [JET2] - Is there a way to check if a variable has been defined [message #18284 is a reply to message #18233] Thu, 31 May 2007 09:05 Go to previous messageGo to next message
Eclipse UserFriend
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 #18336 is a reply to message #18284] Fri, 01 June 2007 09:55 Go to previous messageGo to next message
Eclipse UserFriend
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 #18353 is a reply to message #18336] Fri, 01 June 2007 11:25 Go to previous messageGo to next message
Eclipse UserFriend
Stu:

The message is coming from IConfigurationElement.createExecutableExtension

So, the good news is Eclise/OSGi has loaded your plug-in. In fact, it was
able to load your class, too. The error is happening when it
Class.newInstance is called. Unfortunately, the Eclipse code suppresses the
reason for the failure.

There are a couple of suggestions:

1) implement XPathFunction as well as XPathFunctionWithContext. Whether this
is the source of your problem or not, you'll need it.
(XPathFunctionWithContext is not a subinterface of XPathFunction - I can't
remember whether that was be design or not).

2) You don't need to declare the FUNCTION_META_DATA field. JET uses this on
standard XPath functions so that it can configure the XPath engine without
relying on Eclipse and extension points. (It is a little known fact that the
XPath engine is independent of Eclipse).

If all else fails, I suggest creating a JUnit plug-in (i.e, add a dependency
on JUnit), the then add a JUnit that simply does:

new IsDefinedFunction();

Whatever exeception is being thrown will be become clear.

Paul
Re: [JET2] - Is there a way to check if a variable has been defined [message #18415 is a reply to message #18353] Sat, 02 June 2007 01:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: evaandoli.dodo.com.au

You were right you need to implement XPathFunction as well.

I will try and submit the enhausement if you like.

To package this do you just export a jar ?
Haven't tried just asking.

Stu



"Paul Elder" <pelder@ca.ibm.com> wrote in message
news:f3pdr7$8mr$1@build.eclipse.org...
> Stu:
>
> The message is coming from IConfigurationElement.createExecutableExtension
>
> So, the good news is Eclise/OSGi has loaded your plug-in. In fact, it was
> able to load your class, too. The error is happening when it
> Class.newInstance is called. Unfortunately, the Eclipse code suppresses
> the reason for the failure.
>
> There are a couple of suggestions:
>
> 1) implement XPathFunction as well as XPathFunctionWithContext. Whether
> this is the source of your problem or not, you'll need it.
> (XPathFunctionWithContext is not a subinterface of XPathFunction - I can't
> remember whether that was be design or not).
>
> 2) You don't need to declare the FUNCTION_META_DATA field. JET uses this
> on standard XPath functions so that it can configure the XPath engine
> without relying on Eclipse and extension points. (It is a little known
> fact that the XPath engine is independent of Eclipse).
>
> If all else fails, I suggest creating a JUnit plug-in (i.e, add a
> dependency on JUnit), the then add a JUnit that simply does:
>
> new IsDefinedFunction();
>
> Whatever exeception is being thrown will be become clear.
>
> Paul
>
Re: [JET2] - Is there a way to check if a variable has been defined [message #19277 is a reply to message #18415] Sat, 02 June 2007 10:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: evaandoli.dodo.com.au

Submitted an enhausement and included the code / definitions used.
#190650

"Stu" <evaandoli@dodo.com.au> wrote in message
news:f3qv96$uas$1@build.eclipse.org...
> You were right you need to implement XPathFunction as well.
>
> I will try and submit the enhausement if you like.
>
> To package this do you just export a jar ?
> Haven't tried just asking.
>
> Stu
>
>
>
> "Paul Elder" <pelder@ca.ibm.com> wrote in message
> news:f3pdr7$8mr$1@build.eclipse.org...
>> Stu:
>>
>> The message is coming from
>> IConfigurationElement.createExecutableExtension
>>
>> So, the good news is Eclise/OSGi has loaded your plug-in. In fact, it was
>> able to load your class, too. The error is happening when it
>> Class.newInstance is called. Unfortunately, the Eclipse code suppresses
>> the reason for the failure.
>>
>> There are a couple of suggestions:
>>
>> 1) implement XPathFunction as well as XPathFunctionWithContext. Whether
>> this is the source of your problem or not, you'll need it.
>> (XPathFunctionWithContext is not a subinterface of XPathFunction - I
>> can't remember whether that was be design or not).
>>
>> 2) You don't need to declare the FUNCTION_META_DATA field. JET uses this
>> on standard XPath functions so that it can configure the XPath engine
>> without relying on Eclipse and extension points. (It is a little known
>> fact that the XPath engine is independent of Eclipse).
>>
>> If all else fails, I suggest creating a JUnit plug-in (i.e, add a
>> dependency on JUnit), the then add a JUnit that simply does:
>>
>> new IsDefinedFunction();
>>
>> Whatever exeception is being thrown will be become clear.
>>
>> Paul
>>
>
>
Re: [JET2] - Is there a way to check if a variable has been defined [message #19321 is a reply to message #18415] Sat, 02 June 2007 10:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: evaandoli.dodo.com.au

Ok to answer my own question - yes just export as plugin and its works fine
:-)

Shame the export function remembers the "last" exported plugin and not
settings for the project you have selected.
Is there a way to do this ?
Maybe not a question for here.

Stu

"Stu" <evaandoli@dodo.com.au> wrote in message
news:f3qv96$uas$1@build.eclipse.org...
> You were right you need to implement XPathFunction as well.
>
> I will try and submit the enhausement if you like.
>
> To package this do you just export a jar ?
> Haven't tried just asking.
>
> Stu
>
>
>
> "Paul Elder" <pelder@ca.ibm.com> wrote in message
> news:f3pdr7$8mr$1@build.eclipse.org...
>> Stu:
>>
>> The message is coming from
>> IConfigurationElement.createExecutableExtension
>>
>> So, the good news is Eclise/OSGi has loaded your plug-in. In fact, it was
>> able to load your class, too. The error is happening when it
>> Class.newInstance is called. Unfortunately, the Eclipse code suppresses
>> the reason for the failure.
>>
>> There are a couple of suggestions:
>>
>> 1) implement XPathFunction as well as XPathFunctionWithContext. Whether
>> this is the source of your problem or not, you'll need it.
>> (XPathFunctionWithContext is not a subinterface of XPathFunction - I
>> can't remember whether that was be design or not).
>>
>> 2) You don't need to declare the FUNCTION_META_DATA field. JET uses this
>> on standard XPath functions so that it can configure the XPath engine
>> without relying on Eclipse and extension points. (It is a little known
>> fact that the XPath engine is independent of Eclipse).
>>
>> If all else fails, I suggest creating a JUnit plug-in (i.e, add a
>> dependency on JUnit), the then add a JUnit that simply does:
>>
>> new IsDefinedFunction();
>>
>> Whatever exeception is being thrown will be become clear.
>>
>> Paul
>>
>
>
Re: [JET2] - Is there a way to check if a variable has been defined [message #24311 is a reply to message #19277] Thu, 28 June 2007 07:05 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
where can I get this enhancement ?

Tex.
Re: [JET2] - Is there a way to check if a variable has been defined [message #24392 is a reply to message #24311] Thu, 28 June 2007 09:58 Go to previous messageGo to next message
Eclipse UserFriend
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 #24596 is a reply to message #24392] Fri, 29 June 2007 10:55 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
you mean that this "isDefined" function will be included with the 0.8.0
version ?


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 #24826 is a reply to message #24596] Tue, 03 July 2007 06:42 Go to previous messageGo to next message
Eclipse UserFriend
Sorry to ask again but is this function supposed to be included in the
last release ?

thx,
Tex.

Tex Twil wrote:
> Hi,
> you mean that this "isDefined" function will be included with the 0.8.0
> version ?
>
>
> 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 #24860 is a reply to message #24392] Wed, 04 July 2007 04:42 Go to previous messageGo to next message
Eclipse UserFriend
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 #24913 is a reply to message #24826] Wed, 04 July 2007 10:59 Go to previous messageGo to next message
Eclipse UserFriend
Tex:

No isDefined is not yet included in any JET version.

Paul

"Tex Twil" <chaljan@hotmail.com> wrote in message
news:f6d96v$t0c$1@build.eclipse.org...
> Sorry to ask again but is this function supposed to be included in the
> last release ?
>
> thx,
> Tex.
>
> Tex Twil wrote:
>> Hi,
>> you mean that this "isDefined" function will be included with the 0.8.0
>> version ?
>>
>>
>> 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 #25003 is a reply to message #24860] Wed, 04 July 2007 11:14 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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.
>>>>
>
Previous Topic:Re: invoke template from java with string return?
Next Topic:User of infant JET
Goto Forum:
  


Current Time: Sun May 11 18:09:35 EDT 2025

Powered by FUDForum. Page generated in 0.03957 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top