View Javadoc

1   /*
2    * Copyright 2004-2010 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  
17  package org.seasar.cubby.routing.impl;
18  
19  import java.lang.reflect.Method;
20  import java.util.List;
21  import java.util.regex.Pattern;
22  
23  import org.seasar.cubby.action.RequestMethod;
24  import org.seasar.cubby.internal.util.StringUtils;
25  import org.seasar.cubby.routing.Routing;
26  
27  /**
28   * ルーティングの実装。
29   * 
30   * @author baba
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  			final String onSubmit, final int priority) {
83  		this.actionClass = actionClass;
84  		this.actionMethod = actionMethod;
85  		this.actionPath = actionPath;
86  		this.uriParameterNames = uriParameterNames;
87  		this.pattern = pattern;
88  		this.requestMethod = requestMethod;
89  		this.onSubmit = onSubmit;
90  		this.priority = priority;
91  	}
92  
93  	/**
94  	 * {@inheritDoc}
95  	 */
96  	public Class<?> getActionClass() {
97  		return actionClass;
98  	}
99  
100 	/**
101 	 * {@inheritDoc}
102 	 */
103 	public Method getActionMethod() {
104 		return actionMethod;
105 	}
106 
107 	/**
108 	 * {@inheritDoc}
109 	 */
110 	public String getActionPath() {
111 		return actionPath;
112 	}
113 
114 	/**
115 	 * {@inheritDoc}
116 	 */
117 	public List<String> getUriParameterNames() {
118 		return uriParameterNames;
119 	}
120 
121 	/**
122 	 * {@inheritDoc}
123 	 */
124 	public Pattern getPattern() {
125 		return pattern;
126 	}
127 
128 	/**
129 	 * {@inheritDoc}
130 	 */
131 	public RequestMethod getRequestMethod() {
132 		return requestMethod;
133 	}
134 
135 	/**
136 	 * {@inheritDoc}
137 	 */
138 	public String getOnSubmit() {
139 		return onSubmit;
140 	}
141 
142 	/**
143 	 * {@inheritDoc}
144 	 */
145 	public int getPriority() {
146 		return this.priority;
147 	}
148 
149 	/**
150 	 * {@inheritDoc}
151 	 */
152 	public boolean isAcceptable(final String requestMethod) {
153 		return StringUtils.equalsIgnoreCase(this.requestMethod.name(),
154 				requestMethod);
155 	}
156 
157 	/**
158 	 * このオブジェクトの文字列表現を返します。
159 	 * 
160 	 * @return このオブジェクトの正規表現
161 	 */
162 	@Override
163 	public String toString() {
164 		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 }