| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira
- */
- package net.ranides.assira.reflection;
- import java.lang.annotation.Annotation;
- import java.lang.annotation.IncompleteAnnotationException;
- import java.lang.reflect.Method;
- import java.util.*;
- import javax.jws.WebMethod;
- import javax.jws.WebParam;
- import javax.jws.WebResult;
- import net.ranides.assira.asm.MethodInspector;
- import net.ranides.assira.collection.ArrayUtils;
- import net.ranides.assira.text.Strings;
- /**
- *
- * @author ranides
- */
- public class WebServiceMethod {
- private final Method method;
- private final WebMethod info;
- private final String result;
- private final Map<String, GenericClass> params = new LinkedHashMap<String, GenericClass>();
- private final Map<String, String> webParams = new LinkedHashMap<String, String>();
- WebServiceMethod(Method method) {
- this.method = method;
- this.info = method.getAnnotation(WebMethod.class);
-
- if (null == this.info) {
- throw new IncompleteAnnotationException(WebMethod.class, method.getDeclaringClass().getCanonicalName() );
- }
-
- WebResult iresult = method.getAnnotation(WebResult.class);
- this.result = (null==iresult) ? null : iresult.name();
-
- Annotation[][] paramInfos = method.getParameterAnnotations();
- Class<?>[] paramTypes = method.getParameterTypes();
-
- int index = 0;
- for(Variable param : MethodInspector.getArguments(method)) {
- params.put(param.name(), param.type());
- WebParam paramInfo = ArrayUtils.first(paramInfos[index], WebParam.class);
- if (null == paramInfo) {
- webParams.put(param.name(), param.type().asText());
- } else {
- webParams.put(paramInfo.name(), param.type().asText());
- }
- }
- }
-
- public Method getMethod() {
- return method;
- }
- public String getAction() {
- return info.action();
- }
- public boolean getExclude() {
- return info.exclude();
- }
- public String getName() {
- return Strings.orne(info.operationName(), method.getName());
- }
- public String getResult() {
- return Strings.orne(result, method.getReturnType().getSimpleName());
- }
- public Map<String, GenericClass> getParamTypes() {
- return Collections.unmodifiableMap(params);
- }
-
- public Map<String, String> getParams() {
- return Collections.unmodifiableMap(webParams);
- }
- }
|