svn commit: r783060 - in /ofbiz/trunk/framework: base/config/ base/lib/ minilang/src/org/ofbiz/minilang/ webslinger/lib/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r783060 - in /ofbiz/trunk/framework: base/config/ base/lib/ minilang/src/org/ofbiz/minilang/ webslinger/lib/

doogie-3
Author: doogie
Date: Tue Jun  9 16:19:50 2009
New Revision: 783060

URL: http://svn.apache.org/viewvc?rev=783060&view=rev
Log:
Add ability for simple methods to be wrapped with a custom compiled
class.  The resource location from where the simple method was read
is encoded as the classname of the proxy.  This makes debugging
simpler to do.  This feature is turned off by default.

The wrapping code has support for setting the line number, to include
in stack traces.  However, DOM-based xml parsing doesn't record line
numbers, so it's not possible to encode that into the wrapped proxy
class.

Added:
    ofbiz/trunk/framework/base/config/webslinger-invoker.properties
    ofbiz/trunk/framework/base/lib/webslinger-base-invoker-20090608-61c717e4e33c.jar
      - copied unchanged from r782815, ofbiz/trunk/framework/webslinger/lib/webslinger-base-invoker-20090608-61c717e4e33c.jar
Removed:
    ofbiz/trunk/framework/webslinger/lib/webslinger-base-invoker-20090608-61c717e4e33c.jar
Modified:
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java

Added: ofbiz/trunk/framework/base/config/webslinger-invoker.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/config/webslinger-invoker.properties?rev=783060&view=auto
==============================================================================
--- ofbiz/trunk/framework/base/config/webslinger-invoker.properties (added)
+++ ofbiz/trunk/framework/base/config/webslinger-invoker.properties Tue Jun  9 16:19:50 2009
@@ -0,0 +1,24 @@
+###############################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+###############################################################################
+
+# If true, then various dynamically loaded items will have a custom
+# class compiled, that includes more helpful identification.  This
+# can include some of the following: file location, line number,
+# and/or other unique identification.
+wrap-calls=false

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java?rev=783060&r1=783059&r2=783060&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Tue Jun  9 16:19:50 2009
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.ofbiz.minilang;
 
+import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Collections;
@@ -82,11 +83,15 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import org.webslinger.invoker.Wrap;
+
 /**
  * SimpleMethod Mini Language Core Object
  */
 public class SimpleMethod {
     private static final Map<String, MethodOperation.Factory> methodOperationFactories;
+    private static final Method simpleMethodExecMethod;
+    private static final Method methodOperationExecMethod;
     static {
         Map<String, MethodOperation.Factory> mapFactories = new HashMap<String, MethodOperation.Factory>();
         Iterator<MethodOperation.Factory> it = ServiceRegistry.lookupProviders(MethodOperation.Factory.class, SimpleMethod.class.getClassLoader());
@@ -95,6 +100,12 @@
             mapFactories.put(factory.getName(), factory);
         }
         methodOperationFactories = Collections.unmodifiableMap(mapFactories);
+        try {
+            simpleMethodExecMethod = SimpleMethod.class.getDeclaredMethod("exec", MethodContext.class);
+            methodOperationExecMethod = MethodOperation.class.getDeclaredMethod("exec", MethodContext.class);
+        } catch (NoSuchMethodException e) {
+            throw (InternalError) new InternalError(e.getMessage()).initCause(e);
+        }
     }
 
     public static final String module = SimpleMethod.class.getName();
@@ -225,13 +236,25 @@
 
         Element rootElement = document.getDocumentElement();
         for (Element simpleMethodElement: UtilXml.childElementList(rootElement, "simple-method")) {
-            SimpleMethod simpleMethod = new SimpleMethod(simpleMethodElement, simpleMethods, xmlURL.toString());
+            SimpleMethod simpleMethod = compileSimpleMethod(simpleMethodElement, simpleMethods, xmlURL.toString());
             simpleMethods.put(simpleMethod.getMethodName(), simpleMethod);
         }
 
         return simpleMethods;
     }
 
+    protected static SimpleMethod compileSimpleMethod(Element simpleMethodElement, Map<String, SimpleMethod> simpleMethods, String location) {
+        if (UtilProperties.propertyValueEquals("webslinger-invoker.properties", "wrap-calls", "true")) {
+            Wrap<SimpleMethod> wrap = new Wrap<SimpleMethod>().fileName(location).wrappedClass(SimpleMethod.class);
+            wrap.loader(SimpleMethod.class.getClassLoader());
+            wrap.wrap(simpleMethodExecMethod);
+            SimpleMethod simpleMethod = wrap.newInstance(new Class<?>[] {Element.class, Map.class, String.class}, new Object[] {simpleMethodElement, simpleMethods, location});
+            return simpleMethod;
+        } else {
+            return new SimpleMethod(simpleMethodElement, simpleMethods, location);
+        }
+    }
+
     public static Map<String, SimpleMethod> getDirectSimpleMethods(String name, String content, String fromLocation) throws MiniLangException {
         Map<String, SimpleMethod> simpleMethods = simpleMethodsDirectCache.get(name);
 
@@ -278,7 +301,7 @@
 
         Element rootElement = document.getDocumentElement();
         for (Element simpleMethodElement: UtilXml.childElementList(rootElement, "simple-method")) {
-            SimpleMethod simpleMethod = new SimpleMethod(simpleMethodElement, simpleMethods, fromLocation);
+            SimpleMethod simpleMethod = compileSimpleMethod(simpleMethodElement, simpleMethods, fromLocation);
             simpleMethods.put(simpleMethod.getMethodName(), simpleMethod);
         }
 
@@ -905,6 +928,11 @@
                     Debug.logWarning("Operation element \"" + nodeName + "\" no recognized", module);
                 }
                 if (methodOp == null) continue;
+                if (UtilProperties.propertyValueEquals("webslinger-invoker.properties", "wrap-calls", "true")) {
+                    Wrap<MethodOperation> wrap = new Wrap<MethodOperation>().fileName(simpleMethod.getLocationAndName()).wrappedClass(methodOp.getClass());
+                    wrap.wrap(methodOperationExecMethod);
+                    methodOp = wrap.newInstance(new Class<?>[] {Element.class, SimpleMethod.class}, new Object[] {curOperElem, simpleMethod});
+                }
                 methodOperations.add(methodOp);
                 DeprecatedOperation depOp = methodOp.getClass().getAnnotation(DeprecatedOperation.class);
                 if (depOp != null) Debug.logInfo("The " + nodeName + " operation has been deprecated in favor of the " + depOp.value() + " operation; found use of this in [" + simpleMethod.getShortDescription() + "]: " + methodOp.rawString(), module);