1 package org.codehaus.xfire.annotations.jsr181; 2 3 import java.lang.annotation.Annotation; 4 import java.lang.reflect.Method; 5 6 import javax.jws.HandlerChain; 7 import javax.jws.Oneway; 8 import javax.jws.WebMethod; 9 import javax.jws.WebParam; 10 import javax.jws.WebResult; 11 import javax.jws.WebService; 12 import javax.jws.soap.SOAPBinding; 13 14 import org.codehaus.xfire.annotations.HandlerChainAnnotation; 15 import org.codehaus.xfire.annotations.WebAnnotations; 16 import org.codehaus.xfire.annotations.WebMethodAnnotation; 17 import org.codehaus.xfire.annotations.WebParamAnnotation; 18 import org.codehaus.xfire.annotations.WebResultAnnotation; 19 import org.codehaus.xfire.annotations.WebServiceAnnotation; 20 import org.codehaus.xfire.annotations.soap.SOAPBindingAnnotation; 21 22 public class Jsr181WebAnnotations 23 implements WebAnnotations 24 { 25 public boolean hasWebServiceAnnotation(Class clazz) 26 { 27 return clazz.isAnnotationPresent(WebService.class); 28 } 29 30 public WebServiceAnnotation getWebServiceAnnotation(Class clazz) 31 { 32 WebService webService = (WebService) clazz.getAnnotation(WebService.class); 33 if (webService != null) 34 { 35 WebServiceAnnotation annotation = new WebServiceAnnotation(); 36 annotation.setEndpointInterface(webService.endpointInterface()); 37 annotation.setName(webService.name()); 38 annotation.setServiceName(webService.serviceName()); 39 annotation.setTargetNamespace(webService.targetNamespace()); 40 41 return annotation; 42 } 43 else 44 { 45 return null; 46 } 47 } 48 49 public boolean hasWebMethodAnnotation(Method method) 50 { 51 return method.isAnnotationPresent(WebMethod.class); 52 } 53 54 public WebMethodAnnotation getWebMethodAnnotation(Method method) 55 { 56 WebMethod webMethod = (WebMethod) method.getAnnotation(WebMethod.class); 57 if (webMethod != null) 58 { 59 WebMethodAnnotation annotation = new WebMethodAnnotation(); 60 annotation.setAction(webMethod.action()); 61 annotation.setOperationName(webMethod.operationName()); 62 63 return annotation; 64 } 65 else 66 { 67 return null; 68 } 69 } 70 71 public boolean hasWebResultAnnotation(Method method) 72 { 73 return method.isAnnotationPresent(WebResult.class); 74 } 75 76 public WebResultAnnotation getWebResultAnnotation(Method method) 77 { 78 Annotation[][] annotations = method.getParameterAnnotations(); 79 WebResult webResult = (WebResult) method.getAnnotation(WebResult.class); 80 if (webResult != null) 81 { 82 WebResultAnnotation annot = new WebResultAnnotation(); 83 annot.setName(webResult.name()); 84 annot.setTargetNamespace(webResult.targetNamespace()); 85 86 return annot; 87 } 88 else 89 { 90 return null; 91 } 92 } 93 94 public boolean hasWebParamAnnotation(Method method, int parameter) 95 { 96 Annotation[][] annotations = method.getParameterAnnotations(); 97 if (parameter >= annotations.length) 98 { 99 return false; 100 } 101 else 102 { 103 for (int i = 0; i < annotations[parameter].length; i++) 104 { 105 Annotation annotation = annotations[parameter][i]; 106 if (annotation.annotationType().equals(WebParam.class)) 107 { 108 return true; 109 } 110 } 111 return false; 112 } 113 } 114 115 public WebParamAnnotation getWebParamAnnotation(Method method, int parameter) 116 { 117 Annotation[][] annotations = method.getParameterAnnotations(); 118 if (parameter >= annotations.length) 119 { 120 return null; 121 } 122 WebParam webParam = null; 123 for (int i = 0; i < annotations[parameter].length; i++) 124 { 125 Annotation annotation = annotations[parameter][i]; 126 if (annotation.annotationType().equals(WebParam.class)) 127 { 128 webParam = (WebParam) annotations[parameter][i]; 129 break; 130 } 131 } 132 if (webParam != null) 133 { 134 WebParamAnnotation annot = new WebParamAnnotation(); 135 annot.setName(webParam.name()); 136 annot.setTargetNamespace(webParam.targetNamespace()); 137 annot.setHeader(webParam.header()); 138 139 if (webParam.mode() == WebParam.Mode.IN) 140 { 141 annot.setMode(WebParamAnnotation.MODE_IN); 142 } 143 else if (webParam.mode() == WebParam.Mode.INOUT) 144 { 145 annot.setMode(WebParamAnnotation.MODE_INOUT); 146 } 147 else if (webParam.mode() == WebParam.Mode.OUT) 148 { 149 annot.setMode(WebParamAnnotation.MODE_OUT); 150 } 151 152 return annot; 153 } 154 else 155 { 156 return null; 157 } 158 } 159 160 public boolean hasOnewayAnnotation(Method method) 161 { 162 return method.isAnnotationPresent(Oneway.class); 163 } 164 165 public boolean hasSOAPBindingAnnotation(Class clazz) 166 { 167 return clazz.isAnnotationPresent(SOAPBinding.class); 168 } 169 170 public SOAPBindingAnnotation getSOAPBindingAnnotation(Class clazz) 171 { 172 SOAPBinding binding = (SOAPBinding) clazz.getAnnotation(SOAPBinding.class); 173 174 SOAPBindingAnnotation annot = null; 175 if (binding != null) 176 { 177 annot = new SOAPBindingAnnotation(); 178 if (binding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) 179 { 180 annot.setParameterStyle(SOAPBindingAnnotation.PARAMETER_STYLE_BARE); 181 } 182 else if (binding.parameterStyle() == SOAPBinding.ParameterStyle.WRAPPED) 183 { 184 annot.setParameterStyle(SOAPBindingAnnotation.PARAMETER_STYLE_WRAPPED); 185 } 186 187 if (binding.style() == SOAPBinding.Style.DOCUMENT) 188 { 189 annot.setStyle(SOAPBindingAnnotation.STYLE_DOCUMENT); 190 } 191 else if (binding.style() == SOAPBinding.Style.RPC) 192 { 193 annot.setStyle(SOAPBindingAnnotation.STYLE_RPC); 194 } 195 196 if (binding.use() == SOAPBinding.Use.ENCODED) 197 { 198 annot.setUse(SOAPBindingAnnotation.USE_ENCODED); 199 } 200 else if (binding.use() == SOAPBinding.Use.LITERAL) 201 { 202 annot.setUse(SOAPBindingAnnotation.USE_LITERAL); 203 } 204 } 205 206 return annot; 207 } 208 209 public boolean hasHandlerChainAnnotation(Class clazz) 210 { 211 return clazz.isAnnotationPresent(HandlerChain.class); 212 } 213 214 public HandlerChainAnnotation getHandlerChainAnnotation(Class clazz) 215 { 216 HandlerChain handlerChain = (HandlerChain) clazz.getAnnotation(HandlerChain.class); 217 HandlerChainAnnotation annotation = null; 218 if (handlerChain != null) 219 { 220 annotation = new HandlerChainAnnotation(handlerChain.file(), 221 handlerChain.name()); 222 } 223 return annotation; 224 } 225 }