1 package org.objectweb.celtix.bus.jaxws; 2 3 import java.lang.reflect.Method ; 4 import java.lang.reflect.ParameterizedType ; 5 import java.lang.reflect.Type ; 6 import java.util.ArrayList ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 import java.util.logging.Level ; 10 import java.util.logging.Logger ; 11 12 import javax.jws.WebMethod; 13 import javax.jws.WebService; 14 import javax.xml.namespace.QName ; 15 import javax.xml.ws.Provider; 16 import javax.xml.ws.ServiceMode; 17 import javax.xml.ws.WebServiceProvider; 18 19 import org.objectweb.celtix.common.logging.LogUtils; 20 21 public final class EndpointUtils { 22 23 private static final Logger LOG = LogUtils.getL7dLogger(EndpointUtils.class); 24 25 private EndpointUtils() { 26 } 28 29 public static ServiceMode getServiceMode(EndpointImpl endpoint) { 30 assert null != endpoint; 31 Class <?> implementorClass = endpoint.getImplementorClass(); 32 if (implementorClass.isAssignableFrom(Provider.class)) { 33 return implementorClass.getAnnotation(ServiceMode.class); 34 } 35 return null; 36 } 37 38 50 51 public static Method getMethod(EndpointImpl endpoint, QName operationName) { 52 Class <?> iClass = endpoint.getImplementorClass(); 53 return getMethod(iClass, operationName); 54 } 55 public static Method getMethod(Class <?> iClass, QName operationName) { 56 List <Class <?>> list = getWebServiceAnnotatedClass(iClass); 58 59 String methodName = operationName.getLocalPart(); 61 Method iMethod = null; 62 63 Iterator <Class <?>> iter = list.iterator(); 64 boolean strictMatch = false; 65 while (iter.hasNext() && !strictMatch) { 66 Class <?> sei = iter.next(); 67 Method [] iMethods = sei.getMethods(); 68 69 for (Method m : iMethods) { 70 WebMethod wm = m.getAnnotation(WebMethod.class); 71 72 if (wm != null && !"".equals(wm.operationName())) { 73 if (methodName.equals(wm.operationName()) 74 && methodName.equalsIgnoreCase(m.getName())) { 75 iMethod = m; 76 strictMatch = true; 77 break; 78 } 79 } else if (methodName.equals(m.getName())) { 80 iMethod = m; 81 break; 82 } 83 } 84 } 85 86 if (null == iMethod) { 87 LOG.log(Level.SEVERE, "METHOD_NOT_DEFINED_MSG", methodName); 88 return null; 89 } 90 91 return iMethod; 92 } 93 94 public static Class <?> getProviderParameterType(EndpointImpl endpoint) { 95 Type intfTypes[] = endpoint.getImplementorClass().getGenericInterfaces(); 97 for (Type t : intfTypes) { 98 Class <?> clazz = JAXBEncoderDecoder.getClassFromType(t); 99 if (Provider.class == clazz) { 100 Type paramTypes[] = ((ParameterizedType )t).getActualTypeArguments(); 101 return JAXBEncoderDecoder.getClassFromType(paramTypes[0]); 102 } 103 } 104 105 return null; 106 } 107 108 private static boolean hasWebServiceAnnotation(Class <?> cls) { 109 if (cls == null) { 110 return false; 111 } 112 if (null != cls.getAnnotation(WebService.class)) { 113 return true; 114 } 115 for (Class <?> inf : cls.getInterfaces()) { 116 if (null != inf.getAnnotation(WebService.class)) { 117 return true; 118 } 119 } 120 121 return hasWebServiceAnnotation(cls.getSuperclass()); 122 } 123 124 private static boolean hasWebServiceProviderAnnotation(Class <?> cls) { 125 if (cls != null) { 126 return cls.isAnnotationPresent(WebServiceProvider.class); 127 } 128 129 return false; 130 } 131 132 public static boolean isValidImplementor(Object implementor) { 133 if (Provider.class.isAssignableFrom(implementor.getClass()) 134 && hasWebServiceProviderAnnotation(implementor.getClass())) { 135 return true; 136 } 137 138 142 if (hasWebServiceAnnotation(implementor.getClass())) { 143 return true; 144 } 145 146 LOG.info("Implementor is not annotated with WebService annotation."); 147 return false; 148 } 149 150 public static List <Class <?>> getWebServiceAnnotatedClass(Class <?> cls) { 151 List <Class <?>> list = new ArrayList <Class <?>>(); 152 153 Class <?>[] interfaces = cls.getInterfaces(); 154 for (Class <?> c : interfaces) { 155 list.addAll(getWebServiceAnnotatedClass(c)); 156 } 157 158 if (!cls.isInterface()) { 159 Class <?> superClass = cls.getSuperclass(); 160 if (superClass != null) { 161 list.addAll(getWebServiceAnnotatedClass(superClass)); 162 } 163 } 164 165 if (cls.isAnnotationPresent(WebService.class)) { 166 list.add(cls); 167 } 168 169 return list; 170 } 171 172 173 } 174 | Popular Tags |