Author: proyal
Date: Fri Jun 1 20:54:51 2007
New Revision: 543702
URL: http://svn.apache.org/viewvc?view=rev&rev=543702
Log:
JEXL-13 - Allow pluggable Uberspect by supplying one when creating a non-static
instance of the ExpressionFactory. The static instance still uses the default
Uberspect.
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTArrayAccess.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTForeachStatement.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIdentifier.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeFunction.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeMethod.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleNode.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/VelPropertyGet.java
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java
Fri Jun 1 20:54:51 2007
@@ -28,6 +28,8 @@
import org.apache.commons.jexl.parser.Parser;
import org.apache.commons.jexl.parser.SimpleNode;
import org.apache.commons.jexl.parser.TokenMgrError;
+import org.apache.commons.jexl.util.introspection.Uberspect;
+import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -64,7 +66,9 @@
* When parsing expressions, ExpressionFactory synchronizes on Parser.
*/
protected static Parser parser =
- new Parser(new StringReader(";")); //$NON-NLS-1$
+ new Parser(new StringReader(";"), Introspector.getUberspect() );
//$NON-NLS-1$
+
+ private final Parser _parser;
/**
* ExpressionFactory is a singleton and this is the private
@@ -77,13 +81,18 @@
* with a call to getInstance().
*/
private ExpressionFactory() {
+ _parser = parser;
+ }
+
+ public ExpressionFactory( Uberspect uberspect ) {
+ _parser = new Parser(new StringReader(";"), uberspect);
}
/**
* Returns the single instance of ExpressionFactory.
* @return the instance of ExpressionFactory.
*/
- protected static ExpressionFactory getInstance() {
+ public static ExpressionFactory getInstance() {
return ef;
}
@@ -111,17 +120,17 @@
* @throws Exception for a variety of reasons - mostly malformed
* Jexl expression
*/
- protected Expression createNewExpression(final String expression)
+ public Expression createNewExpression(final String expression)
throws Exception {
String expr = cleanExpression(expression);
// Parse the Expression
SimpleNode tree;
- synchronized (parser) {
+ synchronized (_parser) {
log.debug("Parsing expression: " + expr);
try {
- tree = parser.parse(new StringReader(expr));
+ tree = _parser.parse(new StringReader(expr));
} catch (TokenMgrError tme) {
throw new ParseException(tme.getMessage());
}
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
Fri Jun 1 20:54:51 2007
@@ -30,20 +30,21 @@
import org.apache.commons.jexl.parser.Parser;
import org.apache.commons.jexl.parser.SimpleNode;
import org.apache.commons.jexl.parser.TokenMgrError;
+import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * <p>
+ * <p>
* Creates [EMAIL PROTECTED] Script}s. To create a JEXL Script, pass
* valid JEXL syntax to the static createScript() method:
* </p>
- *
+ *
* <pre>
* String jexl = "y = x * 12 + 44; y = y * 4;";
* Script script = ScriptFactory.createScript( jexl );
* </pre>
- *
+ *
* <p>
* When an [EMAIL PROTECTED] Script} is created, the JEXL syntax is
* parsed and verified.
@@ -58,11 +59,11 @@
LogFactory.getLog("org.apache.commons.jexl.ScriptFactory");
/**
- * The singleton ScriptFactory also holds a single instance of
- * [EMAIL PROTECTED] Parser}. When parsing expressions, ScriptFactory
+ * The singleton ScriptFactory also holds a single instance of
+ * [EMAIL PROTECTED] Parser}. When parsing expressions, ScriptFactory
* synchronizes on Parser.
*/
- protected static Parser parser = new Parser(new StringReader(";"));
+ protected static Parser parser = new Parser(new StringReader(";"),
Introspector.getUberspect() );
/**
* ScriptFactory is a singleton and this is the private
@@ -87,13 +88,13 @@
}
/**
- * Creates a Script from a String containing valid JEXL syntax.
+ * Creates a Script from a String containing valid JEXL syntax.
* This method parses the script which validates the syntax.
- *
+ *
* @param scriptText A String containing valid JEXL syntax
- * @return A [EMAIL PROTECTED] Script} which can be executed with a
+ * @return A [EMAIL PROTECTED] Script} which can be executed with a
* [EMAIL PROTECTED] JexlContext}.
- * @throws Exception An exception can be thrown if there is a
+ * @throws Exception An exception can be thrown if there is a
* problem parsing the script.
*/
public static Script createScript(String scriptText) throws Exception {
@@ -101,14 +102,14 @@
}
/**
- * Creates a Script from a [EMAIL PROTECTED] File} containing valid JEXL
syntax.
+ * Creates a Script from a [EMAIL PROTECTED] File} containing valid JEXL
syntax.
* This method parses the script and validates the syntax.
- *
+ *
* @param scriptFile A [EMAIL PROTECTED] File} containing valid JEXL
syntax.
* Must not be null. Must be a readable file.
- * @return A [EMAIL PROTECTED] Script} which can be executed with a
+ * @return A [EMAIL PROTECTED] Script} which can be executed with a
* [EMAIL PROTECTED] JexlContext}.
- * @throws Exception An exception can be thrown if there is a problem
+ * @throws Exception An exception can be thrown if there is a problem
* parsing the script.
*/
public static Script createScript(File scriptFile) throws Exception {
@@ -116,21 +117,21 @@
throw new NullPointerException("scriptFile is null");
}
if (!scriptFile.canRead()) {
- throw new IOException("Can't read scriptFile ("
+ throw new IOException("Can't read scriptFile ("
+ scriptFile.getCanonicalPath() + ")");
}
BufferedReader reader = new BufferedReader(new FileReader(scriptFile));
return createScript(readerToString(reader));
-
+
}
/**
- * Creates a Script from a [EMAIL PROTECTED] URL} containing valid JEXL
syntax.
+ * Creates a Script from a [EMAIL PROTECTED] URL} containing valid JEXL
syntax.
* This method parses the script and validates the syntax.
- *
+ *
* @param scriptUrl A [EMAIL PROTECTED] URL} containing valid JEXL syntax.
* Must not be null. Must be a readable file.
- * @return A [EMAIL PROTECTED] Script} which can be executed with a
+ * @return A [EMAIL PROTECTED] Script} which can be executed with a
* [EMAIL PROTECTED] JexlContext}.
* @throws Exception An exception can be thrown if there is a problem
* parsing the script.
@@ -140,7 +141,7 @@
throw new NullPointerException("scriptUrl is null");
}
URLConnection connection = scriptUrl.openConnection();
-
+
BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
return createScript(readerToString(reader));
@@ -186,7 +187,7 @@
}
return expr;
}
-
+
/**
* Read a buffered reader into a StringBuffer and return a String with
* the contents of the reader.
@@ -198,7 +199,7 @@
throws IOException {
StringBuffer buffer = new StringBuffer();
try {
- String line = null;
+ String line;
while ((line = reader.readLine()) != null) {
buffer.append(line).append('\n');
}
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTArrayAccess.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTArrayAccess.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTArrayAccess.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTArrayAccess.java
Fri Jun 1 20:54:51 2007
@@ -17,21 +17,21 @@
package org.apache.commons.jexl.parser;
+import java.lang.reflect.Array;
+import java.util.List;
+import java.util.Map;
+
import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Coercion;
-import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.jexl.util.introspection.Info;
+import org.apache.commons.jexl.util.introspection.Uberspect;
import org.apache.commons.jexl.util.introspection.VelPropertyGet;
-import java.util.List;
-import java.util.Map;
-import java.lang.reflect.Array;
-
/**
* Like an ASTIdentifier, but with array access allowed.
- *
+ *
* $foo[2]
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id$
*/
@@ -41,7 +41,7 @@
/**
* Create the node given an id.
- *
+ *
* @param id node id.
*/
public ASTArrayAccess(int id) {
@@ -50,7 +50,7 @@
/**
* Create a node with the given parser and id.
- *
+ *
* @param p a parser.
* @param id node id.
*/
@@ -65,9 +65,9 @@
/**
* evaluate array access upon a base object.
- *
+ *
* foo.bar[2]
- *
+ *
* makes me rethink the array operator :)
* @param jc the [EMAIL PROTECTED] JexlContext} to evaluate against.
* @param obj not used.
@@ -89,7 +89,7 @@
return null;
}
- result = evaluateExpr(result, loc);
+ result = evaluateExpr(result, loc, getUberspect() );
}
return result;
@@ -115,7 +115,7 @@
return null;
}
- o = evaluateExpr(o, loc);
+ o = evaluateExpr(o, loc, getUberspect() );
}
return o;
@@ -124,19 +124,20 @@
/**
* Evaluate the Array expression 'loc' on the given object, o.
* e.g. in 'a[2]', <code>2</code> is 'loc' and <code>a</code> is 'o'.
- *
+ *
* If o or loc are null, null is returned.
* If o is a Map, o.get(loc) is returned.
* If o is a List, o.get(loc) is returned. loc must resolve to an int
value.
* If o is an Array, o[loc] is returned. loc must resolve to an int value.
* Otherwise loc is treated as a bean property of o.
- *
+ *
* @param o an object to be accessed using the array operator or '.'
operator.
* @param loc the index of the object to be returned.
+ * @param uberspect Uberspector to use during evaluation
* @return the resulting value.
* @throws Exception on any error.
*/
- public static Object evaluateExpr(Object o, Object loc) throws Exception {
+ public static Object evaluateExpr( Object o, Object loc, Uberspect
uberspect ) throws Exception {
/*
* following the JSTL EL rules
*/
@@ -178,7 +179,7 @@
String s = loc.toString();
- VelPropertyGet vg = Introspector.getUberspect().getPropertyGet(o,
s, DUMMY);
+ VelPropertyGet vg = uberspect.getPropertyGet(o, s, DUMMY);
if (vg != null) {
return vg.invoke(o);
@@ -190,7 +191,7 @@
/**
* Gets the variable name piece of the expression.
- * @return a String of the identifer.
+ * @return a String of the identifer.
* @see ASTIdentifier#getIdentifierString().
*/
public String getIdentifierString() {
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTForeachStatement.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTForeachStatement.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTForeachStatement.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTForeachStatement.java
Fri Jun 1 20:54:51 2007
@@ -20,12 +20,11 @@
import java.util.Iterator;
import org.apache.commons.jexl.JexlContext;
-import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.jexl.util.introspection.Info;
/**
* ForEach statement. Syntax: foreach (var in iterable) Statement()
- *
+ *
* @author Dion Gillard
* @since 1.1
*/
@@ -42,7 +41,7 @@
/**
* Create the node given an id.
- *
+ *
* @param id node id.
*/
public ASTForeachStatement(int id) {
@@ -51,7 +50,7 @@
/**
* Create a node with the given parser and id.
- *
+ *
* @param p a parser.
* @param id node id.
*/
@@ -78,7 +77,7 @@
SimpleNode statement = (SimpleNode) jjtGetChild(2);
// get an iterator for the collection/array etc via the
// introspector.
- Iterator itemsIterator = Introspector.getUberspect().getIterator(
+ Iterator itemsIterator = getUberspect().getIterator(
iterableValue, DUMMY);
while (itemsIterator.hasNext()) {
// set loopVariable to value of iterator
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIdentifier.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIdentifier.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIdentifier.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIdentifier.java
Fri Jun 1 20:54:51 2007
@@ -18,10 +18,11 @@
package org.apache.commons.jexl.parser;
import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.util.introspection.Uberspect;
/**
* Simple identifier - $foo or $foo.bar (both parts are identifiers).
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id$
*/
@@ -31,7 +32,7 @@
/**
* Create the node given an id.
- *
+ *
* @param id node id.
*/
public ASTIdentifier(int id) {
@@ -40,7 +41,7 @@
/**
* Create a node with the given parser and id.
- *
+ *
* @param p a parser.
* @param id node id.
*/
@@ -63,18 +64,18 @@
* identifier can be gotten via a get(String).
* e.g. if we have bean.property, 'property' has been parsed as an
identifier,
* and we need to resolve the expression by calling the property getter.
- *
+ *
* @param obj the object to evaluate against.
* @param jc the [EMAIL PROTECTED] JexlContext}.
* @throws Exception on any error.
* @return the resulting value.
- * @see ASTArrayAccess#evaluateExpr(Object, Object)
+ * @see ASTArrayAccess#evaluateExpr(Object, Object, Uberspect)
*/
public Object execute(Object obj, JexlContext jc) throws Exception {
- return ASTArrayAccess.evaluateExpr(obj, val);
+ return ASTArrayAccess.evaluateExpr(obj, val, getUberspect() );
}
- /**
+ /**
* Gets the name of the variable.
* @return the variable name.
*/
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIntegerLiteral.java
Fri Jun 1 20:54:51 2007
@@ -17,10 +17,11 @@
package org.apache.commons.jexl.parser;
import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.util.introspection.Uberspect;
/**
* represents an integer.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id$
*/
@@ -30,7 +31,7 @@
/**
* Create the node given an id.
- *
+ *
* @param id node id.
*/
public ASTIntegerLiteral(int id) {
@@ -39,7 +40,7 @@
/**
* Create a node with the given parser and id.
- *
+ *
* @param p a parser.
* @param id node id.
*/
@@ -60,10 +61,10 @@
* @param ctx the [EMAIL PROTECTED] JexlContext}.
* @throws Exception on any error.
* @return the resulting value.
- * @see ASTArrayAccess#evaluateExpr(Object, Object)
+ * @see ASTArrayAccess#evaluateExpr(Object, Object, Uberspect)
*/
public Object execute(Object obj, JexlContext ctx) throws Exception {
- return ASTArrayAccess.evaluateExpr(obj, val);
+ return ASTArrayAccess.evaluateExpr(obj, val, getUberspect() );
}
/** [EMAIL PROTECTED] */
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMethod.java
Fri Jun 1 20:54:51 2007
@@ -21,9 +21,8 @@
import java.math.BigInteger;
import org.apache.commons.jexl.JexlContext;
-import org.apache.commons.jexl.util.Introspector;
-import org.apache.commons.jexl.util.introspection.VelMethod;
import org.apache.commons.jexl.util.introspection.Info;
+import org.apache.commons.jexl.util.introspection.VelMethod;
/**
* Method execution.
@@ -34,7 +33,7 @@
/**
* Create the node given an id.
- *
+ *
* @param id node id.
*/
public ASTMethod(int id) {
@@ -43,7 +42,7 @@
/**
* Create a node with the given parser and id.
- *
+ *
* @param p a parser.
* @param id node id.
*/
@@ -58,9 +57,9 @@
/**
* evaluate a method invocation upon a base object.
- *
+ *
* foo.bar(2)
- *
+ *
* @param jc the [EMAIL PROTECTED] JexlContext} to evaluate against.
* @param obj The object to have the method invoked.
* @return the value of the method invocation.
@@ -82,7 +81,7 @@
params[i] = ((SimpleNode) jjtGetChild(i + 1)).value(jc);
}
- VelMethod vm = Introspector.getUberspect().getMethod(obj,
methodName, params, DUMMY);
+ VelMethod vm = getUberspect().getMethod(obj, methodName, params,
DUMMY);
/*
* DG: If we can't find an exact match, narrow the parameters and
* try again!
@@ -96,7 +95,7 @@
params[i] = narrow((Number) param);
}
}
- vm = Introspector.getUberspect().getMethod(obj, methodName,
params, DUMMY);
+ vm = getUberspect().getMethod(obj, methodName, params, DUMMY);
if (vm == null) {
return null;
}
@@ -120,7 +119,7 @@
* method calls, e.g. a call to substring(int,int) with an int and a long
* will fail, but a call to substring(int,int) with an int and a short will
* succeed.
- *
+ *
* @param original the original number.
* @return a value of the smallest type the original number will fit into.
* @since 1.1
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeFunction.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeFunction.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeFunction.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeFunction.java
Fri Jun 1 20:54:51 2007
@@ -21,13 +21,13 @@
import java.util.Map;
import org.apache.commons.jexl.JexlContext;
-import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.jexl.util.introspection.Info;
+import org.apache.commons.jexl.util.introspection.Uberspect;
import org.apache.commons.jexl.util.introspection.VelMethod;
/**
* generalized size() function for all classes we can think of.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @author <a href="[EMAIL PROTECTED]">Mark H. Wilkinson</a>
* @version $Id$
@@ -35,7 +35,7 @@
public class ASTSizeFunction extends SimpleNode {
/**
* Create the node given an id.
- *
+ *
* @param id node id.
*/
public ASTSizeFunction(int id) {
@@ -44,7 +44,7 @@
/**
* Create a node with the given parser and id.
- *
+ *
* @param p a parser.
* @param id node id.
*/
@@ -67,18 +67,19 @@
throw new Exception("size() : null arg");
}
- return new Integer(ASTSizeFunction.sizeOf(val));
+ return new Integer(ASTSizeFunction.sizeOf(val, getUberspect() ));
}
/**
* Calculate the <code>size</code> of various types: Collection, Array,
Map, String,
* and anything that has a int size() method.
- *
+ *
* @param val the object to get the size of.
+ * @param uberspect
* @return the size of val
* @throws Exception if the size cannot be determined.
*/
- public static int sizeOf(Object val) throws Exception {
+ public static int sizeOf( Object val, Uberspect uberspect ) throws
Exception {
if (val instanceof Collection) {
return ((Collection) val).size();
} else if (val.getClass().isArray()) {
@@ -93,7 +94,7 @@
// and if so, just use it
Object[] params = new Object[0];
Info velInfo = new Info("", 1, 1);
- VelMethod vm = Introspector.getUberspect().getMethod(val, "size",
params, velInfo);
+ VelMethod vm = uberspect.getMethod(val, "size", params, velInfo);
if (vm != null && vm.getReturnType() == Integer.TYPE) {
Integer result = (Integer) vm.invoke(val, params);
return result.intValue();
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeMethod.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeMethod.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeMethod.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTSizeMethod.java
Fri Jun 1 20:54:51 2007
@@ -20,14 +20,14 @@
/**
* Size Method, e.g. size().
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Mark H. Wilkinson</a>
* @version $Id$
*/
public class ASTSizeMethod extends SimpleNode {
/**
* Create the node given an id.
- *
+ *
* @param id node id.
*/
public ASTSizeMethod(int id) {
@@ -36,7 +36,7 @@
/**
* Create a node with the given parser and id.
- *
+ *
* @param p a parser.
* @param id node id.
*/
@@ -51,16 +51,16 @@
/**
* evaluate size as part of an expression on a base object.
- *
+ *
* foo.bar.size
- *
+ *
* @param jc the [EMAIL PROTECTED] JexlContext} to evaluate against.
* @param obj not used.
* @return the value of the array expression.
* @throws Exception on any error
*/
public Object execute(Object obj, JexlContext jc) throws Exception {
- return new Integer(ASTSizeFunction.sizeOf(obj));
+ return new Integer(ASTSizeFunction.sizeOf(obj, getUberspect() ));
}
}
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.java
Fri Jun 1 20:54:51 2007
@@ -18,10 +18,13 @@
package org.apache.commons.jexl.parser;
import java.io.Reader;
-import java.io.ByteArrayInputStream;
+
+import org.apache.commons.jexl.util.introspection.Uberspect;
+import org.apache.commons.jexl.util.Introspector;
public class Parser/* @bgen(jjtree) */implements ParserTreeConstants,
ParserConstants { /* @bgen(jjtree) */
protected JJTParserState jjtree = new JJTParserState();
+ private final Uberspect uberspect;
public SimpleNode parse(Reader reader) throws Exception {
ReInit(reader);
@@ -2932,11 +2935,12 @@
private boolean jj_rescan = false;
private int jj_gc = 0;
- public Parser(java.io.InputStream stream) {
- this(stream, null);
+ public Parser( java.io.InputStream stream, Uberspect uberspect ) {
+ this(stream, null, uberspect);
}
- public Parser(java.io.InputStream stream, String encoding) {
- try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); }
catch(java.io.UnsupportedEncodingException e) { throw new
RuntimeException(e.getMessage()); }
+ public Parser( java.io.InputStream stream, String encoding, Uberspect
uberspect ) {
+ this.uberspect = uberspect;
+ try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); }
catch(java.io.UnsupportedEncodingException e) { throw new
RuntimeException(e.getMessage()); }
token_source = new ParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
@@ -2958,8 +2962,13 @@
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
- public Parser(java.io.Reader stream) {
- jj_input_stream = new SimpleCharStream(stream, 1, 1);
+ public Parser( java.io.Reader stream ) {
+ this( stream, Introspector.getUberspect());
+ }
+
+ public Parser( java.io.Reader stream, Uberspect uberspect ) {
+ this.uberspect = uberspect;
+ jj_input_stream = new SimpleCharStream(stream, 1, 1);
token_source = new ParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
@@ -2978,8 +2987,9 @@
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
- public Parser(ParserTokenManager tm) {
- token_source = tm;
+ public Parser( ParserTokenManager tm, Uberspect uberspect ) {
+ this.uberspect = uberspect;
+ token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
@@ -3020,7 +3030,11 @@
throw generateParseException();
}
- static private final class LookaheadSuccess extends java.lang.Error { }
+ public Uberspect getUberspect() {
+ return uberspect;
+ }
+
+ static private final class LookaheadSuccess extends java.lang.Error { }
final private LookaheadSuccess jj_ls = new LookaheadSuccess();
final private boolean jj_scan_token(int kind) {
if (jj_scanpos == jj_lastpos) {
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleNode.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleNode.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleNode.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleNode.java
Fri Jun 1 20:54:51 2007
@@ -18,10 +18,12 @@
package org.apache.commons.jexl.parser;
import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.util.introspection.Uberspect;
+import org.apache.commons.jexl.util.Introspector;
/**
* A Useful implementation of [EMAIL PROTECTED] Node}. Mostly autogenerated by
javacc
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id$
*/
@@ -40,7 +42,7 @@
/**
* Create the node given an id.
- *
+ *
* @param i node id.
*/
public SimpleNode(int i) {
@@ -49,7 +51,7 @@
/**
* Create a node with the given parser and id.
- *
+ *
* @param p a parser.
* @param i node id.
*/
@@ -105,7 +107,7 @@
/**
* Accept the visitor.
- *
+ *
* @param visitor a [EMAIL PROTECTED] ParserVisitor}.
* @param data data to be passed along to the visitor.
* @return the value from visiting.
@@ -117,7 +119,7 @@
/**
* Visit all children.
- *
+ *
* @param visitor a [EMAIL PROTECTED] ParserVisitor}.
* @param data data to be passed along to the visitor.
* @return the value from visiting.
@@ -186,7 +188,7 @@
/**
* Gets the value of this node.
- *
+ *
* @param context the context to retrieve values from.
* @return the value of the node.
* @throws Exception when evaluating the operands fails.
@@ -198,7 +200,7 @@
/**
* Sets the value for the node - again, only makes sense for some nodes but
* lazyness tempts me to put it here. Keeps things simple.
- *
+ *
* @param context the context to retrieve values from.
* @param value the value.
* @return the result.
@@ -217,5 +219,9 @@
*/
public Object execute(Object o, JexlContext ctx) throws Exception {
return null;
+ }
+
+ protected Uberspect getUberspect() {
+ return parser.getUberspect();
}
}
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java
Fri Jun 1 20:54:51 2007
@@ -17,26 +17,27 @@
package org.apache.commons.jexl.util.introspection;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.List;
+
+import org.apache.commons.jexl.util.AbstractExecutor;
import org.apache.commons.jexl.util.ArrayIterator;
+import org.apache.commons.jexl.util.BooleanPropertyExecutor;
import org.apache.commons.jexl.util.EnumerationIterator;
-import org.apache.commons.jexl.util.AbstractExecutor;
import org.apache.commons.jexl.util.GetExecutor;
-import org.apache.commons.jexl.util.BooleanPropertyExecutor;
import org.apache.commons.jexl.util.PropertyExecutor;
import org.apache.commons.logging.Log;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Iterator;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Enumeration;
-import java.util.ArrayList;
-
/**
* Implementation of Uberspect to provide the default introspective
* functionality of Velocity.
- *
+ *
* @since 1.0
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id$
@@ -53,7 +54,7 @@
/**
* the default Velocity introspector.
*/
- private static Introspector introspector;
+ private Introspector introspector;
/**
* init - does nothing - we need to have setRuntimeLogger called before
@@ -151,7 +152,7 @@
executor = new GetExecutor(rlog, introspector, claz, identifier);
}
- return (executor == null) ? null : new VelGetterImpl(executor);
+ return new VelGetterImpl(executor);
}
/**
@@ -215,9 +216,9 @@
public class VelMethodImpl implements VelMethod {
/** the method. */
protected Method method = null;
- /**
+ /**
* Create a new instance.
- *
+ *
* @param m the method.
*/
public VelMethodImpl(Method m) {
@@ -268,7 +269,7 @@
/**
* [EMAIL PROTECTED]
*/
- public class VelGetterImpl implements VelPropertyGet {
+ public static class VelGetterImpl implements VelPropertyGet {
/** executor for performing the get. */
protected AbstractExecutor ae = null;
@@ -298,6 +299,13 @@
/**
* [EMAIL PROTECTED]
*/
+ public boolean isAlive() {
+ return ae.isAlive();
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
public String getMethodName() {
return ae.getMethod().getName();
}
@@ -333,7 +341,7 @@
/** [EMAIL PROTECTED] */
public Object invoke(Object o, Object value) throws Exception {
- ArrayList al = new ArrayList();
+ List al = new ArrayList();
if (putKey == null) {
al.add(value);
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/VelPropertyGet.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/VelPropertyGet.java?view=diff&rev=543702&r1=543701&r2=543702
==============================================================================
---
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/VelPropertyGet.java
(original)
+++
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/VelPropertyGet.java
Fri Jun 1 20:54:51 2007
@@ -20,9 +20,9 @@
/**
* Interface defining a 'getter'. For uses when looking for resolution of
* property references
- *
+ *
* $foo.bar
- *
+ *
* @since 1.0
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id$
@@ -40,7 +40,7 @@
/**
* specifies if this VelPropertyGet is cacheable and able to be reused for
* this class of object it was returned for.
- *
+ *
* @return true if can be reused for this class, false if not
*/
boolean isCacheable();
@@ -50,4 +50,12 @@
* @return the method name.
*/
String getMethodName();
+
+ /**
+ * Tell whether the method underlying this 'property' is alive by
+ * checking to see if represents a successful name resolution
+ *
+ * @return boolean Whether 'property' is alive.
+ */
+ boolean isAlive();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]