cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r543495 - /cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java
Date Fri, 01 Jun 2007 14:31:52 GMT
Author: vgritsenko
Date: Fri Jun  1 07:31:51 2007
New Revision: 543495

URL: http://svn.apache.org/viewvc?view=rev&rev=543495
Log:
remove excessive code duplication.
check for possible eternal loop.
improve consistency (one case had if() not while() as everywhere else)

Modified:
    cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java

Modified: cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java?view=diff&rev=543495&r1=543494&r2=543495
==============================================================================
--- cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java
(original)
+++ cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JSIntrospector.java
Fri Jun  1 07:31:51 2007
@@ -78,14 +78,8 @@
                     }
                 }
                 result = ScriptRuntime.call(cx, result, thisObj, newArgs, scope);
-                if (result == Undefined.instance || result == Scriptable.NOT_FOUND) {
-                    result = null;
-                } else if (!(result instanceof NativeJavaClass)) {
-                    while (result instanceof Wrapper) {
-                        result = ((Wrapper)result).unwrap();
-                    }
-                }
-                return result;
+
+                return unwrap(result);
             } catch (JavaScriptException e) {
                 throw new java.lang.reflect.InvocationTargetException(e);
             } finally {
@@ -135,12 +129,8 @@
                         }
                     }
                 }
-                if (result == Scriptable.NOT_FOUND || result == Undefined.instance) {
-                    result = null;
-                } else if (result instanceof Wrapper && !(result instanceof NativeJavaClass))
{
-                    result = ((Wrapper)result).unwrap();
-                }
-                return result;
+
+                return unwrap(result);
             } finally {
                 Context.exit();
             }
@@ -216,17 +206,8 @@
             Context.enter();
             try {
                 Object result = arr.get(index++, arr);
-                if (result == Undefined.instance ||
-                    result == Scriptable.NOT_FOUND) {
-                    result = null;
-                } else {
-                    if (!(result instanceof NativeJavaClass)) {
-                        while (result instanceof Wrapper) {
-                            result = ((Wrapper)result).unwrap();
-                        }
-                    }
-                }
-                return result;
+
+                return unwrap(result);
             } finally {
                 Context.exit();
             }
@@ -257,14 +238,8 @@
             Context.enter();
             try {
                 Object result = ScriptableObject.getProperty(scope, ids[index++].toString());
-                if (result == Undefined.instance || result == Scriptable.NOT_FOUND) {
-                    result = null;
-                } else if (!(result instanceof NativeJavaClass)) {
-                    while (result instanceof Wrapper) {
-                        result = ((Wrapper)result).unwrap();
-                    }
-                }
-                return result;
+
+                return unwrap(result);
             } finally {
                 Context.exit();
             }
@@ -333,5 +308,25 @@
     public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info
i) throws Exception {
         return !(obj instanceof Scriptable) ?
                 super.getPropertySet(obj, identifier, arg, i) : new JSPropertySet((Scriptable)obj,
identifier);
+    }
+
+    private static Object unwrap(Object result) {
+        if (result == Undefined.instance || result == Scriptable.NOT_FOUND) {
+            return null;
+        }
+
+        if (!(result instanceof NativeJavaClass)) {
+            Object value;
+            while (result instanceof Wrapper) {
+                value = ((Wrapper) result).unwrap();
+                if (value == result) {
+                    break;
+                }
+
+                result = value;
+            }
+        }
+
+        return result;
     }
 }



Mime
View raw message