Java Doc for Expression.java in  » Scripting » InstantJ » instantj » expression » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » InstantJ » instantj.expression 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   instantj.expression.Expression

Expression
public class Expression implements Serializable(Code)

An Expression is a piece of Java-code that evaluates to a result of a primitive- or Object-type. Therefor it doesn't have any return-statements and does not end with ';'. Think of an expression as something you can assign to a variable like this

 Object foo = theExpression;
 
(Note that Object foo = and ; are NOT part of the expression). Examples for expression are
 "Hello World"
 account.balance - 100
 2 * Math.PI
 count--; count<0
 
The last one is treated a little bit different - this expression consists of an instruction count--; and the end-result count<0. During evaluation the instruction(s) is/are executed first and the last piece of the expression is returned as the result.

A java-expression can evaluate to a Object- or primitive-type. In the latter case the evaluation of the Expression-object will wrap the primitive result in a Java-type (e.g. Integer).

This type not only wraps the expression's body but alos its environment properties. The properties are kept in a map of name/Class that keeps track of those the expression can use.(e.g. String.class, Account.class or Integer.TYPE). The expression can reference properties in its environment as local variables (see above).

Once you have an instance of an expression you can evaluate it in the environment of property values that you provide. The values are mapped to the property-names and assigned to the expression's local variables before execution.

Example 1:

 // Our expression body
 String body = " 3*4 ";
 // Creating the Expression
 Expression expression = new Expression(body);
 // Evaluate it
 Object result = expression.evaluate();
 
The result of this expression is
(java.lang.Integer) 12
Note: there's no exception-handling in this snippet

Example 2:

 // The properties we want to use inside the expression
 Hashtable properties = new Hashtable();
 properties.put("count", Integer.TYPE);
 properties.put("msg"  , String.class);
 // Our expression body
 String body = " count++; msg+new java.util.Date() ";
 // Creating the Expression
 Expression expression = new Expression(body,properties);
 // The values we give to the evaluation	
 Map values = new HashMap();
 values.put("count", new Integer(3));
 values.put("msg"  , "Guybrush was here on " );
 // Evaluate it
 Object result = expression.getInstance(values).evaluate();
 
The result of this expression is
(java.lang.String) Guybrush was here on Dec 17 11:33:31 EST 2000
As an alternative to passing a value map into getInstance() you can also provide the values for properties programmatically:
 // Evaluate it
 Object result = expression.getInstance().set("count", new Integer(3)).set("msg", "Guybrush was here on").evaluate();
 
Note: there's no exception-handling in this snippet; primitive-types have to wrapped when provided; the time varies :)


author:
   Nils Meier


Field Summary
final public static  StringPARAM_EXPRESSION_DIR
    

Constructor Summary
protected  Expression()
    
public  Expression(String body)
     Constructor for a simple expression without properties.
public  Expression(String body, Map properties)
     Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  properties - the property-names mapped to types (java.lang.Class or java.lang.String).
public  Expression(String body, Map props, Collection imports)
     Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  props - the property-names mapped to types (java.lang.Class or java.lang.String).
public  Expression(String body, Map props, Collection imports, Collection library)
     Constructor for an expression with properties and a library. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  props - the property-names mapped to types (java.lang.Class or java.lang.String).
public  Expression(InputStream body)
     Constructor for a simple expression without properties.
public  Expression(InputStream body, Map properties)
     Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  properties - the property-names mapped to types (java.lang.Class or java.lang.String).
public  Expression(InputStream body, Map properties, Collection imports)
     Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  properties - the property-names mapped to types (java.lang.Class or java.lang.String).
public  Expression(InputStream body, Map properties, Collection imports, Collection library)
     Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  properties - the property-names mapped to types (java.lang.Class or java.lang.String).

Method Summary
public  ExpressionInstancegetInstance()
    
public  ExpressionInstancegetInstance(Map context)
     Returns an ExpressionInstance with its properties' preset to values in given context.

Field Detail
PARAM_EXPRESSION_DIR
final public static String PARAM_EXPRESSION_DIR(Code)
a VM flag that will turn on output of generated expressions in specified directory




Constructor Detail
Expression
protected Expression()(Code)
Constructor for de-serialization



Expression
public Expression(String body) throws CompilationFailedException(Code)
Constructor for a simple expression without properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression Java body
exception:
  CompilationFailedException - when the expression couldn't be compiled



Expression
public Expression(String body, Map properties) throws CompilationFailedException(Code)
Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  properties - the property-names mapped to types (java.lang.Class or java.lang.String). These will be available to the evaluated expression.
exception:
  CompilationFailedException - when the expression couldn't be compiled
exception:
  IllegalArgumentException - when passed Hashtable does not map names (String) to types (Class)



Expression
public Expression(String body, Map props, Collection imports) throws CompilationFailedException(Code)
Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  props - the property-names mapped to types (java.lang.Class or java.lang.String). These will be available to the evaluated expression.
Parameters:
  imports - imports to use (e.g java.util.*, java.sql.*)
exception:
  CompilationFailedException - when the expression couldn't be compiled
exception:
  IllegalArgumentException - when passed Hashtable does not map names (String) to types (Class)



Expression
public Expression(String body, Map props, Collection imports, Collection library) throws CompilationFailedException(Code)
Constructor for an expression with properties and a library. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  props - the property-names mapped to types (java.lang.Class or java.lang.String). These will be available to the evaluated expression.
Parameters:
  imports - imports to use (e.g java.util.*, java.sql.*)
Parameters:
  library - of CompiledSources to use
exception:
  CompilationFailedException - when the expression couldn't be compiled
exception:
  IllegalArgumentException - when passed Hashtable does not map names (String) to types (Class)



Expression
public Expression(InputStream body) throws CompilationFailedException, IOException(Code)
Constructor for a simple expression without properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression's body (Java)
exception:
  CompilationFailedException - when the expression couldn't be compiled



Expression
public Expression(InputStream body, Map properties) throws CompilationFailedException, IOException(Code)
Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  properties - the property-names mapped to types (java.lang.Class or java.lang.String). These will be available to the evaluated expression.
exception:
  CompilationFailedException - when the expression couldn't be compiled
exception:
  IllegalArgumentException - when passed Hashtable does not map names (String) to types (Class)



Expression
public Expression(InputStream body, Map properties, Collection imports) throws CompilationFailedException, IOException(Code)
Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  properties - the property-names mapped to types (java.lang.Class or java.lang.String). These will be available to the evaluated expression.
Parameters:
  imports - imports to use
exception:
  CompilationFailedException - when the expression couldn't be compiled
exception:
  IllegalArgumentException - when passed Hashtable does not map names (String) to types (Class)



Expression
public Expression(InputStream body, Map properties, Collection imports, Collection library) throws CompilationFailedException, IOException(Code)
Constructor for an expression with properties. For more information about what an expression is, look at the Expression class description
Parameters:
  body - the expression body (Java)
Parameters:
  properties - the property-names mapped to types (java.lang.Class or java.lang.String). These will be available to the evaluated expression.
Parameters:
  imports - imports to use
exception:
  CompilationFailedException - when the expression couldn't be compiled
exception:
  IllegalArgumentException - when passed Hashtable does not map names (String) to types (Class)




Method Detail
getInstance
public ExpressionInstance getInstance()(Code)
Returns an instance of the expression for thread-private use



getInstance
public ExpressionInstance getInstance(Map context) throws IllegalPropertyException(Code)
Returns an ExpressionInstance with its properties' preset to values in given context.
Parameters:
  context - a context for the evaluation of the expression. Itmaps property-names to -values. All properties specified inthe expression's constructor will be preset with values fromthe map if possible.Either provide values of according property-type or values that can be used in a one-argument-constructor of the according property-type.
exception:
  IllegalPropertyException - when a property doesn't match the expression's properties the result



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.