You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2007/12/12 09:14:38 UTC

svn commit: r603508 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ tools/javato/ws/src/test...

Author: ema
Date: Wed Dec 12 00:14:37 2007
New Revision: 603508

URL: http://svn.apache.org/viewvc?rev=603508&view=rev
Log:
Simplified generating getter and setter method generation in WrapperClassGenerator
[CXF-1178] Support @XMlJavaTypeAdapter annotation in SEI

Added:
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/CurrencyAdapter.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Greeter.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/GreeterImpl.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Money.java
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java?rev=603508&r1=603507&r2=603508&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java Wed Dec 12 00:14:37 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxws;
 
+
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
@@ -94,8 +95,8 @@
     public Set<Class<?>> genearte() {
         for (OperationInfo opInfo : interfaceInfo.getOperations()) {
             if (opInfo.isUnwrappedCapable()
-                && opInfo.getUnwrappedOperation().getProperty(ReflectionServiceFactoryBean.WRAPPERGEN_NEEDED) 
-                != null) {
+                && (opInfo.getUnwrappedOperation()
+                    .getProperty(ReflectionServiceFactoryBean.WRAPPERGEN_NEEDED) != null)) {
                 Method method = (Method)opInfo.getProperty(ReflectionServiceFactoryBean.METHOD);
                 MessageInfo messageInfo = opInfo.getUnwrappedOperation().getInput();
                 Class requestWrapperClass = createWrapperClass(messageInfo, method, true);
@@ -192,9 +193,10 @@
             filedDescriptor = classCode.substring(0, classCode.lastIndexOf(";")) + "<"
                               + getClassCode(genericTypeClass) + ">;";
         }
-        String fieldName = JavaUtils.makeNonJavaKeyword(name);
-
-        FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldName, classCode, filedDescriptor, null);
+        String fieldName = JavaUtils.isJavaKeyword(name) ? JavaUtils.makeNonJavaKeyword(name) : name;
+        
+        FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldName, 
+                                        classCode, filedDescriptor, null);
         AnnotationVisitor av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true);
         av0.visit("name", name);
         av0.visit("namespace", "");
@@ -208,8 +210,13 @@
                 av0.visitEnd();
             } else if (ann instanceof XmlJavaTypeAdapter) {
                 av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapter;", true);
-                av0.visit("value", ((XmlJavaTypeAdapter)ann).value());
-                av0.visit("type", ((XmlJavaTypeAdapter)ann).type());
+                XmlJavaTypeAdapter adapter = (XmlJavaTypeAdapter)ann;
+                if (adapter.value() != null) {
+                    av0.visit("value", org.objectweb.asm.Type.getType(getClassCode(adapter.value())));
+                }
+                if (adapter.type() != javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT.class) {
+                    av0.visit("type", org.objectweb.asm.Type.getType(getClassCode(adapter.type())));
+                }
                 av0.visitEnd();
             } else if (ann instanceof XmlAttachmentRef) {
                 av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlAttachmentRef;", true);
@@ -228,34 +235,21 @@
         MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "get" + methodName, "()" + classCode, null,
                                           null);
         mv.visitCode();
-        Label l2 = new Label();
-        mv.visitLabel(l2);
+
         mv.visitVarInsn(Opcodes.ALOAD, 0);
         mv.visitFieldInsn(Opcodes.GETFIELD, classFileName, fieldName, classCode);
-        mv.visitInsn(Opcodes.ARETURN);
-        Label l3 = new Label();
-        mv.visitLabel(l3);
-        mv.visitLocalVariable("this", classCode, null, l2, l3, 0);
-        mv.visitMaxs(1, 1);
+        mv.visitInsn(org.objectweb.asm.Type.getType(classCode).getOpcode(Opcodes.IRETURN));
+        mv.visitMaxs(0, 0);
         mv.visitEnd();
-
+        
         mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "set" + methodName, "(" + classCode + ")V", null, null);
         mv.visitCode();
-        Label l4 = new Label();
-        mv.visitLabel(l4);
         mv.visitVarInsn(Opcodes.ALOAD, 0);
-        mv.visitVarInsn(Opcodes.ALOAD, 1);
-        mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldName, classCode);
-        Label l5 = new Label();
-        mv.visitLabel(l5);
+        org.objectweb.asm.Type setType = org.objectweb.asm.Type.getType(classCode);
+        mv.visitVarInsn(setType.getOpcode(Opcodes.ILOAD), 1);
+        mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldName, classCode);       
         mv.visitInsn(Opcodes.RETURN);
-        Label l6 = new Label();
-        mv.visitLabel(l6);
-
-        mv.visitLocalVariable("this", "L" + classFileName + ";", null, l4, l6, 0);
-        mv.visitLocalVariable(fieldName, classCode, null, l4, l6, 1);
-        mv.visitMaxs(2, 2);
-
+        mv.visitMaxs(0, 0);
         mv.visitEnd();
 
     }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java?rev=603508&r1=603507&r2=603508&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java Wed Dec 12 00:14:37 2007
@@ -85,6 +85,10 @@
     
     private List<WebServiceFeature> wsFeatures;
 
+    private boolean wrapperBeanGenerated;
+    private Set<Class<?>> wrapperClasses;
+    
+    
     public JaxWsServiceFactoryBean() {
         getIgnoredClasses().add(Service.class.getName());
         
@@ -523,6 +527,13 @@
     
     @Override
     protected Set<Class<?>> getExtraClass() {
+        if (!wrapperBeanGenerated) {
+            wrapperClasses = generatedWrapperBeanClass();
+        } 
+        return wrapperClasses;
+    }
+    
+    private Set<Class<?>> generatedWrapperBeanClass() {
         ServiceInfo serviceInfo = getService().getServiceInfos().get(0);
         WrapperClassGenerator wrapperGen = new WrapperClassGenerator(serviceInfo.getInterface());
         return wrapperGen.genearte();

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=603508&r1=603507&r2=603508&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java Wed Dec 12 00:14:37 2007
@@ -307,7 +307,6 @@
         if (Proxy.isProxyClass(this.getServiceClass())) {
             LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
         }
-
         ServiceInfo serviceInfo = new ServiceInfo();
         SchemaCollection col = serviceInfo.getXmlSchemaCollection();
         col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());
@@ -323,9 +322,11 @@
 
         createInterface(serviceInfo);
 
+
         for (ServiceInfo si : getService().getServiceInfos()) {
-            if (getExtraClass() != null) {
-                si.setProperty(EXTRA_CLASS, getExtraClass());
+            Set<?> wrapperClasses = this.getExtraClass();
+            if (wrapperClasses != null) {
+                serviceInfo.setProperty(EXTRA_CLASS, wrapperClasses);
             }
         }
         

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java?rev=603508&r1=603507&r2=603508&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java (original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java Wed Dec 12 00:14:37 2007
@@ -303,6 +303,21 @@
                    str.indexOf(":swaRef") > -1 && str.indexOf(swaImport) > -1);
 
     }
+    
+    
+    @Test
+    public void testXmlJavaTypeAdapter() throws Exception {
+        String[] args = new String[] {"-o", output.getPath() + "/xmladapter.wsdl", "-verbose",
+                                      "-wsdl", "org.apache.xmladapter.GreeterImpl"};
+       
+        JavaToWS.main(args);
+        File file = new File(output.getPath() + "/xmladapter.wsdl");
+        String str = FileUtils.getStringFromFile(file);
+        String expected = "<xs:element  minOccurs=\"0\"  name=\"arg0\"  type=\"xs:string\"/>";
+        assertTrue("@XmlJavaTypeAdapter in SEI dose not take effect",
+                   str.indexOf(expected) > -1);
+            
+    }
 
 
     protected String getClassPath() throws URISyntaxException {

Added: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/CurrencyAdapter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/CurrencyAdapter.java?rev=603508&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/CurrencyAdapter.java (added)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/CurrencyAdapter.java Wed Dec 12 00:14:37 2007
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+package org.apache.xmladapter;
+
+import java.util.Currency;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+public class CurrencyAdapter extends XmlAdapter<String, Currency> {
+    public Currency unmarshal(String val) throws Exception {
+        return Currency.getInstance(val);
+    }
+
+    public String marshal(Currency val) throws Exception {
+        return val.toString();
+    }
+}

Added: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Greeter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Greeter.java?rev=603508&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Greeter.java (added)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Greeter.java Wed Dec 12 00:14:37 2007
@@ -0,0 +1,36 @@
+/**
+ * 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.
+ */
+
+package org.apache.xmladapter;
+
+import java.util.Currency;
+
+import javax.jws.WebParam;
+import javax.jws.WebService;
+// import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+@WebService
+public interface Greeter {
+    
+    int sayHi(@WebParam
+                @XmlJavaTypeAdapter(value = org.apache.xmladapter.CurrencyAdapter.class)
+                Currency tickerSymbol);
+
+}

Added: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/GreeterImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/GreeterImpl.java?rev=603508&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/GreeterImpl.java (added)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/GreeterImpl.java Wed Dec 12 00:14:37 2007
@@ -0,0 +1,29 @@
+/**
+ * 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.
+ */
+package org.apache.xmladapter;
+
+import java.util.Currency;
+
+@javax.jws.WebService(endpointInterface = "org.apache.xmladapter.Greeter")
+public class GreeterImpl implements Greeter {
+    public int sayHi(Currency tickerSymbol) {
+        return 100;
+    }
+
+}
\ No newline at end of file

Added: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Money.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Money.java?rev=603508&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Money.java (added)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/xmladapter/Money.java Wed Dec 12 00:14:37 2007
@@ -0,0 +1,34 @@
+/**
+ * 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.
+ */
+
+package org.apache.xmladapter;
+
+import java.util.Currency;
+
+public class Money {
+    protected  Currency currency;
+    
+    public Currency getCurrency() {
+        return currency;
+    }
+
+    public void setCurrency(Currency val) {
+        currency = val;
+    }
+}