01: /**
02: * InstantJ
03: *
04: * Copyright (C) 2002 Nils Meier
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */package instantj.tst;
17:
18: import instantj.expression.Expression;
19: import instantj.reflect.ReflectAccess;
20:
21: /**
22: * Hello World Test
23: */
24: public class HelloWorldTest {
25:
26: /** some predefined sample expressions */
27: public final static String[] samples = new String[] {
28: "\"It is \" + new java.util.Date() + \" ... too late!\"",
29: "\"Hello World\"", "\"PI equals \" + Math.PI " };
30:
31: /**
32: * Testing Expression Evaluation -
33: */
34: public static void main(String[] args) {
35:
36: // Disclaimer
37: System.out.println("InstantJ - "
38: + ReflectAccess.getInstance().calcClassNameOf(
39: HelloWorldTest.class));
40:
41: // The user can specify an expression-body on the command-line
42: String body;
43: if (args.length == 1) {
44: // .. here it is
45: body = args[0];
46: } else {
47: // .. otherwise we use a pre-canned one
48: int random = Math.abs(new java.util.Random().nextInt()
49: % samples.length);
50: System.out
51: .println("Usage: java instantj.tst.HelloWorld [expression"
52: + random + "]");
53: body = samples[random];
54: }
55:
56: // We create an expression and evaluate it
57: Object result = "undefined";
58: try {
59: result = new Expression(body).getInstance().evaluate();
60: } catch (Exception t) {
61: t.printStackTrace();
62: }
63:
64: // Lastly report the result
65: System.out.println();
66: System.out.println(" Expression = " + body);
67: System.out.println(" Result = " + result);
68:
69: }
70:
71: }
|