jvanzyl 00/10/20 20:21:04
Modified: src/java/org/apache/velocity/runtime/directive Foreach.java
src/java/org/apache/velocity/runtime/parser/node
ASTIdentifier.java ASTMethod.java
src/java/org/apache/velocity/runtime/visitor
BaseVisitor.java
Removed: src/java/org/apache/velocity/util ClassUtils.java
Log:
- more cleanups.
Revision Changes Path
1.12 +29 -2
jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Foreach.java
Index: Foreach.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Foreach.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Foreach.java 2000/10/21 01:59:58 1.11
+++ Foreach.java 2000/10/21 03:21:03 1.12
@@ -57,6 +57,8 @@
import java.io.Writer;
import java.io.IOException;
+import java.lang.reflect.Method;
+
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
@@ -64,7 +66,6 @@
import org.apache.velocity.Context;
import org.apache.velocity.runtime.Runtime;
-import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.util.ArrayIterator;
import org.apache.velocity.runtime.parser.Token;
@@ -132,10 +133,17 @@
node.setInfo(ARRAY);
sampleElement = ((Object[]) listObject)[0];
}
- else if (ClassUtils.implementsMethod(listObject, "iterator"))
+ else if (implementsMethod(listObject, "iterator"))
{
node.setInfo(ITERATOR);
sampleElement = ((Collection) listObject).iterator().next();
+ }
+ else
+ {
+ // If it's not an array or an object that provides
+ // an iterator then the node is invalid and should
+ // not be rendered.
+ node.setInvalid();
}
// This is a little trick so that we can initialize
@@ -176,5 +184,24 @@
context.remove(elementKey);
return true;
+ }
+
+ /**
+ * Checks whether the provided object implements a given method.
+ *
+ * @param object The object to check.
+ * @param methodName The method to check for.
+ * @return Whether the method is implemented.
+ */
+ public static boolean implementsMethod(Object object, String methodName)
+ {
+ int m;
+
+ Method[] methods = object.getClass().getMethods();
+ for (m = 0 ; m < methods.length ; ++m)
+ if (methodName.equals(methods[m].getName()))
+ break;
+
+ return (m < methods.length);
}
}
1.2 +0 -1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
Index: ASTIdentifier.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ASTIdentifier.java 2000/10/20 19:14:02 1.1
+++ ASTIdentifier.java 2000/10/21 03:21:03 1.2
@@ -6,7 +6,6 @@
import java.lang.reflect.Method;
import org.apache.velocity.Context;
-import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.runtime.parser.*;
public class ASTIdentifier extends SimpleNode
1.2 +0 -1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
Index: ASTMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ASTMethod.java 2000/10/20 19:14:02 1.1
+++ ASTMethod.java 2000/10/21 03:21:03 1.2
@@ -5,7 +5,6 @@
import java.lang.reflect.Method;
import org.apache.velocity.Context;
-import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.util.Introspector;
import org.apache.velocity.runtime.parser.*;
1.4 +0 -1
jakarta-velocity/src/java/org/apache/velocity/runtime/visitor/BaseVisitor.java
Index: BaseVisitor.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/visitor/BaseVisitor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BaseVisitor.java 2000/10/21 02:00:17 1.3
+++ BaseVisitor.java 2000/10/21 03:21:04 1.4
@@ -60,7 +60,6 @@
import java.util.Map;
import org.apache.velocity.Context;
-import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.runtime.parser.ParserVisitor;
import org.apache.velocity.runtime.parser.node.*;