View Javadoc

1   /*
2    * Copyright 2004-2008 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.action;
17  
18  import java.lang.annotation.ElementType;
19  import java.lang.annotation.Retention;
20  import java.lang.annotation.RetentionPolicy;
21  import java.lang.annotation.Target;
22  
23  import org.seasar.cubby.routing.PathResolver;
24  
25  /**
26   * アクションメソッドのパス。
27   * <p>
28   * アクションメソッドを起動するためのパスを指定するアノテーションです。
29   * </p>
30   * <p>
31   * 使用例
32   * 
33   * <pre>
34   * &#064;Path(&quot;fuga&quot;)
35   * public class HogeAction {
36   * 	// -&gt; &quot;/fuga/index&quot;
37   * 	public ActionResult index() {
38   * 	}
39   * 
40   * 	// -&gt; &quot;/fuga/m1&quot;
41   * 	public ActionResult m1() {
42   * 	}
43   * 
44   * 	&#064;Path(&quot;list&quot;)
45   * 	// -&gt; &quot;/fuga/list&quot;
46   * 	public ActionResult m2() {
47   * 	}
48   * 
49   * 	&#064;Path(&quot;/xxx/yyy&quot;)
50   * 	// -&gt; &quot;/xxx/yyy&quot;
51   * 	public ActionResult m3() {
52   * 	}
53   * 
54   * 	&#064;Path(&quot;/{id}/edit&quot;)
55   * 	// {id}部分をリクエストパラメータに追加。
56   *  // {id}部分の正規表現は省略されているためデフォルトの「[0-9a-zA-Z]+」。
57   *  // priority(優先度)はデフォルト値の「Integer.MAX_VALUE」。
58   * 	public ActionResult m4() {
59   * 	}
60   * 
61   * 	&#064;Path(&quot;/{userId,[a-z]+}/edit&quot;, priprity=0)
62   * 	// {userId}部分をリクエストパラメータに追加。
63   *  // {userId}部分の正規表現は「[a-z]+」のため小文字アルファベットのみ。
64   *  // priority(優先度)は「0」のため、m4メソッドよりも先に適用される。
65   * 	public ActionResult m5() {
66   * 	}
67   * }
68   * 
69   * &#064;Path(&quot;/&quot;)
70   * public class RootAction {
71   * 	// -&gt; &quot;/&quot;
72   * 	public ActionResult index() {
73   * 	}
74   * 
75   * 	// -&gt; &quot;/m1&quot;
76   * 	public ActionResult m1() {
77   * 	}
78   * 
79   * 	&#064;Path(&quot;list&quot;)
80   * 	// -&gt; &quot;/list&quot;
81   * 	public ActionResult m2() {
82   * 	}
83   * 
84   * 	&#064;Path(&quot;/xxx/yyy&quot;)
85   * 	// -&gt; &quot;/xxx/yyy&quot;
86   * 	public ActionResult m3() {
87   * 	}
88   * }
89   * </pre>
90   * 
91   * </p>
92   * 
93   * @author agata
94   * @author baba
95   * @since 1.0.0
96   */
97  @Retention(RetentionPolicy.RUNTIME)
98  @Target( { ElementType.METHOD, ElementType.TYPE })
99  public @interface Path {
100 
101 	/**
102 	 * アクションメソッドのバインディング用パスを指定します。
103 	 * <p>
104 	 * URLはアクションクラスのパス+アクションメソッドのパスで決定されます。
105 	 * ただし、先頭が『/』の場合コンテキストルートからの絶対パスとして解釈されます。
106 	 * </p>
107 	 * <p>
108 	 * {パラメータ名,正規表現}でプレースホルダーの指定ができます。
109 	 * </p>
110 	 * <p>
111 	 * 正規表現にマッチした場合、マッチした箇所が指定されたパラメータ名に追加され、アクションメソッドが実行されます。
112 	 * 正規表現は省略可能です。省略した場合「[a-zA-Z0-9]+」と同じ意味になります。
113 	 * </p>
114 	 * <p>
115 	 * アクションメソッドのパスは「パスの正規表現+{@link Accept リクエストメソッド}」で一意に特定できなければいけません。
116 	 * 実行時に重複が発見されると例外が発生します。
117 	 * </p>
118 	 * 
119 	 * @return アクションメソッドのバインディング用パス
120 	 * @see Accept
121 	 */
122 	String value() default "";
123 	
124 	/**
125 	 * アクションメソッドのバインディング時の優先度を設定します。
126 	 * <p>
127 	 * この値が小さいほど、優先度が高く先に適用されます。デフォルト値は{@link Integer#MAX_VALUE}です。
128 	 * </p>
129 	 * <p>
130 	 * 手動でバインディングの設定が追加された場合、優先度は0から順番に振られます。手動追加よりも自動設定の優先度を上げたい場合は、負の値を設定してください。
131 	 * </p>
132 	 * @return アクションメソッドのバインディング時の優先度
133 	 * @see PathResolver#add(String, Class, String, RequestMethod...) 手動によるバインディング設定の追加
134 	 */
135 	int priority() default Integer.MAX_VALUE;
136 
137 }