001
014
015 package com.liferay.portal.jsonwebservice;
016
017 import com.liferay.portal.kernel.jsonwebservice.JSONWebServiceActionMapping;
018 import com.liferay.portal.kernel.util.CharPool;
019 import com.liferay.portal.kernel.util.MethodParameter;
020 import com.liferay.portal.kernel.util.MethodParametersResolverUtil;
021 import com.liferay.portal.kernel.util.StringBundler;
022
023 import java.lang.reflect.Method;
024
025
028 public class JSONWebServiceActionConfig
029 implements Comparable<JSONWebServiceActionConfig>,
030 JSONWebServiceActionMapping {
031
032 public JSONWebServiceActionConfig(
033 String servletContextName, Class<?> actionClass, Method actionMethod,
034 String path, String method) {
035
036 _servletContextName = servletContextName;
037 _actionClass = actionClass;
038 _actionMethod = actionMethod;
039 _path = path;
040 _method = method;
041
042 _methodParameters =
043 MethodParametersResolverUtil.resolveMethodParameters(actionMethod);
044
045 StringBundler sb = new StringBundler(_methodParameters.length * 2 + 4);
046
047 sb.append(_path);
048 sb.append(CharPool.MINUS);
049 sb.append(_methodParameters.length);
050
051 for (MethodParameter methodParameter : _methodParameters) {
052 sb.append(CharPool.MINUS);
053 sb.append(methodParameter.getName());
054 }
055
056 _fullPath = sb.toString();
057 }
058
059 public int compareTo(
060 JSONWebServiceActionConfig jsonWebServiceActionConfig) {
061
062 return _fullPath.compareTo(jsonWebServiceActionConfig._fullPath);
063 }
064
065 public Class<?> getActionClass() {
066 return _actionClass;
067 }
068
069 public Method getActionMethod() {
070 return _actionMethod;
071 }
072
073 public String getMethod() {
074 return _method;
075 }
076
077 public MethodParameter[] getMethodParameters() {
078 return _methodParameters;
079 }
080
081 public String getPath() {
082 return _path;
083 }
084
085 public String getServletContextName() {
086 return _servletContextName;
087 }
088
089 public String getSignature() {
090 return _fullPath;
091 }
092
093 @Override
094 public String toString() {
095 StringBundler sb = new StringBundler(13);
096
097 sb.append("{actionClass=");
098 sb.append(_actionClass);
099 sb.append(", actionMethod=");
100 sb.append(_actionMethod);
101 sb.append(", fullPath=");
102 sb.append(_fullPath);
103 sb.append(", method=");
104 sb.append(_method);
105 sb.append(", _methodParameters=");
106 sb.append(_methodParameters);
107 sb.append(", path=");
108 sb.append(_path);
109 sb.append("}");
110
111 return sb.toString();
112 }
113
114 private Class<?> _actionClass;
115 private Method _actionMethod;
116 private String _fullPath;
117 private String _method;
118 private MethodParameter[] _methodParameters;
119 private String _path;
120 private String _servletContextName;
121
122 }