1 package org.apache.beehive.wsm.model.jsr181; 2 3 20 21 import java.lang.annotation.Annotation ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import java.util.List ; 26 27 import javax.jws.Oneway; 28 import javax.jws.WebMethod; 29 import javax.jws.WebParam; 30 import javax.jws.WebResult; 31 32 import javax.xml.namespace.QName ; 34 import org.apache.beehive.wsm.model.BeehiveWsMethodMetadata; 35 import org.apache.beehive.wsm.model.BeehiveWsParameterMetadata; 36 import org.apache.beehive.wsm.model.ValidationException; 37 import org.apache.beehive.wsm.model.java.JavaMethodInfo; 38 import org.apache.beehive.wsm.model.java.JavaParameterInfo; 39 40 public class Jsr181MethodMetadataImpl implements BeehiveWsMethodMetadata, java.io.Serializable { 41 42 private static final long serialVersionUID = 1L; 43 private static final String DEFAULT_WRNAME = "return"; 44 45 private String wmOperationName; 46 private String wmAction; 47 private boolean oneway = false; 48 private List <BeehiveWsParameterMetadata> params = 49 new ArrayList <BeehiveWsParameterMetadata>(); 50 private String wrName; 51 private String wrTargetNamespace; 52 private String javaMethodName; 53 private Class javaReturnType; 54 55 private QName mXMLReturnType; 56 57 public void validate() throws ValidationException { 58 return; } 60 61 public Jsr181MethodMetadataImpl( 62 String operationName, 63 Class javaType, 64 QName xmlReturnType) 65 { 66 this(operationName, javaType); 67 setXmlReturnType(xmlReturnType); 68 } 69 70 public Jsr181MethodMetadataImpl(String methodName, Class returnType) { 71 super(); 72 javaMethodName = methodName; 73 javaReturnType = returnType; 74 } 75 76 public Jsr181MethodMetadataImpl(JavaMethodInfo jm) { 77 78 super(); 79 80 if (null == jm) { 82 jm.logError("illegal java method info: <null>"); 83 return; 84 } 85 86 javaMethodName = jm.getMethodName(); 87 javaReturnType = jm.getReturnType(); 88 89 List <BeehiveWsParameterMetadata> webParams = 91 new ArrayList <BeehiveWsParameterMetadata>(); 92 for (JavaParameterInfo param : jm.getParameters()) { 93 BeehiveWsParameterMetadata wspm = new Jsr181ParameterMetadataImpl(param); 94 if (null == wspm) { 95 jm.logError("cannot create metadata for web param: " + param.getName()); 96 } 97 webParams.add(wspm); 98 } 99 100 setWrName(DEFAULT_WRNAME); 102 103 if (! jm.isPublic()) { 105 jm.logError("@WebMethod must be public: " + javaMethodName); 106 } 107 if (null != jm.getAnnotation(Oneway.class)) { 108 if (null != jm.getAnnotation(WebResult.class)) { 110 jm.logError("@Oneway method " + javaMethodName + " has incompatible annotation: @WebResult"); 111 } 112 if (void.class != javaReturnType) { 114 jm.logError("@Oneway method " + javaMethodName + " has illegal non-void return type: " + javaReturnType); 115 } 116 if (jm.throwsExceptions()) { 118 jm.logError("@Oneway method " + javaMethodName + " must not throw checked exceptions"); 119 } 120 122 if (null != webParams) { 123 for (BeehiveWsParameterMetadata param : webParams) { 124 if ((WebParam.Mode.OUT == param.getWpMode()) || (WebParam.Mode.INOUT == param.getWpMode())) { 125 jm.logError("@Oneway method " + javaMethodName + " has illegal INOUT or OUT parameter: " + param.getWpName()); 126 } 127 } 128 } 129 } 130 131 Collection <Annotation > annotations = jm.getAnnotations(); 133 if (null != annotations) { 134 for (Annotation a : annotations) { 135 if (a.annotationType() == javax.jws.WebMethod.class) { 136 initFromAnnotation((javax.jws.WebMethod) a); 137 } 138 else if (a.annotationType() == javax.jws.Oneway.class) { 139 initFromAnnotation((javax.jws.Oneway) a); 140 } 141 else if (a.annotationType() == javax.jws.WebResult.class) { 142 initFromAnnotation((javax.jws.WebResult) a); 143 } 144 else { 145 } 147 } 148 } 149 150 if ((null == getWmOperationName()) || (0 == getWmOperationName().length())) { 152 setWmOperationName(javaMethodName); 153 } 154 if ((null == getWmAction()) || (0 == getWmAction().length())) { 155 setWmAction(""); 156 } 157 158 addParams(webParams); 160 } 161 162 163 private void initFromAnnotation(WebResult annotation) { 164 if (null != annotation) { 165 setWrName(annotation.name()); 166 setWrTargetNamespace(annotation.targetNamespace()); 167 } 168 } 169 170 private void initFromAnnotation(Oneway annotation) { 171 setOneWay(null != annotation); 172 } 173 174 private void initFromAnnotation(WebMethod annotation) { 175 if (null != annotation) { 176 setWmAction(annotation.action()); 177 setWmOperationName(annotation.operationName()); 178 } 179 } 180 181 public boolean isOneWay() { 182 return oneway; 183 } 184 185 public void setOneWay(boolean oneway) { 186 this.oneway = oneway; 187 } 188 189 190 public String getWmAction() { 191 return wmAction; 192 } 193 194 public void setWmAction(String wmAction) { 195 this.wmAction = wmAction; 196 } 197 198 public String getWmOperationName() { 199 return wmOperationName; 200 } 201 202 public void setWmOperationName(String wmOperationName) { 203 this.wmOperationName = wmOperationName; 204 } 205 206 public String getWrName() { 207 return wrName; 208 } 209 210 public void setWrName(String wrName) { 211 this.wrName = wrName; 212 } 213 214 public String getWrTargetNamespace() { 215 return wrTargetNamespace; 216 } 217 218 public void setWrTargetNamespace(String wrTargetNamespace) { 219 this.wrTargetNamespace = wrTargetNamespace; 220 } 221 222 public List <BeehiveWsParameterMetadata> getParams() { 223 return Collections.unmodifiableList(params); 224 } 225 226 public void addParams(List <? extends BeehiveWsParameterMetadata> parameters) { 227 if (null != parameters) { 228 params.addAll(parameters); 229 } 230 } 232 233 public void addParam(BeehiveWsParameterMetadata parameter) { 234 if (null != parameter) { 235 params.add(parameter); 236 } 237 } 239 240 public String getJavaMethodName() { 241 return javaMethodName; 242 } 243 244 public Class getJavaReturnType() { 245 return javaReturnType; 246 } 247 248 public String getSignature() { 249 StringBuilder sb = new StringBuilder (getJavaMethodName()); 250 sb.append('('); 251 boolean firstParam = true; 252 if (null != params) { 253 for (BeehiveWsParameterMetadata p : params) { 254 if (firstParam) { 255 firstParam = false; 256 } 257 else { 258 sb.append(','); 259 } 260 sb.append(p.getJavaType()); 261 } 262 } 263 sb.append(')'); 264 return sb.toString(); 265 } 266 267 public String toString() { 268 String signature = getJavaReturnType().toString() + " " + getJavaMethodName() + "( "; 269 for (BeehiveWsParameterMetadata p : params) { 270 signature += p.getJavaType().toString() + " "; 271 } 272 return signature + ")"; 273 } 274 275 public boolean equals(Object o) { 276 if (! (o instanceof Jsr181MethodMetadataImpl)) { 277 return false; 278 } 279 Jsr181MethodMetadataImpl m = (Jsr181MethodMetadataImpl) o; 280 281 if (! getJavaMethodName().equals(m.getJavaMethodName())) { 283 return false; 284 } 285 286 if (! getJavaReturnType().equals(m.getJavaReturnType())) { 288 return false; 289 } 290 291 if (params.size() != m.params.size()) { 293 return false; 294 } 295 for (int i = 0; i < params.size(); i++) { 296 if (! m.params.get(i).getJavaType().equals(params.get(i).getJavaType())) { 297 return false; 298 } 299 } 300 301 303 return true; 304 } 305 306 313 public String getJavaReturnTypeFullName() { 314 return getClassName(getJavaReturnType()); 315 } 316 317 private String getClassName(Class cls) { 318 if (cls.isArray()) { 319 return getClassName(cls.getComponentType()) + "[]"; 320 } 321 else { 322 return cls.getName().replace('$', '.'); 323 } 324 } 325 326 public QName getXmlReturnType() { 327 return mXMLReturnType; 328 } 329 330 public void setXmlReturnType(QName xmlReturnType) { 331 mXMLReturnType = xmlReturnType; 332 } 333 334 337 public void setReturnType(Class javaType) { 338 this.javaReturnType = javaType; 339 340 } 341 342 345 public BeehiveWsParameterMetadata findParam(String parmName) { 346 if( null == parmName) return null; 349 BeehiveWsParameterMetadata res = null; 350 for(BeehiveWsParameterMetadata nxtParam : params) { 351 if( parmName.equals(nxtParam.getWpName())) { 352 res = nxtParam; 353 break; 354 } 355 } 356 return res; 357 } 358 } 359 | Popular Tags |