cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r638186 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/
Date Tue, 18 Mar 2008 02:56:38 GMT
Author: dkulp
Date: Mon Mar 17 19:56:36 2008
New Revision: 638186

URL: http://svn.apache.org/viewvc?rev=638186&view=rev
Log:
Fixes to allow the use of the ASM generated wrapper helper (instead of reflection) in more
cases

Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelperCompiler.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java?rev=638186&r1=638185&r2=638186&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
Mon Mar 17 19:56:36 2008
@@ -189,7 +189,7 @@
             if (name.endsWith("package-info")) {
                 Package p = super.getPackage(name.substring(0, name.length() - 13));
                 if (p == null) {
-                    definePackage(name.substring(0, name.length() - 13),
+                    definePackage(name.substring(0, name.length() - 13).replace('/', '.'),
                                     null,
                                     null,
                                     null, 
@@ -200,7 +200,7 @@
                 }
             }
             
-            Class<?> ret = super.defineClass(name, bytes, 0, bytes.length);
+            Class<?> ret = super.defineClass(name.replace('/', '.'), bytes, 0, bytes.length);
             defined.put(name, ret);
             return ret;
         }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java?rev=638186&r1=638185&r2=638186&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java
Mon Mar 17 19:56:36 2008
@@ -42,6 +42,7 @@
     
     public abstract List<Object> getWrapperParts(Object o) throws Fault;
 
+    public abstract String getSignature();
     
     public static WrapperHelper createWrapperHelper(Class<?> wrapperType,
                                                     List<String> partNames,
@@ -265,7 +266,9 @@
             wrapperType = wt;
             objectFactory = of;
         }
-        
+        public String getSignature() {
+            return "" + System.identityHashCode(this);
+        }
         public Object createWrapperObject(List<?> lst) 
             throws Fault {
             

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelperCompiler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelperCompiler.java?rev=638186&r1=638185&r2=638186&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelperCompiler.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelperCompiler.java
Mon Mar 17 19:56:36 2008
@@ -85,9 +85,31 @@
         if (cw == null) {
             return null;
         }
-        String newClassName = wrapperType.getName() + "_WrapperTypeHelper";
+        int count = 1;
+        String newClassName = wrapperType.getName() + "_WrapperTypeHelper" + count;
         newClassName = newClassName.replaceAll("\\$", ".");
         newClassName = periodToSlashes(newClassName);
+
+        Class<?> cls = super.findClass(newClassName.replace('/', '.'), wrapperType);
+        while (cls != null) {
+            try {
+                WrapperHelper helper = WrapperHelper.class.cast(cls.newInstance());
+                if (!helper.getSignature().equals(computeSignature())) {
+                    count++;
+                    newClassName = wrapperType.getName() + "_WrapperTypeHelper" + count;
+                    newClassName = newClassName.replaceAll("\\$", ".");
+                    newClassName = periodToSlashes(newClassName);
+                    cls = super.findClass(newClassName.replace('/', '.'), wrapperType);
+                } else {
+                    return helper;
+                }
+            } catch (Exception e) {
+                return null;
+            }
+        }
+        
+        
+        
         cw.visit(Opcodes.V1_5,
                  Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER,
                  newClassName,
@@ -96,28 +118,63 @@
                  null);
         
         addConstructor(newClassName, cw, objectFactory == null ? null : objectFactory.getClass());
-        boolean b = addCreateWrapperObject(newClassName,
-                                           objectFactory == null ? null : objectFactory.getClass());
+        boolean b = addSignature();
+        if (b) {
+            addCreateWrapperObject(newClassName,
+                                   objectFactory == null ? null : objectFactory.getClass());
+        }
         if (b) {
             b = addGetWrapperParts(newClassName, wrapperType,
                            getMethods, fields, cw);
         }
-        
                                                                           
         try {
             if (b) {
                 cw.visitEnd();
                 byte bt[] = cw.toByteArray();                
-                Class<?> cl = loadClass(newClassName, wrapperType, bt);
+                Class<?> cl = loadClass(newClassName.replace('/', '.'), wrapperType,
bt);
                 Object o = cl.newInstance();
                 return WrapperHelper.class.cast(o);
             }
-        } catch (Exception e) {
+        } catch (Throwable e) {
             // ignore, we'll just fall down to reflection based
         }
         return null;
     }
     
+    private String computeSignature() {
+        StringBuilder b = new StringBuilder();
+        b.append(setMethods.length).append(':');
+        for (int x = 0; x < setMethods.length; x++) {
+            if (getMethods[x] == null) {
+                b.append("null,");
+            } else {
+                b.append(getMethods[x].getName()).append('/');
+                b.append(getMethods[x].getReturnType().getName()).append(',');          
     
+            }
+        }
+        return b.toString();
+    }
+    
+    private boolean addSignature() {
+        String sig = computeSignature();
+        if (sig == null) {
+            return false;
+        }
+        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC,
+                                          "getSignature", "()Ljava/lang/String;", null, null);
+        mv.visitCode();
+        Label l0 = new Label();
+        mv.visitLabel(l0);
+        mv.visitLdcInsn(sig);
+        mv.visitInsn(Opcodes.ARETURN);
+        Label l1 = new Label();
+        mv.visitLabel(l1);
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+        return true;
+    }
+
     private static void addConstructor(String newClassName, ClassWriter cw,  Class<?>
objectFactory) {
         
         if (objectFactory != null) {
@@ -182,7 +239,7 @@
             if (getMethods[x] == null) { 
                 if (setMethods[x] == null
                     && fields[x] == null) {
-                    // null placeholder, just skip it
+                    // null placeholder
                     continue;
                 } else {
                     return false;
@@ -258,7 +315,6 @@
         mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List",
                            "get", "(I)Ljava/lang/Object;");
         mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/List");
-        mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/List");
         mv.visitVarInsn(Opcodes.ASTORE, 4);
         mv.visitVarInsn(Opcodes.ALOAD, 3);
         Label nonNullLabel = new Label();
@@ -275,6 +331,8 @@
         } else {
             mv.visitVarInsn(Opcodes.ALOAD, 2);
             mv.visitVarInsn(Opcodes.ALOAD, 4);
+            mv.visitTypeInsn(Opcodes.CHECKCAST,
+                             getMethods[x].getReturnType().getName().replace('.', '/'));
             mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                                periodToSlashes(wrapperType.getName()),
                                setMethods[x].getName(),



Mime
View raw message