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 contextPath, Class<?> actionClass, Method actionMethod,
034 String path, String method) {
035
036 _contextPath = contextPath;
037 _actionClass = actionClass;
038 _actionMethod = actionMethod;
039 _path = path;
040 _method = method;
041
042 _methodParameters =
043 MethodParametersResolverUtil.resolveMethodParameters(actionMethod);
044
045 _fullPath = _contextPath + _path;
046
047 StringBundler sb = new StringBundler(_methodParameters.length * 2 + 4);
048
049 sb.append(_fullPath);
050 sb.append(CharPool.MINUS);
051 sb.append(_methodParameters.length);
052
053 for (MethodParameter methodParameter : _methodParameters) {
054 sb.append(CharPool.MINUS);
055 sb.append(methodParameter.getName());
056 }
057
058 _signature = sb.toString();
059 }
060
061 @Override
062 public int compareTo(
063 JSONWebServiceActionConfig jsonWebServiceActionConfig) {
064
065 return _signature.compareTo(jsonWebServiceActionConfig._signature);
066 }
067
068 @Override
069 public Class<?> getActionClass() {
070 return _actionClass;
071 }
072
073 @Override
074 public Method getActionMethod() {
075 return _actionMethod;
076 }
077
078 @Override
079 public String getContextPath() {
080 return _contextPath;
081 }
082
083 public String getFullPath() {
084 return _fullPath;
085 }
086
087 @Override
088 public String getMethod() {
089 return _method;
090 }
091
092 @Override
093 public MethodParameter[] getMethodParameters() {
094 return _methodParameters;
095 }
096
097 @Override
098 public String getPath() {
099 return _path;
100 }
101
102 @Override
103 public String getSignature() {
104 return _signature;
105 }
106
107 @Override
108 public String toString() {
109 StringBundler sb = new StringBundler(17);
110
111 sb.append("{actionClass=");
112 sb.append(_actionClass);
113 sb.append(", actionMethod=");
114 sb.append(_actionMethod);
115 sb.append(", contextPath=");
116 sb.append(_contextPath);
117 sb.append(", fullPath=");
118 sb.append(_fullPath);
119 sb.append(", method=");
120 sb.append(_method);
121 sb.append(", methodParameters=");
122 sb.append(_methodParameters);
123 sb.append(", path=");
124 sb.append(_path);
125 sb.append(", signature=");
126 sb.append(_signature);
127 sb.append("}");
128
129 return sb.toString();
130 }
131
132 private Class<?> _actionClass;
133 private Method _actionMethod;
134 private String _contextPath;
135 private String _fullPath;
136 private String _method;
137 private MethodParameter[] _methodParameters;
138 private String _path;
139 private String _signature;
140
141 }