cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r610277 - in /incubator/cxf/trunk/tools: common/src/main/java/org/apache/cxf/tools/common/model/ common/src/test/java/org/apache/cxf/tools/common/model/ javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ javato...
Date Wed, 09 Jan 2008 06:05:04 GMT
Author: mmao
Date: Tue Jan  8 22:04:56 2008
New Revision: 610277

URL: http://svn.apache.org/viewvc?rev=610277&view=rev
Log:
CXF-1359
  * Fix the Holder in the generated Wrapper beans
  * Use the field name for the getter/setter in the wrapper beans


Added:
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/AddressingFeatureException.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/WSAImpl2.java
Modified:
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java
    incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java?rev=610277&r1=610276&r2=610277&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java
(original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaClass.java
Tue Jan  8 22:04:56 2008
@@ -44,7 +44,7 @@
     }
 
     public JavaMethod appendGetter(JavaField field) {
-        String getterName = "get" + StringUtils.capitalize(field.getParaName());
+        String getterName = "get" + StringUtils.capitalize(field.getName());
         JavaMethod jMethod = new JavaMethod(this);
         jMethod.setName(getterName);
         jMethod.setReturn(new JavaReturn(field.getParaName(),
@@ -63,7 +63,7 @@
     }
 
     public JavaMethod appendSetter(JavaField field) {
-        String setterName = "set" + StringUtils.capitalize(field.getParaName());
+        String setterName = "set" + StringUtils.capitalize(field.getName());
         JavaMethod jMethod = new JavaMethod(this);
         jMethod.setReturn(new JavaReturn("return", "void", null));
         String paramName = getSetterParamName(field.getParaName());

Modified: incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java?rev=610277&r1=610276&r2=610277&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java
(original)
+++ incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaClassTest.java
Tue Jan  8 22:04:56 2008
@@ -74,13 +74,13 @@
         clz = new JavaClass();
         clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHiResponse");
         getter = clz.appendGetter(field);
-        assertEquals("get_return", getter.getName());
+        assertEquals("getReturn", getter.getName());
         assertEquals("String[]",
                      getter.getReturn().getClassName());
         assertEquals("_return", getter.getReturn().getName());
 
         setter = clz.appendSetter(field);
-        assertEquals("set_return", setter.getName());
+        assertEquals("setReturn", setter.getName());
         assertEquals("void", setter.getReturn().getClassName());
         assertEquals("_return", getter.getReturn().getName());
         assertEquals("String[]",

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java?rev=610277&r1=610276&r2=610277&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
Tue Jan  8 22:04:56 2008
@@ -21,6 +21,8 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -61,24 +63,36 @@
     protected List<JavaField> buildFields(final Method method, final MessageInfo message)
{
         List<JavaField> fields = new ArrayList<JavaField>();
         String name;
-        String type;
+        String type = "Object";
 
-        final Class[] paramClasses = method.getParameterTypes();
+        final Type[] paramClasses = method.getGenericParameterTypes();
         for (MessagePartInfo mpi : message.getMessageParts()) {
             int idx = mpi.getIndex();
             name = mpi.getName().getLocalPart();
-            Class clz = paramClasses[idx];
-            if (clz.isArray()) {
-                if (isBuiltInTypes(clz.getComponentType())) {
-                    type = clz.getComponentType().getSimpleName() + "[]";
+            Type t = paramClasses[idx];
+
+
+            if (t instanceof Class) {
+                Class clz = (Class) t;
+                if (clz.isArray()) {
+                    if (isBuiltInTypes(clz.getComponentType())) {
+                        type = clz.getComponentType().getSimpleName() + "[]";
+                    } else {
+                        type = clz.getComponentType().getName() + "[]";
+                    }
                 } else {
-                    type = clz.getComponentType().getName() + "[]";
+                    type = clz.getName();
+                }
+            } else if (t instanceof ParameterizedType) {
+                ParameterizedType pt = (ParameterizedType) t;
+                if (pt.getActualTypeArguments().length > 0
+                    && pt.getActualTypeArguments()[0] instanceof Class) {
+                    type = ((Class)pt.getActualTypeArguments()[0]).getName();
                 }
-            } else {
-                type = clz.getName();
             }
+
             JavaField field = new JavaField(name, type, "");
-            field.setTargetNamespace("");           
+            field.setTargetNamespace("");
             List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method, idx);
             field.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
             fields.add(field);

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java?rev=610277&r1=610276&r2=610277&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java
Tue Jan  8 22:04:56 2008
@@ -21,6 +21,8 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -33,7 +35,7 @@
 import org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass;
 
 
-public final class ResponseWrapper extends Wrapper { 
+public final class ResponseWrapper extends Wrapper {
     @Override
     public void setOperationInfo(final OperationInfo op) {
         super.setOperationInfo(op);
@@ -41,13 +43,13 @@
         setClassName((String)op.getOutput().getMessageParts().get(0)
                          .getProperty("RESPONSE.WRAPPER.CLASSNAME"));
     }
-   
+
     @Override
     public boolean isWrapperAbsent(final Method method) {
         javax.xml.ws.ResponseWrapper resWrapper = method.getAnnotation(javax.xml.ws.ResponseWrapper.class);
         return getClassName() == null && (resWrapper == null || StringUtils.isEmpty(resWrapper.className()));
     }
-    
+
     public String getWrapperTns(Method method) {
         javax.xml.ws.RequestWrapper reqWrapper = method.getAnnotation(javax.xml.ws.RequestWrapper.class);
         if (reqWrapper != null) {
@@ -55,25 +57,29 @@
         }
         return null;
     }
-    
+
     @Override
     protected List<JavaField> buildFields() {
         return buildFields(getMethod(), getOperationInfo().getUnwrappedOperation().getOutput());
     }
-    
+
     protected List<JavaField> buildFields(final Method method, final MessageInfo message)
{
         List<JavaField> fields = new ArrayList<JavaField>();
-        
+
         final Class<?> returnType = method.getReturnType();
         JavaField field = new JavaField();
         if (CollectionUtils.isEmpty(message.getMessageParts())) {
             return fields;
         }
         MessagePartInfo part = message.getMessageParts().get(0);
+
         field.setName(part.getName().getLocalPart());
-        
+
+        boolean hasReturnType = false;
+
         if (!returnType.isAssignableFrom(void.class)) {
-            String type;            
+            hasReturnType = true;
+            String type;
             if (returnType.isArray()) {
                 if (isBuiltInTypes(returnType.getComponentType())) {
                     type = returnType.getComponentType().getSimpleName() + "[]";
@@ -87,34 +93,45 @@
             field.setType(type);
             field.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
             field.setTargetNamespace("");
-            
+
         }
         fields.add(field);
-        
-        final Class[] paramClasses = method.getParameterTypes();
+
+        final Type[] paramClasses = method.getGenericParameterTypes();
         for (MessagePartInfo mpi : message.getMessageParts()) {
-            int idx = mpi.getIndex();
-            if (idx > 0) {
+            int idx = hasReturnType ? mpi.getIndex() - 1 : mpi.getIndex();
+            if (idx >= 0) {
                 String name = mpi.getName().getLocalPart();
-                String type;
-                Class clz = paramClasses[idx - 1];
-                if (clz.isArray()) {
-                    if (isBuiltInTypes(clz.getComponentType())) {
-                        type = clz.getComponentType().getSimpleName() + "[]";
+                String type = "Object";
+
+                Type t = paramClasses[idx];
+                if (t instanceof Class) {
+                    Class clz = (Class) t;
+                    if (clz.isArray()) {
+                        if (isBuiltInTypes(clz.getComponentType())) {
+                            type = clz.getComponentType().getSimpleName() + "[]";
+                        } else {
+                            type = clz.getComponentType().getName() + "[]";
+                        }
                     } else {
-                        type = clz.getComponentType().getName() + "[]";
+                        type = clz.getName();
+                    }
+                } else if (t instanceof ParameterizedType) {
+                    ParameterizedType pt = (ParameterizedType) t;
+                    if (pt.getActualTypeArguments().length > 0
+                        && pt.getActualTypeArguments()[0] instanceof Class) {
+                        type = ((Class)pt.getActualTypeArguments()[0]).getName();
                     }
-                } else {
-                    type = clz.getName();
                 }
+
                 JavaField jf = new JavaField(name, type, "");
                 List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method,
idx - 1);
                 jf.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
                 fields.add(new JavaField(name, type, ""));
-               
+
             }
         }
-        
+
         return fields;
     }
 
@@ -123,24 +140,24 @@
         javax.xml.ws.ResponseWrapper resWrapper = method.getAnnotation(javax.xml.ws.ResponseWrapper.class);
         String resClassName = getClassName();
         String resNs = null;
-        
+
         if (resWrapper != null) {
             resClassName = resWrapper.className().length() > 0 ? resWrapper.className()
: resClassName;
             resNs = resWrapper.targetNamespace().length() > 0 ? resWrapper.targetNamespace()
: null;
-        }  
+        }
         if (resClassName == null) {
-            resClassName = getPackageName(method) + ".jaxws." 
+            resClassName = getPackageName(method) + ".jaxws."
                 + StringUtils.capitalize(method.getName())
                 + "Response";
         }
-        
+
         WrapperBeanClass jClass = new WrapperBeanClass();
         jClass.setFullClassName(resClassName);
         jClass.setNamespace(resNs);
         return jClass;
     }
-    
-    
 
-    
+
+
+
 }

Added: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/AddressingFeatureException.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/AddressingFeatureException.java?rev=610277&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/AddressingFeatureException.java
(added)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/AddressingFeatureException.java
Tue Jan  8 22:04:56 2008
@@ -0,0 +1,39 @@
+/**
+ * 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.cxf.tools.fortest.addr;
+
+import javax.xml.ws.WebServiceException;
+
+public class AddressingFeatureException extends WebServiceException {
+    String detail;
+
+    public AddressingFeatureException(String message) {
+        super(message);
+    }
+
+    public AddressingFeatureException(String message, String detail) {
+        super(message);
+        this.detail = detail;
+    }
+
+    public String getDetail() {
+        return detail;
+    }
+}

Added: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/WSAImpl2.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/WSAImpl2.java?rev=610277&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/WSAImpl2.java
(added)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/addr/WSAImpl2.java
Tue Jan  8 22:04:56 2008
@@ -0,0 +1,48 @@
+/**
+ * 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.cxf.tools.fortest.addr;
+
+import javax.jws.WebService;
+import javax.xml.ws.Action;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.Holder;
+import javax.xml.ws.soap.Addressing;
+import javax.xml.ws.soap.SOAPBinding;
+
+@WebService(
+    name = "AddressingFeatureTest2",
+    portName = "AddressingFeatureTest2Port",
+    targetNamespace = "http://addressingfeatureservice.org/wsdl",
+    serviceName = "AddressingFeatureTest2Service"
+)
+
+@BindingType(value = SOAPBinding.SOAP11HTTP_BINDING)
+@Addressing(enabled = true, required = true)
+
+public class WSAImpl2 {
+    @Action(input = "inputAction", output = "outputAction")
+    public int addNumbers(Holder<String> testname, int number1, int number2) {
+        if (number1 < 0 || number2 < 0) {
+            new AddressingFeatureException("One of the numbers received was negative:" 
+                                           + number1 + ", " + number2);
+        }
+        return number1 + number2;
+    }
+}

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java?rev=610277&r1=610276&r2=610277&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
Tue Jan  8 22:04:56 2008
@@ -470,4 +470,65 @@
         String expectedFile = getClass().getResource("expected/add_numbers_expected.wsdl").getFile();
         assertWsdlEquals(new File(expectedFile), wsdlFile);
     }
+
+    // Test the Holder Parameter in the RequestWrapperBean and ResponseWrapperBean
+    @Test
+    public void testWSAImpl2() throws Exception {
+        env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/add_numbers_2.wsdl");
+        env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.addr.WSAImpl2");
+        env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
+        env.put(ToolConstants.CFG_WRAPPERBEAN, ToolConstants.CFG_WRAPPERBEAN);
+        env.put(ToolConstants.CFG_CREATE_XSD_IMPORTS, ToolConstants.CFG_CREATE_XSD_IMPORTS);
+        try {
+            processor.setEnvironment(env);
+            processor.process();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        //File wsdlFile = new File(output, "add_numbers.wsdl");
+        //assertTrue("Generate Wsdl Fail", wsdlFile.exists());
+        //String expectedFile = getClass().getResource("expected/add_numbers_expected.wsdl").getFile();
+        //assertWsdlEquals(new File(expectedFile), wsdlFile);
+
+        String pkgBase = "org/apache/cxf/tools/fortest/addr/jaxws";
+        File requestWrapperClass = new File(output, pkgBase + "/AddNumbers.java");
+        File responseWrapperClass = new File(output, pkgBase + "/AddNumbersResponse.java");
+        assertTrue(requestWrapperClass.exists());
+        assertTrue(responseWrapperClass.exists());
+
+        assertTrue(getStringFromFile(requestWrapperClass).indexOf("String  arg0") != -1);
+        assertTrue(getStringFromFile(requestWrapperClass).indexOf("Holder") == -1);
+        assertTrue(getStringFromFile(responseWrapperClass).indexOf("String  arg0") != -1);
+        assertTrue(getStringFromFile(responseWrapperClass).indexOf("Holder") == -1);
+    }
+
+//     @Test
+//     public void testInherit() throws Exception {
+//         env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/inherit.wsdl");
+//         env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.inherit.A");
+//         env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
+//         env.put(ToolConstants.CFG_WRAPPERBEAN, ToolConstants.CFG_WRAPPERBEAN);
+//         //env.put(ToolConstants.CFG_CREATE_XSD_IMPORTS, ToolConstants.CFG_CREATE_XSD_IMPORTS);
+//         try {
+//             processor.setEnvironment(env);
+//             processor.process();
+//         } catch (Exception e) {
+//             e.printStackTrace();
+//         }
+//     }
+
+//     @Test
+//     public void testWSARefParam() throws Exception {
+//         env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/refparam.wsdl");
+//         env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.refparam.AddNumbersImpl");
+//         env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
+//         env.put(ToolConstants.CFG_WRAPPERBEAN, ToolConstants.CFG_WRAPPERBEAN);
+//         try {
+//             processor.setEnvironment(env);
+//             processor.process();
+//         } catch (Exception e) {
+//             e.printStackTrace();
+//         }
+//     }
+
 }



Mime
View raw message