WebServiceMethod.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * @author Ranides Atterwim <ranides@gmail.com>
  3. * @copyright Ranides Atterwim
  4. * @license WTFPL
  5. * @url http://ranides.net/projects/assira
  6. */
  7. package net.ranides.assira.reflection;
  8. import java.lang.annotation.Annotation;
  9. import java.lang.annotation.IncompleteAnnotationException;
  10. import java.lang.reflect.Method;
  11. import java.util.*;
  12. import javax.jws.WebMethod;
  13. import javax.jws.WebParam;
  14. import javax.jws.WebResult;
  15. import net.ranides.assira.asm.MethodInspector;
  16. import net.ranides.assira.collection.ArrayUtils;
  17. import net.ranides.assira.text.Strings;
  18. /**
  19. *
  20. * @author ranides
  21. */
  22. public class WebServiceMethod {
  23. private final Method method;
  24. private final WebMethod info;
  25. private final String result;
  26. private final Map<String, GenericClass> params = new LinkedHashMap<String, GenericClass>();
  27. private final Map<String, String> webParams = new LinkedHashMap<String, String>();
  28. WebServiceMethod(Method method) {
  29. this.method = method;
  30. this.info = method.getAnnotation(WebMethod.class);
  31. if (null == this.info) {
  32. throw new IncompleteAnnotationException(WebMethod.class, method.getDeclaringClass().getCanonicalName() );
  33. }
  34. WebResult iresult = method.getAnnotation(WebResult.class);
  35. this.result = (null==iresult) ? null : iresult.name();
  36. Annotation[][] paramInfos = method.getParameterAnnotations();
  37. Class<?>[] paramTypes = method.getParameterTypes();
  38. int index = 0;
  39. for(Variable param : MethodInspector.getArguments(method)) {
  40. params.put(param.name(), param.type());
  41. WebParam paramInfo = ArrayUtils.first(paramInfos[index], WebParam.class);
  42. if (null == paramInfo) {
  43. webParams.put(param.name(), param.type().asText());
  44. } else {
  45. webParams.put(paramInfo.name(), param.type().asText());
  46. }
  47. }
  48. }
  49. public Method getMethod() {
  50. return method;
  51. }
  52. public String getAction() {
  53. return info.action();
  54. }
  55. public boolean getExclude() {
  56. return info.exclude();
  57. }
  58. public String getName() {
  59. return Strings.orne(info.operationName(), method.getName());
  60. }
  61. public String getResult() {
  62. return Strings.orne(result, method.getReturnType().getSimpleName());
  63. }
  64. public Map<String, GenericClass> getParamTypes() {
  65. return Collections.unmodifiableMap(params);
  66. }
  67. public Map<String, String> getParams() {
  68. return Collections.unmodifiableMap(webParams);
  69. }
  70. }