View Javadoc

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   */
31  class RoutingImpl implements Routing {
32  
33  	/** アクションクラス。 */
34  	private final Class<?> actionClass;
35  
36  	/** アクソンメソッド。 */
37  	private final Method actionMethod;
38  
39  	/** アクションのパス。 */
40  	private final String actionPath;
41  
42  	/** URI パラメータ名。 */
43  	private final List<String> uriParameterNames;
44  
45  	/** 正規表現パターン。 */
46  	private final Pattern pattern;
47  
48  	/** 要求メソッド。 */
49  	private final RequestMethod requestMethod;
50  
51  	/** このルーティングを使用することを判断するためのパラメータ名。 */
52  	private final String onSubmit;
53  
54  	/** 優先順位。 */
55  	private final int priority;
56  
57  	/**
58  	 * インスタンス化します。
59  	 * 
60  	 * @param actionClass
61  	 *            アクションクラス
62  	 * @param actionMethod
63  	 *            アクションメソッド
64  	 * @param actionPath
65  	 *            アクションのパス
66  	 * @param uriParameterNames
67  	 *            URI パラメータ名
68  	 * @param pattern
69  	 *            正規表現パターン
70  	 * @param requestMethod
71  	 *            要求メソッド
72  	 * @param onSubmit
73  	 *            このルーティングを使用することを判断するためのパラメータ名
74  	 * @param priority
75  	 *            優先順位。手動登録の場合は登録順の連番。自動登録の場合は{@link Integer#MAX_VALUE}
76  	 *            が常にセットされます。
77  	 */
78  	RoutingImpl(final Class<?> actionClass, final Method actionMethod,
79  			final String actionPath, final List<String> uriParameterNames,
80  			final Pattern pattern, final RequestMethod requestMethod,
81  			final String onSubmit, final int priority) {
82  		this.actionClass = actionClass;
83  		this.actionMethod = actionMethod;
84  		this.actionPath = actionPath;
85  		this.uriParameterNames = uriParameterNames;
86  		this.pattern = pattern;
87  		this.requestMethod = requestMethod;
88  		this.onSubmit = onSubmit;
89  		this.priority = priority;
90  	}
91  
92  	/**
93  	 * {@inheritDoc}
94  	 */
95  	public Class<?> getActionClass() {
96  		return actionClass;
97  	}
98  
99  	/**
100 	 * {@inheritDoc}
101 	 */
102 	public Method getActionMethod() {
103 		return actionMethod;
104 	}
105 
106 	/**
107 	 * {@inheritDoc}
108 	 */
109 	public String getActionPath() {
110 		return actionPath;
111 	}
112 
113 	/**
114 	 * {@inheritDoc}
115 	 */
116 	public List<String> getUriParameterNames() {
117 		return uriParameterNames;
118 	}
119 
120 	/**
121 	 * {@inheritDoc}
122 	 */
123 	public Pattern getPattern() {
124 		return pattern;
125 	}
126 
127 	/**
128 	 * {@inheritDoc}
129 	 */
130 	public RequestMethod getRequestMethod() {
131 		return requestMethod;
132 	}
133 
134 	/**
135 	 * {@inheritDoc}
136 	 */
137 	public String getOnSubmit() {
138 		return onSubmit;
139 	}
140 
141 	/**
142 	 * {@inheritDoc}
143 	 */
144 	public int getPriority() {
145 		return this.priority;
146 	}
147 
148 	/**
149 	 * {@inheritDoc}
150 	 */
151 	public boolean isAcceptable(final String requestMethod) {
152 		return StringUtils.equalsIgnoreCase(this.requestMethod.name(),
153 				requestMethod);
154 	}
155 
156 	/**
157 	 * このオブジェクトの文字列表現を返します。
158 	 * 
159 	 * @return このオブジェクトの正規表現
160 	 */
161 	@Override
162 	public String toString() {
163 		return new StringBuilder().append("[regex=").append(this.pattern)
164 				.append(",actionMethod=").append(this.actionMethod).append(
165 						",uriParameterNames=").append(this.uriParameterNames)
166 				.append(",requestMethod=").append(this.requestMethod).append(
167 						",onSubmit=").append(onSubmit).append(",priority=")
168 				.append(this.priority).append(",auto=").append("]").toString();
169 	}
170 }