tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r662150 - in /incubator/tuscany/java/sca/modules/interface-java-jaxws/src: main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/ test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/
Date Sun, 01 Jun 2008 06:27:51 GMT
Author: rfeng
Date: Sat May 31 23:27:50 2008
New Revision: 662150

URL: http://svn.apache.org/viewvc?rev=662150&view=rev
Log:
Refactor and clean up the code-gen 

Modified:
    incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java
    incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java
    incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedClassLoader.java
    incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java
    incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGeneratorTestCase.java

Modified: incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java?rev=662150&r1=662149&r2=662150&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java
(original)
+++ incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/BaseBeanGenerator.java
Sat May 31 23:27:50 2008
@@ -19,6 +19,8 @@
 
 package org.apache.tuscany.sca.interfacedef.java.jaxws;
 
+import java.lang.reflect.Type;
+
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.FieldVisitor;
@@ -26,16 +28,41 @@
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 
-public class BaseBeanGenerator implements Opcodes {
+public abstract class BaseBeanGenerator implements Opcodes {
 
-    protected void defineClass(ClassWriter cw,
-                               String classDescriptor,
-                               String classSignature,
-                               String namespace,
-                               String name) {
+    public byte[] defineClass(ClassWriter cw,
+                              String classDescriptor,
+                              String classSignature,
+                              String namespace,
+                              String name,
+                              BeanProperty[] properties) {
+        // Declare the class
         declareClass(cw, classDescriptor);
-        annotateClass(cw, name, namespace);
+
+        // Compute the propOrder
+        String[] propOrder = null;
+        if (properties != null && properties.length > 0) {
+            int size = properties.length;
+            propOrder = new String[size];
+            for (int i = 0; i < size; i++) {
+                propOrder[i] = getFieldName(properties[i].getName());
+            }
+        }
+        // Annotate the class
+        annotateClass(cw, name, namespace, propOrder);
+
+        // Decalre the default constructor
         declareConstructor(cw, classSignature);
+        if (properties != null) {
+            for (BeanProperty p : properties) {
+                declareProperty(cw, classDescriptor, classSignature, p.getName(), p.getSignature(),
p
+                    .getGenericSignature());
+            }
+        }
+
+        // Close the generation
+        cw.visitEnd();
+        return cw.toByteArray();
     }
 
     protected void declareProperty(ClassWriter cw,
@@ -129,7 +156,7 @@
         mv.visitEnd();
     }
 
-    private static String capitalize(String name) {
+    protected static String capitalize(String name) {
         if (name == null || name.length() == 0) {
             return name;
         } else {
@@ -158,7 +185,7 @@
         cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classDescriptor, null, "java/lang/Object",
null);
     }
 
-    protected void annotateClass(ClassWriter cw, String name, String namespace) {
+    protected void annotateClass(ClassWriter cw, String name, String namespace, String[]
propOrder) {
         AnnotationVisitor av0;
         // @XmlRootElement
         av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlRootElement;", true);
@@ -173,6 +200,13 @@
         av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlType;", true);
         av0.visit("name", name);
         av0.visit("namespace", namespace);
+        if (propOrder != null) {
+            AnnotationVisitor pv = av0.visitArray("propOrder");
+            for (String p : propOrder) {
+                pv.visit(null, p);
+            }
+            pv.visitEnd();
+        }
         av0.visitEnd();
     }
 
@@ -180,14 +214,45 @@
                              String classSignature,
                              String namespace,
                              String name,
+                             BeanProperty[] properties,
                              ClassLoader parent) {
         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
-        defineClass(cw, classDescriptor, classSignature, namespace, name);
-        cw.visitEnd();
+        byte[] byteCode = defineClass(cw, classDescriptor, classSignature, namespace, name,
properties);
         String className = classDescriptor.replace('/', '.');
-        GeneratedClassLoader cl = new GeneratedClassLoader(parent, className, cw.toByteArray());
-        Class<?> generated = cl.getGeneratedClass();
+        GeneratedClassLoader cl = new GeneratedClassLoader(parent);
+        Class<?> generated = cl.getGeneratedClass(className, byteCode);
         return generated;
     }
 
+    public static class BeanProperty {
+        private String name;
+        private String signature;
+        private String genericSignature;
+
+        public BeanProperty(String name, Class<?> javaClass, Type type) {
+            super();
+            this.name = name;
+            this.signature = CodeGenerationHelper.getJAXWSSignature(javaClass);
+            this.genericSignature = CodeGenerationHelper.getJAXWSSignature(type);
+        }
+
+        public BeanProperty(String name, String signature, String genericSignature) {
+            super();
+            this.name = name;
+            this.signature = signature;
+            this.genericSignature = genericSignature;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getSignature() {
+            return signature;
+        }
+
+        public String getGenericSignature() {
+            return genericSignature;
+        }
+    }
 }

Modified: incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java?rev=662150&r1=662149&r2=662150&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java
(original)
+++ incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/FaultBeanGenerator.java
Sat May 31 23:27:50 2008
@@ -24,7 +24,6 @@
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
 import java.io.IOException;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -32,24 +31,20 @@
 import java.util.Map;
 import java.util.WeakHashMap;
 
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
 import javax.xml.ws.WebFault;
 
 import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
-import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
 
-public class FaultBeanGenerator implements Opcodes {
+public class FaultBeanGenerator extends BaseBeanGenerator {
     private final ClassWriter cw;
     private final Class<?> exceptionClass;
     private final String classDescriptor;
     private final String classSignature;
-    private byte[] content;
+    private String namespace;
+    private String name;
+    private byte[] byteCode;
     private Class<?> faultBeanClass;
 
     private static final Map<Class<?>, Class<?>> generatedClasses =
@@ -61,16 +56,17 @@
         this.exceptionClass = exceptionClass;
         this.classDescriptor = getFaultBeanName(exceptionClass);
         this.classSignature = "L" + classDescriptor + ";";
+        getElementName();
     }
 
-    protected List<PropertyDescriptor> getProperties() {
+    protected BeanProperty[] getProperties() {
         BeanInfo beanInfo;
         try {
             beanInfo = Introspector.getBeanInfo(exceptionClass);
         } catch (IntrospectionException e) {
             throw new IllegalArgumentException(e);
         }
-        List<PropertyDescriptor> props = new ArrayList<PropertyDescriptor>();
+        List<BeanProperty> props = new ArrayList<BeanProperty>();
         for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
             if (pd.getReadMethod() != null) {
                 String name = pd.getReadMethod().getName();
@@ -79,38 +75,27 @@
                     || "getLocalizedMessage".equals(name)) {
                     continue;
                 }
-                props.add(pd);
+                // Add the field
+                String field = pd.getName();
+                String desc = Type.getDescriptor(pd.getPropertyType());
+                String genericDesc = CodeGenerationHelper.getSignature(pd.getReadMethod().getGenericReturnType());
+                props.add(new BeanProperty(field, desc, genericDesc));
             }
         }
-        Collections.sort(props, new Comparator<PropertyDescriptor>() {
-            public int compare(PropertyDescriptor o1, PropertyDescriptor o2) {
+        Collections.sort(props, new Comparator<BeanProperty>() {
+            public int compare(BeanProperty o1, BeanProperty o2) {
                 return o1.getName().compareTo(o2.getName());
             }
         });
-        return props;
+        return props.toArray(new BeanProperty[0]);
     }
 
     public void generate() {
-        if (content == null) {
-            visit();
-            List<PropertyDescriptor> props = getProperties();
-            int size = props.size();
-            String[] propOrder = new String[size];
-            for (int i = 0; i < size; i++) {
-                propOrder[i] = props.get(i).getName();
-            }
-            annotateClass(propOrder);
-            for (PropertyDescriptor pd : props) {
-                visitProperty(pd);
-            }
-            visitEnd();
+        if (byteCode == null) {
+            byteCode = defineClass(cw, classDescriptor, classSignature, namespace, name,
getProperties());
         }
     }
 
-    protected void visit() {
-        WrapperBeanGenerator.declareClass(cw, classDescriptor);
-    }
-
     private static String getFaultBeanName(Class<?> exceptionClass) {
         String faultBeanName = null;
         WebFault webFault = exceptionClass.getAnnotation(WebFault.class);
@@ -130,75 +115,25 @@
         return faultBeanName;
     }
 
-    protected void visitProperty(PropertyDescriptor pd) {
-        Method getter = pd.getReadMethod();
-        if (getter == null) {
-            return;
-        }
-        String name = getter.getName();
-
-        if ("getClass".equals(name) || "getStackTrace".equals(name)
-            || "getCause".equals(name)
-            || "getLocalizedMessage".equals(name)) {
-            return;
-        }
-
-        // Add the field
-        String field = pd.getName();
-        String desc = Type.getDescriptor(pd.getPropertyType());
-        String genericDesc = CodeGenerationHelper.getSignature(pd.getReadMethod().getGenericReturnType());
-        
-        WrapperBeanGenerator.declareProperty(cw, classDescriptor, classSignature, field,
desc, genericDesc);
-    }
-
-    protected void visitEnd() {
-        WrapperBeanGenerator.declareConstructor(cw, classSignature);
-        cw.visitEnd();
-        content = cw.toByteArray();
-    }
-
-    protected void annotateClass(String[] propOrder) {
+    private void getElementName() {
         WebFault webFault = exceptionClass.getAnnotation(WebFault.class);
-        String ns = null, name = null;
         if (webFault != null) {
-            ns = webFault.targetNamespace();
+            namespace = webFault.targetNamespace();
             name = webFault.name();
         }
-        if (ns == null) {
-            ns = JavaInterfaceUtil.getNamespace(exceptionClass);
+        if (namespace == null) {
+            namespace = JavaInterfaceUtil.getNamespace(exceptionClass);
         }
         if (name == null) {
             name = exceptionClass.getSimpleName();
         }
-        String desc = Type.getDescriptor(XmlRootElement.class);
-        AnnotationVisitor av = cw.visitAnnotation(desc, true);
-        av.visit("namespace", ns);
-        av.visit("name", name);
-        av.visitEnd();
-
-        desc = Type.getDescriptor(XmlType.class);
-        av = cw.visitAnnotation(desc, true);
-        av.visit("namespace", ns);
-        av.visit("name", name);
-        AnnotationVisitor pv = av.visitArray("propOrder");
-        for (String p : propOrder) {
-            pv.visit(null, p);
-        }
-        pv.visitEnd();
-        av.visitEnd();
-
-        desc = Type.getDescriptor(XmlAccessorType.class);
-        av = cw.visitAnnotation(desc, true);
-        av.visitEnum("value", Type.getDescriptor(XmlAccessType.class), "FIELD");
-        av.visitEnd();
-
     }
 
     public Class<?> getFaultBeanClass() {
-        if (faultBeanClass == null && content != null) {
+        if (faultBeanClass == null && byteCode != null) {
             faultBeanClass =
-                new GeneratedClassLoader(exceptionClass.getClassLoader(), classDescriptor.replace('/',
'.'), content)
-                    .getGeneratedClass();
+                new GeneratedClassLoader(exceptionClass.getClassLoader()).getGeneratedClass(classDescriptor
+                    .replace('/', '.'), byteCode);
         }
         return faultBeanClass;
     }
@@ -207,8 +142,8 @@
         return classDescriptor.replace('/', '.');
     }
 
-    public byte[] getContent() {
-        return content;
+    public byte[] getByteCode() {
+        return byteCode;
     }
 
     public static Class<?> generateFaultBeanClass(Class<? extends Throwable>
exceptionClass) throws IOException {
@@ -228,7 +163,7 @@
         synchronized (exceptionClass) {
             FaultBeanGenerator generator = new FaultBeanGenerator(exceptionClass);
             generator.generate();
-            return generator.getContent();
+            return generator.getByteCode();
         }
     }
 }

Modified: incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedClassLoader.java?rev=662150&r1=662149&r2=662150&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedClassLoader.java
(original)
+++ incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedClassLoader.java
Sat May 31 23:27:50 2008
@@ -24,36 +24,46 @@
 import java.util.Map;
 
 public class GeneratedClassLoader extends SecureClassLoader {
-    private String className;
-    private byte[] content;
-    private Class<?> cls;
-    
-    private static class GeneratedClass {
+    private class GeneratedClass {
         private String className;
-        private byte[] content;
+        private byte[] byteCode;
         private Class<?> cls;
+
+        public GeneratedClass(String className, byte[] byteCode) {
+            super();
+            this.className = className;
+            this.byteCode = byteCode;
+        }
+
+        public synchronized Class<?> getGeneratedClass() {
+            if (cls == null) {
+                cls = defineClass(className, byteCode, 0, byteCode.length);
+            }
+            return cls;
+        }
     }
-    
+
     private Map<String, GeneratedClass> generatedClasses = new HashMap<String, GeneratedClass>();
 
-    public GeneratedClassLoader(ClassLoader parentLoader, String className, byte[] content)
{
+    public GeneratedClassLoader(ClassLoader parentLoader) {
         super(parentLoader);
-        this.className = className;
-        this.content = content;
     }
 
     @Override
     protected Class<?> findClass(String className) throws ClassNotFoundException {
-        if (this.className.equals(className)) {
-            return getGeneratedClass();
+        GeneratedClass cls = generatedClasses.get(className);
+        if (cls != null) {
+            return cls.getGeneratedClass();
         }
         return super.findClass(className);
     }
 
-    public synchronized Class<?> getGeneratedClass() {
+    public synchronized Class<?> getGeneratedClass(String className, byte[] byteCode)
{
+        GeneratedClass cls = generatedClasses.get(className);
         if (cls == null) {
-            cls = defineClass(className, content, 0, content.length);
+            cls = new GeneratedClass(className, byteCode);
+            generatedClasses.put(className, cls);
         }
-        return cls;
+        return cls.getGeneratedClass();
     }
 }

Modified: incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java?rev=662150&r1=662149&r2=662150&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java
(original)
+++ incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGenerator.java
Sat May 31 23:27:50 2008
@@ -19,35 +19,18 @@
 
 package org.apache.tuscany.sca.interfacedef.java.jaxws;
 
-import static org.apache.tuscany.sca.interfacedef.java.jaxws.CodeGenerationHelper.getJAXWSSignature;
-import static org.apache.tuscany.sca.interfacedef.java.jaxws.CodeGenerationHelper.getSignature;
-
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
-import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.FieldVisitor;
-import org.objectweb.asm.Label;
-import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.Opcodes;
-
-public class WrapperBeanGenerator implements Opcodes {
-
-    private static void processClass(ClassWriter cw,
-                                     String wrapperClassDescriptor,
-                                     String wrapperClassSignature,
-                                     String wrapperNamespace,
-                                     String wrapperName) {
-        declareClass(cw, wrapperClassDescriptor);
-        annotateClass(cw, wrapperName, wrapperNamespace);
-        declareConstructor(cw, wrapperClassSignature);
-    }
 
-    public static List<Class<?>> generateWrapperBeans(Class<?> sei) {
+public class WrapperBeanGenerator extends BaseBeanGenerator {
+
+
+    public List<Class<?>> generateWrapperBeans(Class<?> sei) {
         List<Class<?>> classes = new ArrayList<Class<?>>();
         for (Method m : sei.getMethods()) {
             if (m.getDeclaringClass() == Object.class) {
@@ -60,7 +43,7 @@
 
     }
 
-    private static Class<?> generateRequestWrapper(Class<?> sei, Method m) {
+    private Class<?> generateRequestWrapper(Class<?> sei, Method m) {
         String wrapperNamespace = JavaInterfaceUtil.getNamespace(sei);
 
         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
@@ -68,31 +51,23 @@
         String wrapperClassName = sei.getPackage().getName() + ".jaxws." + wrapperName;
         String wrapperClassDescriptor = wrapperClassName.replace('.', '/');
         String wrapperClassSignature = "L" + wrapperClassDescriptor + ";";
-        processClass(cw, wrapperClassDescriptor, wrapperClassSignature, wrapperNamespace,
m.getName());
+
         Class<?>[] paramTypes = m.getParameterTypes();
         Type[] genericParamTypes = m.getGenericParameterTypes();
+        BeanProperty[] properties = new BeanProperty[paramTypes.length];
         for (int i = 0; i < paramTypes.length; i++) {
             String propName = "arg" + i;
-            String propClassSignature = getSignature(paramTypes[i]);
-            String propTypeSignature = getJAXWSSignature(genericParamTypes[i]);
-            //            if (paramTypes[i].isPrimitive()) {
-            //                propTypeSignature = null;
-            //            }
-            declareProperty(cw,
-                            wrapperClassDescriptor,
-                            wrapperClassSignature,
-                            propName,
-                            propClassSignature,
-                            propTypeSignature);
+            properties[i] = new BeanProperty(propName, paramTypes[i], genericParamTypes[i]);
         }
-        cw.visitEnd();
+
+        defineClass(cw, wrapperClassDescriptor, wrapperClassSignature, wrapperNamespace,
m.getName(), properties);
         GeneratedClassLoader cl =
-            new GeneratedClassLoader(Thread.currentThread().getContextClassLoader(), wrapperClassName,
cw.toByteArray());
-        Class<?> generated = cl.getGeneratedClass();
+            new GeneratedClassLoader(sei.getClassLoader());
+        Class<?> generated = cl.getGeneratedClass(wrapperClassName, cw.toByteArray());
         return generated;
     }
 
-    private static Class<?> generateResponseWrapper(Class<?> sei, Method m) {
+    private Class<?> generateResponseWrapper(Class<?> sei, Method m) {
         String wrapperNamespace = JavaInterfaceUtil.getNamespace(sei);
 
         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
@@ -100,173 +75,19 @@
         String wrapperClassName = sei.getPackage().getName() + ".jaxws." + wrapperName;
         String wrapperClassDescriptor = wrapperClassName.replace('.', '/');
         String wrapperClassSignature = "L" + wrapperClassDescriptor + ";";
-        processClass(cw, wrapperClassDescriptor, wrapperClassSignature, wrapperNamespace,
m.getName() + "Response");
+        
         Class<?> returnType = m.getReturnType();
+        BeanProperty[] properties = null;
         if (returnType != void.class) {
             Type genericReturnType = m.getGenericReturnType();
             String propName = "return";
-            String propClassSignature = getSignature(returnType);
-            String propTypeSignature = getJAXWSSignature(genericReturnType);
-            //        if (returnType.isPrimitive()) {
-            //            propTypeSignature = null;
-            //        }
-            declareProperty(cw,
-                            wrapperClassDescriptor,
-                            wrapperClassSignature,
-                            propName,
-                            propClassSignature,
-                            propTypeSignature);
+            properties = new BeanProperty[] {new BeanProperty(propName, returnType, genericReturnType)};
         }
-        cw.visitEnd();
+        byte[] byteCode = defineClass(cw, wrapperClassDescriptor, wrapperClassSignature,
wrapperNamespace, m.getName() + "Response", properties);
         GeneratedClassLoader cl =
-            new GeneratedClassLoader(Thread.currentThread().getContextClassLoader(), wrapperClassName,
cw.toByteArray());
-        Class<?> generated = cl.getGeneratedClass();
+            new GeneratedClassLoader(sei.getClassLoader());
+        Class<?> generated = cl.getGeneratedClass(wrapperClassName, byteCode);
         return generated;
     }
 
-    public static void declareProperty(ClassWriter cw,
-                                       String classDescriptor,
-                                       String wrapperClassSignature,
-                                       String propName,
-                                       String propClassSignature,
-                                       String propTypeSignature) {
-        if (propClassSignature.equals(propTypeSignature)) {
-            propTypeSignature = null;
-        }
-        declareField(cw, propName, propClassSignature, propTypeSignature);
-        decalreGetter(cw, classDescriptor, wrapperClassSignature, propName, propClassSignature,
propTypeSignature);
-        declareSetter(cw, classDescriptor, wrapperClassSignature, propName, propClassSignature,
propTypeSignature);
-    }
-
-    private static String getFieldName(String propName) {
-        if ("return".equals(propName)) {
-            return "_return";
-        } else {
-            return propName;
-        }
-    }
-
-    private static void declareField(ClassWriter cw,
-                                     String propName,
-                                     String propClassSignature,
-                                     String propTypeSignature) {
-        FieldVisitor fv;
-        AnnotationVisitor av0;
-        {
-            fv = cw.visitField(ACC_PRIVATE, getFieldName(propName), propClassSignature, propTypeSignature,
null);
-            {
-                av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true);
-                av0.visit("name", propName);
-                av0.visit("namespace", "");
-                av0.visitEnd();
-            }
-            fv.visitEnd();
-        }
-    }
-
-    private static void declareSetter(ClassWriter cw,
-                                      String classDescriptor,
-                                      String wrapperClassSignature,
-                                      String propName,
-                                      String propClassSignature,
-                                      String propTypeSignature) {
-        MethodVisitor mv;
-        {
-            mv =
-                cw.visitMethod(ACC_PUBLIC,
-                               "set" + capitalize(propName),
-                               "(" + propClassSignature + ")V",
-                               propTypeSignature == null ? null : "(" + propTypeSignature
+ ")V",
-                               null);
-            mv.visitCode();
-            Label l0 = new Label();
-            mv.visitLabel(l0);
-            // mv.visitLineNumber(57, l0);
-            mv.visitVarInsn(ALOAD, 0);
-            mv.visitVarInsn(CodeGenerationHelper.getLoadOPCode(propClassSignature), 1);
-            mv.visitFieldInsn(PUTFIELD, classDescriptor, getFieldName(propName), propClassSignature);
-            Label l1 = new Label();
-            mv.visitLabel(l1);
-            // mv.visitLineNumber(58, l1);
-            mv.visitInsn(RETURN);
-            Label l2 = new Label();
-            mv.visitLabel(l2);
-            mv.visitLocalVariable("this", wrapperClassSignature, null, l0, l2, 0);
-            mv.visitLocalVariable(getFieldName(propName), propClassSignature, propTypeSignature,
l0, l2, 1);
-            mv.visitMaxs(3, 3);
-            mv.visitEnd();
-        }
-    }
-
-    private static void decalreGetter(ClassWriter cw,
-                                      String classDescriptor,
-                                      String wrapperClassSignature,
-                                      String propName,
-                                      String propClassSignature,
-                                      String propTypeSignature) {
-        String getterName = ("B".equals(propClassSignature) ? "is" : "get") + capitalize(propName);
-        MethodVisitor mv =
-            cw.visitMethod(ACC_PUBLIC, getterName, "()" + propClassSignature, propTypeSignature
== null ? null
-                : "()" + propTypeSignature, null);
-        mv.visitCode();
-        Label l0 = new Label();
-        mv.visitLabel(l0);
-        // mv.visitLineNumber(48, l0);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitFieldInsn(GETFIELD, classDescriptor, getFieldName(propName), propClassSignature);
-        mv.visitInsn(CodeGenerationHelper.getReturnOPCode(propClassSignature));
-        Label l1 = new Label();
-        mv.visitLabel(l1);
-        mv.visitLocalVariable("this", wrapperClassSignature, null, l0, l1, 0);
-        mv.visitMaxs(2, 1);
-        mv.visitEnd();
-    }
-
-    private static String capitalize(String name) {
-        if (name == null || name.length() == 0) {
-            return name;
-        } else {
-            return Character.toUpperCase(name.charAt(0)) + name.substring(1);
-        }
-    }
-
-    public static void declareConstructor(ClassWriter cw, String wrapperClassSignature) {
-        MethodVisitor mv;
-        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
-        mv.visitCode();
-        Label l0 = new Label();
-        mv.visitLabel(l0);
-        // mv.visitLineNumber(37, l0);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
-        mv.visitInsn(RETURN);
-        Label l1 = new Label();
-        mv.visitLabel(l1);
-        mv.visitLocalVariable("this", wrapperClassSignature, null, l0, l1, 0);
-        mv.visitMaxs(1, 1);
-        mv.visitEnd();
-    }
-
-    public static void declareClass(ClassWriter cw, String classDescriptor) {
-        cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classDescriptor, null, "java/lang/Object",
null);
-    }
-
-    private static void annotateClass(ClassWriter cw, String wrapperName, String wrapperNamespace)
{
-        AnnotationVisitor av0;
-        // @XmlRootElement
-        av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlRootElement;", true);
-        av0.visit("name", wrapperName);
-        av0.visit("namespace", wrapperNamespace);
-        av0.visitEnd();
-        // @XmlAccessorType
-        av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlAccessorType;", true);
-        av0.visitEnum("value", "Ljavax/xml/bind/annotation/XmlAccessType;", "FIELD");
-        av0.visitEnd();
-        // @XmlType
-        av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlType;", true);
-        av0.visit("name", wrapperName);
-        av0.visit("namespace", wrapperNamespace);
-        av0.visitEnd();
-    }
-
 }

Modified: incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGeneratorTestCase.java?rev=662150&r1=662149&r2=662150&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGeneratorTestCase.java
(original)
+++ incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/WrapperBeanGeneratorTestCase.java
Sat May 31 23:27:50 2008
@@ -40,7 +40,7 @@
 public class WrapperBeanGeneratorTestCase {
     @Test
     public void testGenerate() throws Exception {
-        List<Class<?>> classes = WrapperBeanGenerator.generateWrapperBeans(TestInterface.class);
+        List<Class<?>> classes = new WrapperBeanGenerator().generateWrapperBeans(TestInterface.class);
         for (Class<?> cls : classes) {
             for (Field f : cls.getDeclaredFields()) {
                 // System.out.println(f.getName());
@@ -64,7 +64,7 @@
 
     @Test
     public void testGenerateSchema() throws Exception {
-        List<Class<?>> classes = WrapperBeanGenerator.generateWrapperBeans(TestInterface.class);
+        List<Class<?>> classes = new WrapperBeanGenerator().generateWrapperBeans(TestInterface.class);
         JAXBContext context = JAXBContext.newInstance(classes.toArray(new Class[0]));
         Map<String, DOMResult> results = JAXBTypeHelper.generateSchema(context);
         Node2String t = new Node2String();



Mime
View raw message