Accessing Static member variables from XPRESS.
Hi guys,
Anyone has an idea of how to specify a static member variable in XPRESS?
A static method can be invoked using <invoke name='.....' class='.....'> but what about a variable? For example: variable USER in com.waveset.object.Type.
Thanks in advance.
Adi.
[302 byte] By [
adimut] at [2007-11-26 11:48:49]

# 1
Fortunately for the class com.waveset.object.Type, there is a static method available that returns an object of type 'Type'
<invoke name='findType' class='com.waveset.object.Type'>
<s>User</s>
</invoke>
.... will return Type.USER
but my question above still applies to static member variables in general.
# 2
I dont think there's anything "documented" but you can get around this by doing something like...
<block>
<defvar name='field'>
<invoke name='getField'>
<invoke name='getClass'>
<invoke name='getInstance' class='java.util.Calendar'/>
</invoke>
<s>MONTH</s>
</invoke>
</defvar>
<invoke name='get'>
<ref>field</ref>
<ref>field</ref>
</invoke>
</block>
# 3
Interesting way to work it out!
Just that you should be able to get an instance of the class. In some cases like in 'Type' above, the constructor is protected (or private for that matter) is its not possible to get an object instance.
But this should work in many other cases. Thanks for the insight!
Adi.
# 4
Extending this idea, we could use the Class.forName( ) method, if a class-instance cannot be initiatialized:
<block>
<defvar name='field'>
<invoke name='getField'>
<invoke name='forName' class='java.lang.Class'>
<s>com.waveset.object.Type</s>
</invoke>
<s>USER</s>
</invoke>
</defvar>
<invoke name='get'>
<ref>field</ref>
<ref>field</ref>
</invoke>
</block>
-Adi
# 5
How about using javascript?
<!-- adds 30 days to the current date -->
<script>
var calendar = java.util.Calendar.getInstance();
calendar.add(java.util.Calendar.DAY_OF_YEAR, 30);
var formatter = new java.text.SimpleDateFormat('yyyy-MM-dd');
var deadline = formatter.format(calendar.getTime());
deadline;
</script>