1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
32 import com.sun.xml.internal.ws.api.WSBinding;
33 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
34 import com.sun.xml.internal.ws.api.databinding.MetadataReader;
35 import com.sun.xml.internal.ws.api.model.ExceptionType;
36 import com.sun.xml.internal.ws.api.model.MEP;
37 import com.sun.xml.internal.ws.api.model.Parameter;
38 import com.sun.xml.internal.ws.api.model.ParameterBinding;
39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
40 import com.sun.xml.internal.ws.api.model.wsdl.WSDLInput;
41 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPart;
42 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
43 import com.sun.xml.internal.ws.binding.WebServiceFeatureList;
44 import com.sun.xml.internal.ws.model.soap.SOAPBindingImpl;
45 import com.sun.xml.internal.ws.resources.ModelerMessages;
46 import com.sun.xml.internal.ws.resources.ServerMessages;
47 import com.sun.xml.internal.ws.spi.db.BindingContext;
48 import com.sun.xml.internal.ws.spi.db.TypeInfo;
49 import com.sun.xml.internal.ws.spi.db.WrapperComposite;
50
51 import static com.sun.xml.internal.ws.binding.WebServiceFeatureList.getSoapVersion;
52
53 import javax.jws.*;
54 import javax.jws.WebParam.Mode;
55 import javax.jws.soap.SOAPBinding;
56 import javax.jws.soap.SOAPBinding.Style;
57 import javax.xml.bind.annotation.XmlElement;
58 import javax.xml.bind.annotation.XmlSeeAlso;
59 import javax.xml.namespace.QName;
60 import javax.xml.ws.*;
61 import javax.xml.ws.soap.MTOM;
62 import javax.xml.ws.soap.MTOMFeature;
63 import java.lang.annotation.Annotation;
64 import java.lang.reflect.Method;
65 import java.lang.reflect.Modifier;
66 import java.lang.reflect.ParameterizedType;
67 import java.lang.reflect.Type;
68 import java.rmi.RemoteException;
69 import java.security.AccessController;
70 import java.util.HashSet;
71 import java.util.Map;
364 private Class getResponseWrapperClass(String className, Method method, QName resElemName) {
365 ClassLoader loader = (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader;
366 try {
367 return loader.loadClass(className);
368 } catch (ClassNotFoundException e) {
369 if (noWrapperGen()) return WrapperComposite.class;
370 logger.fine("Dynamically creating response wrapper bean Class " + className);
371 return WrapperBeanGenerator.createResponseWrapperBean(className, method, resElemName, loader);
372 }
373 }
374
375
376 private Class getExceptionBeanClass(String className, Class exception, String name, String namespace) {
377 boolean decapitalizeExceptionBeanProperties = true;
378 Object o = config.properties().get(DecapitalizeExceptionBeanProperties);
379 if (o!= null && o instanceof Boolean) decapitalizeExceptionBeanProperties = (Boolean) o;
380 ClassLoader loader = (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader;
381 try {
382 return loader.loadClass(className);
383 } catch (ClassNotFoundException e) {
384 logger.fine("Dynamically creating exception bean Class " + className);
385 return WrapperBeanGenerator.createExceptionBean(className, exception, targetNamespace, name, namespace, loader, decapitalizeExceptionBeanProperties);
386 }
387 }
388
389 protected void determineWebMethodUse(Class clazz) {
390 if (clazz == null)
391 return;
392 if (!clazz.isInterface()) {
393 if (clazz == Object.class)
394 return;
395 WebMethod webMethod;
396 for (Method method : clazz.getMethods()) {
397 if (method.getDeclaringClass()!=clazz)
398 continue;
399 webMethod = getAnnotation(method, WebMethod.class);
400 if (webMethod != null && !webMethod.exclude()) {
401 classUsesWebMethod.add(clazz);
402 break;
403 }
868
869 //get WebParam
870 Class<?>[] parameterTypes = method.getParameterTypes();
871 Type[] genericParameterTypes = method.getGenericParameterTypes();
872 Annotation[][] pannotations = getParamAnnotations(method);
873 int pos = 0;
874 for (Class clazzType : parameterTypes) {
875 String partName=null;
876 String paramName = "arg"+pos;
877 //String paramNamespace = "";
878 boolean isHeader = false;
879
880 if(javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)){
881 continue;
882 }
883
884 boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
885 //set the actual type argument of Holder in the TypeReference
886 if (isHolder) {
887 if(clazzType==Holder.class){
888 clazzType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)genericParameterTypes[pos]).getActualTypeArguments()[0]);
889 }
890 }
891 Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
892 WebParam webParam = null;
893 xmlElem = null;
894 for (Annotation annotation : pannotations[pos]) {
895 if (annotation.annotationType() == WebParam.class)
896 webParam = (WebParam)annotation;
897 else if (annotation.annotationType() == XmlElement.class)
898 xmlElem = (XmlElement)annotation;
899 }
900
901 QName paramQName = getParameterQName(method, webParam, xmlElem, paramName);
902 if (webParam != null) {
903 isHeader = webParam.header();
904 methodHasHeaderParams = isHeader || methodHasHeaderParams;
905 if (isHeader && xmlElem != null) {
906 throw new RuntimeModelerException("@XmlElement cannot be specified on method "+method+" parameter that is bound to header");
907 }
908 if(webParam.partName().length() > 0)
1083
1084 //get WebParam
1085 Class<?>[] parameterTypes = method.getParameterTypes();
1086 Type[] genericParameterTypes = method.getGenericParameterTypes();
1087 Annotation[][] pannotations = getParamAnnotations(method);
1088 int pos = 0;
1089 for (Class clazzType : parameterTypes) {
1090 String paramName = "";
1091 String paramNamespace = "";
1092 String partName = "";
1093 boolean isHeader = false;
1094
1095 if(javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)){
1096 continue;
1097 }
1098
1099 boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
1100 //set the actual type argument of Holder in the TypeReference
1101 if (isHolder) {
1102 if (clazzType==Holder.class)
1103 clazzType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)genericParameterTypes[pos]).getActualTypeArguments()[0]);
1104 }
1105 Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
1106 for (Annotation annotation : pannotations[pos]) {
1107 if (annotation.annotationType() == javax.jws.WebParam.class) {
1108 javax.jws.WebParam webParam = (javax.jws.WebParam) annotation;
1109 paramName = webParam.name();
1110 partName = webParam.partName();
1111 isHeader = webParam.header();
1112 WebParam.Mode mode = webParam.mode();
1113 paramNamespace = webParam.targetNamespace();
1114 if (isHolder && mode == Mode.IN)
1115 mode = Mode.INOUT;
1116 paramMode = mode;
1117 break;
1118 }
1119 }
1120
1121 if (paramName.length() == 0) {
1122 paramName = "arg"+pos;
1123 }
1193 }
1194
1195 /**
1196 * models the exceptions thrown by <code>method</code> and adds them to the <code>javaMethod</code>
1197 * runtime model object
1198 * @param javaMethod the runtime model object to add the exception model objects to
1199 * @param method the <code>method</code> from which to find the exceptions to model
1200 */
1201 protected void processExceptions(JavaMethodImpl javaMethod, Method method) {
1202 Action actionAnn = getAnnotation(method, Action.class);
1203 FaultAction[] faultActions = {};
1204 if(actionAnn != null)
1205 faultActions = actionAnn.fault();
1206 for (Class<?> exception : method.getExceptionTypes()) {
1207
1208 //Exclude RuntimeException, RemoteException and Error etc
1209 if (!EXCEPTION_CLASS.isAssignableFrom(exception))
1210 continue;
1211 if (RUNTIME_EXCEPTION_CLASS.isAssignableFrom(exception) || REMOTE_EXCEPTION_CLASS.isAssignableFrom(exception))
1212 continue;
1213
1214 Class exceptionBean;
1215 Annotation[] anns;
1216 WebFault webFault = getAnnotation(exception, WebFault.class);
1217 Method faultInfoMethod = getWSDLExceptionFaultInfo(exception);
1218 ExceptionType exceptionType = ExceptionType.WSDLException;
1219 String namespace = targetNamespace;
1220 String name = exception.getSimpleName();
1221 String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
1222 if (packageName.length() == 0)
1223 beanPackage = JAXWS_PACKAGE_PD;
1224 String className = beanPackage+ name + BEAN;
1225 String messageName = exception.getSimpleName();
1226 if (webFault != null) {
1227 if (webFault.faultBean().length()>0)
1228 className = webFault.faultBean();
1229 if (webFault.name().length()>0)
1230 name = webFault.name();
1231 if (webFault.targetNamespace().length()>0)
1232 namespace = webFault.targetNamespace();
1233 if (webFault.messageName().length()>0)
1234 messageName = webFault.messageName();
1235 }
1236 if (faultInfoMethod == null) {
1237 exceptionBean = getExceptionBeanClass(className, exception, name, namespace);
1238 exceptionType = ExceptionType.UserDefined;
1239 anns = getAnnotations(exceptionBean);
1240 } else {
1241 exceptionBean = faultInfoMethod.getReturnType();
1242 anns = getAnnotations(faultInfoMethod);
1243 }
1244 QName faultName = new QName(namespace, name);
1245 TypeInfo typeRef = new TypeInfo(faultName, exceptionBean, anns);
1246 CheckedExceptionImpl checkedException =
1247 new CheckedExceptionImpl(javaMethod, exception, typeRef, exceptionType);
1248 checkedException.setMessageName(messageName);
1249 for(FaultAction fa: faultActions) {
1250 if(fa.className().equals(exception) && !fa.value().equals("")) {
1251 checkedException.setFaultAction(fa.value());
1252 break;
1253 }
1254 }
1255 javaMethod.addException(checkedException);
1256 }
1257 }
1258
1259 /**
1260 * returns the method that corresponds to "getFaultInfo". Returns null if this is not an
1261 * exception generated from a WSDL
1262 * @param exception the class to search for the "getFaultInfo" method
1263 * @return the method named "getFaultInfo" if this is an exception generated from WSDL or an
1264 * exception that contains the <code>WebFault</code> annotation. Otherwise it returns null
1265 */
1266 protected Method getWSDLExceptionFaultInfo(Class exception) {
1267 // if (!exception.isAnnotationPresent(WebFault.class))
1268 if (getAnnotation(exception, WebFault.class) == null)
1329 //get WebParam
1330 Class<?>[] parameterTypes = method.getParameterTypes();
1331 Type[] genericParameterTypes = method.getGenericParameterTypes();
1332 Annotation[][] pannotations = getParamAnnotations(method);
1333 int pos = 0;
1334 for (Class clazzType : parameterTypes) {
1335 String paramName = operationName; //method.getName();
1336 String partName = null;
1337 String requestNamespace = targetNamespace;
1338 boolean isHeader = false;
1339
1340 //async
1341 if(javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)){
1342 continue;
1343 }
1344
1345 boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
1346 //set the actual type argument of Holder in the TypeReference
1347 if (isHolder) {
1348 if (clazzType==Holder.class)
1349 clazzType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)genericParameterTypes[pos]).getActualTypeArguments()[0]);
1350 }
1351
1352 Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
1353 for (Annotation annotation : pannotations[pos]) {
1354 if (annotation.annotationType() == javax.jws.WebParam.class) {
1355 javax.jws.WebParam webParam = (javax.jws.WebParam) annotation;
1356 paramMode = webParam.mode();
1357 if (isHolder && paramMode == Mode.IN)
1358 paramMode = Mode.INOUT;
1359 isHeader = webParam.header();
1360 if(isHeader)
1361 paramName = "arg"+pos;
1362 if(paramMode == Mode.OUT && !isHeader)
1363 paramName = operationName+RESPONSE;
1364 if (webParam.name().length() > 0)
1365 paramName = webParam.name();
1366 partName = webParam.partName();
1367 if (!webParam.targetNamespace().equals("")) {
1368 requestNamespace = webParam.targetNamespace();
1369 }
1417 }
1418 if(numInBodyBindings > 1){
1419 throw new RuntimeModelerException(ModelerMessages.localizableNOT_A_VALID_BARE_METHOD(portClass.getName(), javaMethod.getMethod().getName()));
1420 }
1421 }
1422
1423 int numOutBodyBindings = 0;
1424 for(Parameter param : javaMethod.getResponseParameters()){
1425 if(param.getBinding().equals(ParameterBinding.BODY) && param.isOUT()){
1426 numOutBodyBindings++;
1427 }
1428 if(numOutBodyBindings > 1){
1429 throw new RuntimeModelerException(ModelerMessages.localizableNOT_A_VALID_BARE_METHOD(portClass.getName(), javaMethod.getMethod().getName()));
1430 }
1431 }
1432 }
1433
1434 private Class getAsyncReturnType(Method method, Class returnType) {
1435 if(Response.class.isAssignableFrom(returnType)){
1436 Type ret = method.getGenericReturnType();
1437 return (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)ret).getActualTypeArguments()[0]);
1438 }else{
1439 Type[] types = method.getGenericParameterTypes();
1440 Class[] params = method.getParameterTypes();
1441 int i = 0;
1442 for(Class cls : params){
1443 if(AsyncHandler.class.isAssignableFrom(cls)){
1444 return (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)types[i]).getActualTypeArguments()[0]);
1445 }
1446 i++;
1447 }
1448 }
1449 return returnType;
1450 }
1451
1452 /**
1453 * utility to capitalize the first letter in a string
1454 * @param name the string to capitalize
1455 * @return the capitalized string
1456 */
1457 public static String capitalize(String name) {
1458 if (name == null || name.length() == 0) {
1459 return name;
1460 }
1461 char chars[] = name.toCharArray();
1462 chars[0] = Character.toUpperCase(chars[0]);
1463 return new String(chars);
1464 }
1716 if (webParam != null && webParam.targetNamespace().length() > 0) {
1717 webParamNS = webParam.targetNamespace();
1718 }
1719 String xmlElemNS = null;
1720 if (xmlElem != null && !xmlElem.namespace().equals("##default")) {
1721 xmlElemNS = xmlElem.namespace();
1722 }
1723 if (xmlElemNS != null && webParamNS != null && !xmlElemNS.equals(webParamNS)) {
1724 throw new RuntimeModelerException("@XmlElement(namespace)="+xmlElemNS+" and @WebParam(targetNamespace)="+webParamNS+" are different for method " +method);
1725 }
1726 String ns = "";
1727 if (webParamNS != null) {
1728 ns = webParamNS;
1729 } else if (xmlElemNS != null) {
1730 ns = xmlElemNS;
1731 }
1732
1733 return new QName(ns, localPart);
1734 }
1735
1736
1737 }
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
32 import com.sun.xml.internal.ws.api.WSBinding;
33 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
34 import com.sun.xml.internal.ws.api.databinding.MetadataReader;
35 import com.sun.xml.internal.ws.api.model.ExceptionType;
36 import com.sun.xml.internal.ws.api.model.MEP;
37 import com.sun.xml.internal.ws.api.model.Parameter;
38 import com.sun.xml.internal.ws.api.model.ParameterBinding;
39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
40 import com.sun.xml.internal.ws.api.model.wsdl.WSDLInput;
41 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPart;
42 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
43 import com.sun.xml.internal.ws.binding.WebServiceFeatureList;
44 import com.sun.xml.internal.ws.model.soap.SOAPBindingImpl;
45 import com.sun.xml.internal.ws.resources.ModelerMessages;
46 import com.sun.xml.internal.ws.resources.ServerMessages;
47 import com.sun.xml.internal.ws.spi.db.BindingContext;
48 import com.sun.xml.internal.ws.spi.db.TypeInfo;
49 import com.sun.xml.internal.ws.spi.db.WrapperComposite;
50
51 import static com.sun.xml.internal.ws.binding.WebServiceFeatureList.getSoapVersion;
52 import static com.sun.xml.internal.ws.model.Utils.REFLECTION_NAVIGATOR;
53
54 import javax.jws.*;
55 import javax.jws.WebParam.Mode;
56 import javax.jws.soap.SOAPBinding;
57 import javax.jws.soap.SOAPBinding.Style;
58 import javax.xml.bind.annotation.XmlElement;
59 import javax.xml.bind.annotation.XmlSeeAlso;
60 import javax.xml.namespace.QName;
61 import javax.xml.ws.*;
62 import javax.xml.ws.soap.MTOM;
63 import javax.xml.ws.soap.MTOMFeature;
64 import java.lang.annotation.Annotation;
65 import java.lang.reflect.Method;
66 import java.lang.reflect.Modifier;
67 import java.lang.reflect.ParameterizedType;
68 import java.lang.reflect.Type;
69 import java.rmi.RemoteException;
70 import java.security.AccessController;
71 import java.util.HashSet;
72 import java.util.Map;
365 private Class getResponseWrapperClass(String className, Method method, QName resElemName) {
366 ClassLoader loader = (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader;
367 try {
368 return loader.loadClass(className);
369 } catch (ClassNotFoundException e) {
370 if (noWrapperGen()) return WrapperComposite.class;
371 logger.fine("Dynamically creating response wrapper bean Class " + className);
372 return WrapperBeanGenerator.createResponseWrapperBean(className, method, resElemName, loader);
373 }
374 }
375
376
377 private Class getExceptionBeanClass(String className, Class exception, String name, String namespace) {
378 boolean decapitalizeExceptionBeanProperties = true;
379 Object o = config.properties().get(DecapitalizeExceptionBeanProperties);
380 if (o!= null && o instanceof Boolean) decapitalizeExceptionBeanProperties = (Boolean) o;
381 ClassLoader loader = (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader;
382 try {
383 return loader.loadClass(className);
384 } catch (ClassNotFoundException e) {
385 if (noWrapperGen()) return exception;
386 logger.fine("Dynamically creating exception bean Class " + className);
387 return WrapperBeanGenerator.createExceptionBean(className, exception, targetNamespace, name, namespace, loader, decapitalizeExceptionBeanProperties);
388 }
389 }
390
391 protected void determineWebMethodUse(Class clazz) {
392 if (clazz == null)
393 return;
394 if (!clazz.isInterface()) {
395 if (clazz == Object.class)
396 return;
397 WebMethod webMethod;
398 for (Method method : clazz.getMethods()) {
399 if (method.getDeclaringClass()!=clazz)
400 continue;
401 webMethod = getAnnotation(method, WebMethod.class);
402 if (webMethod != null && !webMethod.exclude()) {
403 classUsesWebMethod.add(clazz);
404 break;
405 }
870
871 //get WebParam
872 Class<?>[] parameterTypes = method.getParameterTypes();
873 Type[] genericParameterTypes = method.getGenericParameterTypes();
874 Annotation[][] pannotations = getParamAnnotations(method);
875 int pos = 0;
876 for (Class clazzType : parameterTypes) {
877 String partName=null;
878 String paramName = "arg"+pos;
879 //String paramNamespace = "";
880 boolean isHeader = false;
881
882 if(javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)){
883 continue;
884 }
885
886 boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
887 //set the actual type argument of Holder in the TypeReference
888 if (isHolder) {
889 if(clazzType==Holder.class){
890 clazzType = erasure(((ParameterizedType)genericParameterTypes[pos]).getActualTypeArguments()[0]);
891 }
892 }
893 Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
894 WebParam webParam = null;
895 xmlElem = null;
896 for (Annotation annotation : pannotations[pos]) {
897 if (annotation.annotationType() == WebParam.class)
898 webParam = (WebParam)annotation;
899 else if (annotation.annotationType() == XmlElement.class)
900 xmlElem = (XmlElement)annotation;
901 }
902
903 QName paramQName = getParameterQName(method, webParam, xmlElem, paramName);
904 if (webParam != null) {
905 isHeader = webParam.header();
906 methodHasHeaderParams = isHeader || methodHasHeaderParams;
907 if (isHeader && xmlElem != null) {
908 throw new RuntimeModelerException("@XmlElement cannot be specified on method "+method+" parameter that is bound to header");
909 }
910 if(webParam.partName().length() > 0)
1085
1086 //get WebParam
1087 Class<?>[] parameterTypes = method.getParameterTypes();
1088 Type[] genericParameterTypes = method.getGenericParameterTypes();
1089 Annotation[][] pannotations = getParamAnnotations(method);
1090 int pos = 0;
1091 for (Class clazzType : parameterTypes) {
1092 String paramName = "";
1093 String paramNamespace = "";
1094 String partName = "";
1095 boolean isHeader = false;
1096
1097 if(javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)){
1098 continue;
1099 }
1100
1101 boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
1102 //set the actual type argument of Holder in the TypeReference
1103 if (isHolder) {
1104 if (clazzType==Holder.class)
1105 clazzType = erasure(((ParameterizedType)genericParameterTypes[pos]).getActualTypeArguments()[0]);
1106 }
1107 Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
1108 for (Annotation annotation : pannotations[pos]) {
1109 if (annotation.annotationType() == javax.jws.WebParam.class) {
1110 javax.jws.WebParam webParam = (javax.jws.WebParam) annotation;
1111 paramName = webParam.name();
1112 partName = webParam.partName();
1113 isHeader = webParam.header();
1114 WebParam.Mode mode = webParam.mode();
1115 paramNamespace = webParam.targetNamespace();
1116 if (isHolder && mode == Mode.IN)
1117 mode = Mode.INOUT;
1118 paramMode = mode;
1119 break;
1120 }
1121 }
1122
1123 if (paramName.length() == 0) {
1124 paramName = "arg"+pos;
1125 }
1195 }
1196
1197 /**
1198 * models the exceptions thrown by <code>method</code> and adds them to the <code>javaMethod</code>
1199 * runtime model object
1200 * @param javaMethod the runtime model object to add the exception model objects to
1201 * @param method the <code>method</code> from which to find the exceptions to model
1202 */
1203 protected void processExceptions(JavaMethodImpl javaMethod, Method method) {
1204 Action actionAnn = getAnnotation(method, Action.class);
1205 FaultAction[] faultActions = {};
1206 if(actionAnn != null)
1207 faultActions = actionAnn.fault();
1208 for (Class<?> exception : method.getExceptionTypes()) {
1209
1210 //Exclude RuntimeException, RemoteException and Error etc
1211 if (!EXCEPTION_CLASS.isAssignableFrom(exception))
1212 continue;
1213 if (RUNTIME_EXCEPTION_CLASS.isAssignableFrom(exception) || REMOTE_EXCEPTION_CLASS.isAssignableFrom(exception))
1214 continue;
1215 if (getAnnotation(exception, javax.xml.bind.annotation.XmlTransient.class) != null)
1216 continue;
1217 Class exceptionBean;
1218 Annotation[] anns;
1219 WebFault webFault = getAnnotation(exception, WebFault.class);
1220 Method faultInfoMethod = getWSDLExceptionFaultInfo(exception);
1221 ExceptionType exceptionType = ExceptionType.WSDLException;
1222 String namespace = targetNamespace;
1223 String name = exception.getSimpleName();
1224 String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
1225 if (packageName.length() == 0)
1226 beanPackage = JAXWS_PACKAGE_PD;
1227 String className = beanPackage+ name + BEAN;
1228 String messageName = exception.getSimpleName();
1229 if (webFault != null) {
1230 if (webFault.faultBean().length()>0)
1231 className = webFault.faultBean();
1232 if (webFault.name().length()>0)
1233 name = webFault.name();
1234 if (webFault.targetNamespace().length()>0)
1235 namespace = webFault.targetNamespace();
1236 if (webFault.messageName().length()>0)
1237 messageName = webFault.messageName();
1238 }
1239 if (faultInfoMethod == null) {
1240 exceptionBean = getExceptionBeanClass(className, exception, name, namespace);
1241 exceptionType = ExceptionType.UserDefined;
1242 anns = getAnnotations(exceptionBean);
1243 } else {
1244 exceptionBean = faultInfoMethod.getReturnType();
1245 anns = getAnnotations(faultInfoMethod);
1246 }
1247 QName faultName = new QName(namespace, name);
1248 TypeInfo typeRef = new TypeInfo(faultName, exceptionBean, anns);
1249 CheckedExceptionImpl checkedException =
1250 new CheckedExceptionImpl(javaMethod, exception, typeRef, exceptionType);
1251 checkedException.setMessageName(messageName);
1252 checkedException.setFaultInfoGetter(faultInfoMethod);
1253 for(FaultAction fa: faultActions) {
1254 if(fa.className().equals(exception) && !fa.value().equals("")) {
1255 checkedException.setFaultAction(fa.value());
1256 break;
1257 }
1258 }
1259 javaMethod.addException(checkedException);
1260 }
1261 }
1262
1263 /**
1264 * returns the method that corresponds to "getFaultInfo". Returns null if this is not an
1265 * exception generated from a WSDL
1266 * @param exception the class to search for the "getFaultInfo" method
1267 * @return the method named "getFaultInfo" if this is an exception generated from WSDL or an
1268 * exception that contains the <code>WebFault</code> annotation. Otherwise it returns null
1269 */
1270 protected Method getWSDLExceptionFaultInfo(Class exception) {
1271 // if (!exception.isAnnotationPresent(WebFault.class))
1272 if (getAnnotation(exception, WebFault.class) == null)
1333 //get WebParam
1334 Class<?>[] parameterTypes = method.getParameterTypes();
1335 Type[] genericParameterTypes = method.getGenericParameterTypes();
1336 Annotation[][] pannotations = getParamAnnotations(method);
1337 int pos = 0;
1338 for (Class clazzType : parameterTypes) {
1339 String paramName = operationName; //method.getName();
1340 String partName = null;
1341 String requestNamespace = targetNamespace;
1342 boolean isHeader = false;
1343
1344 //async
1345 if(javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)){
1346 continue;
1347 }
1348
1349 boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
1350 //set the actual type argument of Holder in the TypeReference
1351 if (isHolder) {
1352 if (clazzType==Holder.class)
1353 clazzType = erasure(((ParameterizedType)genericParameterTypes[pos]).getActualTypeArguments()[0]);
1354 }
1355
1356 Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
1357 for (Annotation annotation : pannotations[pos]) {
1358 if (annotation.annotationType() == javax.jws.WebParam.class) {
1359 javax.jws.WebParam webParam = (javax.jws.WebParam) annotation;
1360 paramMode = webParam.mode();
1361 if (isHolder && paramMode == Mode.IN)
1362 paramMode = Mode.INOUT;
1363 isHeader = webParam.header();
1364 if(isHeader)
1365 paramName = "arg"+pos;
1366 if(paramMode == Mode.OUT && !isHeader)
1367 paramName = operationName+RESPONSE;
1368 if (webParam.name().length() > 0)
1369 paramName = webParam.name();
1370 partName = webParam.partName();
1371 if (!webParam.targetNamespace().equals("")) {
1372 requestNamespace = webParam.targetNamespace();
1373 }
1421 }
1422 if(numInBodyBindings > 1){
1423 throw new RuntimeModelerException(ModelerMessages.localizableNOT_A_VALID_BARE_METHOD(portClass.getName(), javaMethod.getMethod().getName()));
1424 }
1425 }
1426
1427 int numOutBodyBindings = 0;
1428 for(Parameter param : javaMethod.getResponseParameters()){
1429 if(param.getBinding().equals(ParameterBinding.BODY) && param.isOUT()){
1430 numOutBodyBindings++;
1431 }
1432 if(numOutBodyBindings > 1){
1433 throw new RuntimeModelerException(ModelerMessages.localizableNOT_A_VALID_BARE_METHOD(portClass.getName(), javaMethod.getMethod().getName()));
1434 }
1435 }
1436 }
1437
1438 private Class getAsyncReturnType(Method method, Class returnType) {
1439 if(Response.class.isAssignableFrom(returnType)){
1440 Type ret = method.getGenericReturnType();
1441 return erasure(((ParameterizedType)ret).getActualTypeArguments()[0]);
1442 }else{
1443 Type[] types = method.getGenericParameterTypes();
1444 Class[] params = method.getParameterTypes();
1445 int i = 0;
1446 for(Class cls : params){
1447 if(AsyncHandler.class.isAssignableFrom(cls)){
1448 return erasure(((ParameterizedType)types[i]).getActualTypeArguments()[0]);
1449 }
1450 i++;
1451 }
1452 }
1453 return returnType;
1454 }
1455
1456 /**
1457 * utility to capitalize the first letter in a string
1458 * @param name the string to capitalize
1459 * @return the capitalized string
1460 */
1461 public static String capitalize(String name) {
1462 if (name == null || name.length() == 0) {
1463 return name;
1464 }
1465 char chars[] = name.toCharArray();
1466 chars[0] = Character.toUpperCase(chars[0]);
1467 return new String(chars);
1468 }
1720 if (webParam != null && webParam.targetNamespace().length() > 0) {
1721 webParamNS = webParam.targetNamespace();
1722 }
1723 String xmlElemNS = null;
1724 if (xmlElem != null && !xmlElem.namespace().equals("##default")) {
1725 xmlElemNS = xmlElem.namespace();
1726 }
1727 if (xmlElemNS != null && webParamNS != null && !xmlElemNS.equals(webParamNS)) {
1728 throw new RuntimeModelerException("@XmlElement(namespace)="+xmlElemNS+" and @WebParam(targetNamespace)="+webParamNS+" are different for method " +method);
1729 }
1730 String ns = "";
1731 if (webParamNS != null) {
1732 ns = webParamNS;
1733 } else if (xmlElemNS != null) {
1734 ns = xmlElemNS;
1735 }
1736
1737 return new QName(ns, localPart);
1738 }
1739
1740 static public Class erasure(Type type) {
1741 return (Class)REFLECTION_NAVIGATOR.erasure(type);
1742 }
1743 }
|