Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RoutingImpl |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2004-2009 the Seasar Foundation and the Others. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
15 | */ | |
16 | package org.seasar.cubby.routing.impl; | |
17 | ||
18 | import java.lang.reflect.Method; | |
19 | import java.util.List; | |
20 | import java.util.regex.Pattern; | |
21 | ||
22 | import org.seasar.cubby.action.RequestMethod; | |
23 | import org.seasar.cubby.internal.util.StringUtils; | |
24 | import org.seasar.cubby.routing.Routing; | |
25 | ||
26 | /** | |
27 | * ルーティングの実装。 | |
28 | * | |
29 | * @author baba | |
30 | * @since 1.1.0 | |
31 | */ | |
32 | class RoutingImpl implements Routing { | |
33 | ||
34 | /** アクションクラス。 */ | |
35 | private final Class<?> actionClass; | |
36 | ||
37 | /** アクソンメソッド。 */ | |
38 | private final Method actionMethod; | |
39 | ||
40 | /** アクションのパス。 */ | |
41 | private final String actionPath; | |
42 | ||
43 | /** URI パラメータ名。 */ | |
44 | private final List<String> uriParameterNames; | |
45 | ||
46 | /** 正規表現パターン。 */ | |
47 | private final Pattern pattern; | |
48 | ||
49 | /** リクエストメソッド。 */ | |
50 | private final RequestMethod requestMethod; | |
51 | ||
52 | /** このルーティングを使用することを判断するためのパラメータ名。 */ | |
53 | private final String onSubmit; | |
54 | ||
55 | /** 優先順位。 */ | |
56 | private final int priority; | |
57 | ||
58 | /** | |
59 | * インスタンス化します。 | |
60 | * | |
61 | * @param actionClass | |
62 | * アクションクラス | |
63 | * @param actionMethod | |
64 | * アクションメソッド | |
65 | * @param actionPath | |
66 | * アクションのパス | |
67 | * @param uriParameterNames | |
68 | * URI パラメータ名 | |
69 | * @param pattern | |
70 | * 正規表現パターン | |
71 | * @param requestMethod | |
72 | * リクエストメソッド | |
73 | * @param onSubmit | |
74 | * このルーティングを使用することを判断するためのパラメータ名 | |
75 | * @param priority | |
76 | * 優先順位。手動登録の場合は登録順の連番。自動登録の場合は{@link Integer#MAX_VALUE} | |
77 | * が常にセットされます。 | |
78 | */ | |
79 | RoutingImpl(final Class<?> actionClass, final Method actionMethod, | |
80 | final String actionPath, final List<String> uriParameterNames, | |
81 | final Pattern pattern, final RequestMethod requestMethod, | |
82 | 1791 | final String onSubmit, final int priority) { |
83 | 1791 | this.actionClass = actionClass; |
84 | 1791 | this.actionMethod = actionMethod; |
85 | 1791 | this.actionPath = actionPath; |
86 | 1791 | this.uriParameterNames = uriParameterNames; |
87 | 1791 | this.pattern = pattern; |
88 | 1791 | this.requestMethod = requestMethod; |
89 | 1791 | this.onSubmit = onSubmit; |
90 | 1791 | this.priority = priority; |
91 | 1791 | } |
92 | ||
93 | /** | |
94 | * {@inheritDoc} | |
95 | */ | |
96 | public Class<?> getActionClass() { | |
97 | 249 | return actionClass; |
98 | } | |
99 | ||
100 | /** | |
101 | * {@inheritDoc} | |
102 | */ | |
103 | public Method getActionMethod() { | |
104 | 249 | return actionMethod; |
105 | } | |
106 | ||
107 | /** | |
108 | * {@inheritDoc} | |
109 | */ | |
110 | public String getActionPath() { | |
111 | 69 | return actionPath; |
112 | } | |
113 | ||
114 | /** | |
115 | * {@inheritDoc} | |
116 | */ | |
117 | public List<String> getUriParameterNames() { | |
118 | 1812 | return uriParameterNames; |
119 | } | |
120 | ||
121 | /** | |
122 | * {@inheritDoc} | |
123 | */ | |
124 | public Pattern getPattern() { | |
125 | 2997 | return pattern; |
126 | } | |
127 | ||
128 | /** | |
129 | * {@inheritDoc} | |
130 | */ | |
131 | public RequestMethod getRequestMethod() { | |
132 | 1860 | return requestMethod; |
133 | } | |
134 | ||
135 | /** | |
136 | * {@inheritDoc} | |
137 | */ | |
138 | public String getOnSubmit() { | |
139 | 1791 | return onSubmit; |
140 | } | |
141 | ||
142 | /** | |
143 | * {@inheritDoc} | |
144 | */ | |
145 | public int getPriority() { | |
146 | 1770 | return this.priority; |
147 | } | |
148 | ||
149 | /** | |
150 | * {@inheritDoc} | |
151 | */ | |
152 | public boolean isAcceptable(final String requestMethod) { | |
153 | 33 | return StringUtils.equalsIgnoreCase(this.requestMethod.name(), |
154 | requestMethod); | |
155 | } | |
156 | ||
157 | /** | |
158 | * このオブジェクトの文字列表現を返します。 | |
159 | * | |
160 | * @return このオブジェクトの正規表現 | |
161 | */ | |
162 | @Override | |
163 | public String toString() { | |
164 | 1710 | return new StringBuilder().append("[regex=").append(this.pattern) |
165 | .append(",actionMethod=").append(this.actionMethod).append( | |
166 | ",uriParameterNames=").append(this.uriParameterNames) | |
167 | .append(",requestMethod=").append(this.requestMethod).append( | |
168 | ",onSubmit=").append(onSubmit).append(",priority=") | |
169 | .append(this.priority).append(",auto=").append("]").toString(); | |
170 | } | |
171 | } |