Dot operators...
Malik H <[email protected]> Thu, 15 Aug 2002 13:24:16 -0700 (PDT)
| Newsgroups | gmane.comp.java.jel.general |
|---|---|
| Message-ID | <[email protected]> |
--0-386232458-1029443056=:96213
Content-Type: text/plain; charset=us-ascii
Konstantin:
Thanks for your email to my colleage Prem. But it appears that We are still experiecing the problem. We are trying to dynamically evaluate java expression like:
"someobject.isTrue()==true" where someObject is created and registered thru Dynamic lib registration.
Similarly we get the following compilitaiion error for String object:
COMPILATION ERROR :The name "String" is unknown.
String.toString()
Here is the entire code....Please help,...
package test;
import gnu.jel.*;
import gov.irs.efile.tfrp.dataModel.PTFResult;
public class JelTest {
public static void main(String[] args) {
// Set up the library
Class[] staticLib=new Class[1];
try {
staticLib[0]=Class.forName("java.lang.String");
} catch(ClassNotFoundException e) {
// Can't be ;)) ...... in java ... ;)
};
Class[] dynamicLib=new Class[1];
/*
PTFResult ptfResult = new PTFResult(0, true);
Object[] context = new Object[1];
context[0]=ptfResult;
dynamicLib[0]=ptfResult.getClass();
*/
String ptfResult = new String();
Object[] context = new Object[1];
context[0]=ptfResult;
dynamicLib[0]=ptfResult.getClass();
Library lib=new Library(null,dynamicLib,new Class[0],null,null);
try {
lib.markStateDependent("random",null);
} catch (Exception e) {
// Can't be also
};
String testStr = "abc";
//DVMap resolver = new DVMap();
//PTFResult ptfResult = new PTFResult(0, true);
//
//String expr = "\"abc\".length()==3";
String expr = "testStr.toString()";///"ptfResult.getIsValid()==true";
//String expr = "PTFResult.getIsValid()==true";
CompiledExpression expr_c=null;
try {
expr_c=Evaluator.compile(expr,lib);
} catch (CompilationException ce) {
System.err.print("COMPILATION ERROR :");
System.err.println(ce.getMessage());
System.err.print(" ");
System.err.println(expr);
int column=ce.getColumn(); // Column, where error was found
for(int i=0;i<column+23-1;i++) System.err.print(' ');
System.err.println('^');
}
if (expr_c != null) {
// Evaluate (Can do it now any number of times FAST !!!)
Boolean result=null;
try {
result=(Boolean)expr_c.evaluate(null);
} catch (Throwable e) {
System.err.println("Exception emerged from JEL compiled"+
" code (IT'S OK) :");
System.err.print(e);
}
System.err.println("result = " + result);
}
}
}
---------------------------------
Do You Yahoo!?
HotJobs, a Yahoo! service - Search Thousands of New Jobs
--0-386232458-1029443056=:96213
Content-Type: text/html; charset=us-ascii
<FONT face="Courier New" color=#000000 size=2>
<P>Konstantin:</P>
<P>Thanks for your email to my colleage Prem. But it appears that We are still experiecing the problem. We are trying to dynamically evaluate java expression like:</P>
<P>"someobject.isTrue()==true" where someObject is created and registered thru Dynamic lib registration.</P>
<P>Similarly we get the following compilitaiion error for String object:</P><FONT color=#ff0000 size=2>
<P>COMPILATION ERROR :The name "String" is unknown.</P>
<P>String.toString()</P></FONT>
<P>Here is the entire code....Please help,...</P><FONT color=#7f0055 size=2>
<P>package </FONT><FONT color=#000000 size=2>test;</P></FONT><FONT color=#7f0055 size=2>
<P>import </FONT><FONT color=#000000 size=2>gnu.jel.*;</P></FONT><FONT color=#7f0055 size=2>
<P>import </FONT><FONT color=#000000 size=2>gov.irs.efile.tfrp.dataModel.PTFResult;</P></FONT><FONT size=2>
<P> </P></FONT><FONT color=#7f0055 size=2>
<P>public class </FONT><FONT color=#000000 size=2>JelTest {</P></FONT><FONT size=2></FONT><FONT color=#000000 size=2>
<P></FONT><FONT color=#7f0055 size=2>public static void </FONT><FONT color=#000000 size=2>main(String[] args) {</P>
<P></P>
<P></P>
<P></FONT><FONT color=#3f7f5f size=2>// Set up the library</P>
<P></FONT><FONT color=#000000 size=2>Class[] staticLib=</FONT><FONT color=#7f0055 size=2>new </FONT><FONT color=#000000 size=2>Class[1];</P>
<P></FONT><FONT color=#7f0055 size=2>try </FONT><FONT color=#000000 size=2>{</P>
<P>staticLib[0]=Class.forName(</FONT><FONT color=#2a00ff size=2>"java.lang.String"</FONT><FONT color=#000000 size=2>);</P>
<P>} </FONT><FONT color=#7f0055 size=2>catch</FONT><FONT color=#000000 size=2>(ClassNotFoundException e) {</P>
<P></FONT><FONT color=#3f7f5f size=2>// Can't be ;)) ...... in java ... ;)</P></FONT><FONT color=#000000 size=2>
<P>};</P>
<P></P>
<P></P>
<P>Class[] dynamicLib=</FONT><FONT color=#7f0055 size=2>new </FONT><FONT color=#000000 size=2>Class[1];</P>
<P></FONT><FONT color=#3f7f5f size=2>/*</P>
<P>PTFResult ptfResult = new PTFResult(0, true);</P>
<P>Object[] context = new Object[1];</P>
<P>context[0]=ptfResult;</P>
<P>dynamicLib[0]=ptfResult.getClass();</P>
<P>*/</P></FONT><FONT color=#000000 size=2>
<P>String ptfResult = </FONT><FONT color=#7f0055 size=2>new </FONT><FONT color=#000000 size=2>String();</P>
<P>Object[] context = </FONT><FONT color=#7f0055 size=2>new </FONT><FONT color=#000000 size=2>Object[1];</P>
<P>context[0]=ptfResult;</P>
<P>dynamicLib[0]=ptfResult.getClass();</P></FONT><FONT size=2></FONT><FONT color=#000000 size=2>
<P></P>
<P></P>
<P></P>
<P>Library lib=</FONT><FONT color=#7f0055 size=2>new </FONT><FONT color=#000000 size=2>Library(</FONT><FONT color=#7f0055 size=2>null</FONT><FONT color=#000000 size=2>,dynamicLib,</FONT><FONT color=#7f0055 size=2>new </FONT><FONT color=#000000 size=2>Class[0],</FONT><FONT color=#7f0055 size=2>null</FONT><FONT color=#000000 size=2>,</FONT><FONT color=#7f0055 size=2>null</FONT><FONT color=#000000 size=2>);</P>
<P></FONT><FONT color=#7f0055 size=2>try </FONT><FONT color=#000000 size=2>{</P>
<P>lib.markStateDependent(</FONT><FONT color=#2a00ff size=2>"random"</FONT><FONT color=#000000 size=2>,</FONT><FONT color=#7f0055 size=2>null</FONT><FONT color=#000000 size=2>);</P>
<P>} </FONT><FONT color=#7f0055 size=2>catch </FONT><FONT color=#000000 size=2>(Exception e) {</P>
<P></FONT><FONT color=#3f7f5f size=2>// Can't be also</P>
<P></FONT><FONT color=#000000 size=2>};</P>
<P></P>
<P>String testStr = </FONT><FONT color=#2a00ff size=2>"abc"</FONT><FONT color=#000000 size=2>; </P>
<P></FONT><FONT color=#3f7f5f size=2>//DVMap resolver = new DVMap();</P>
<P>//PTFResult ptfResult = new PTFResult(0, true); </P>
<P>//</P>
<P></P>
<P>//String expr = "\"abc\".length()==3";</P>
<P></P></FONT><FONT color=#000000 size=2>
<P>String expr = </FONT><FONT color=#2a00ff size=2>"testStr.toString()"</FONT><FONT color=#000000 size=2>;</FONT><FONT color=#3f7f5f size=2>///"ptfResult.getIsValid()==true"; </P>
<P>//String expr = "PTFResult.getIsValid()==true";</P>
<P></FONT><FONT color=#000000 size=2>CompiledExpression expr_c=</FONT><FONT color=#7f0055 size=2>null</FONT><FONT color=#000000 size=2>;</P>
<P></FONT><FONT color=#7f0055 size=2>try </FONT><FONT color=#000000 size=2>{</P>
<P>expr_c=Evaluator.compile(expr,lib);</P>
<P>} </FONT><FONT color=#7f0055 size=2>catch </FONT><FONT color=#000000 size=2>(CompilationException ce) {</P>
<P>System.err.print(</FONT><FONT color=#2a00ff size=2>"COMPILATION ERROR :"</FONT><FONT color=#000000 size=2>);</P>
<P>System.err.println(ce.getMessage());</P>
<P>System.err.print(</FONT><FONT color=#2a00ff size=2>" "</FONT><FONT color=#000000 size=2>);</P>
<P>System.err.println(expr);</P>
<P></FONT><FONT color=#7f0055 size=2>int </FONT><FONT color=#000000 size=2>column=ce.getColumn(); </FONT><FONT color=#3f7f5f size=2>// Column, where error was found</P>
<P></FONT><FONT color=#7f0055 size=2>for</FONT><FONT color=#000000 size=2>(</FONT><FONT color=#7f0055 size=2>int </FONT><FONT color=#000000 size=2>i=0;i<column+23-1;i++) System.err.print(</FONT><FONT color=#2a00ff size=2>' '</FONT><FONT color=#000000 size=2>);</P>
<P>System.err.println(</FONT><FONT color=#2a00ff size=2>'^'</FONT><FONT color=#000000 size=2>);</P>
<P>}</P>
<P></P>
<P></FONT><FONT color=#7f0055 size=2>if </FONT><FONT color=#000000 size=2>(expr_c != </FONT><FONT color=#7f0055 size=2>null</FONT><FONT color=#000000 size=2>) {</P>
<P></P>
<P></FONT><FONT color=#3f7f5f size=2>// Evaluate (Can do it now any number of times FAST !!!)</P>
<P></FONT><FONT color=#000000 size=2>Boolean result=</FONT><FONT color=#7f0055 size=2>null</FONT><FONT color=#000000 size=2>;</P>
<P></FONT><FONT color=#7f0055 size=2>try </FONT><FONT color=#000000 size=2>{</P>
<P>result=(Boolean)expr_c.evaluate(</FONT><FONT color=#7f0055 size=2>null</FONT><FONT color=#000000 size=2>);</P>
<P>} </FONT><FONT color=#7f0055 size=2>catch </FONT><FONT color=#000000 size=2>(Throwable e) {</P>
<P>System.err.println(</FONT><FONT color=#2a00ff size=2>"Exception emerged from JEL compiled"</FONT><FONT color=#000000 size=2>+</P>
<P></FONT><FONT color=#2a00ff size=2>" code (IT'S OK) :"</FONT><FONT color=#000000 size=2>);</P>
<P>System.err.print(e);</P>
<P>}</P>
<P>System.err.println(</FONT><FONT color=#2a00ff size=2>"result = " </FONT><FONT color=#000000 size=2>+ result);</P>
<P></P>
<P>}</P>
<P>}</P></FONT><FONT size=2></FONT><FONT color=#000000 size=2>
<P>}</P></FONT>
<P> </P></FONT><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="http://rd.yahoo.com/careers/mailsig/new/*http://www.hotjobs.com">HotJobs, a Yahoo! service</a> - Search Thousands of New Jobs
--0-386232458-1029443056=:96213--