001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.annotation;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.lang.annotation.*;
019
020import org.apache.juneau.httppart.*;
021
022/**
023 * Annotation that can be applied to a parameter of a {@link RestMethod @RestMethod} annotated method to identify it as a variable
024 * in a URL path pattern converted to a POJO.
025 * 
026 * <h5 class='section'>Example:</h5>
027 * <p class='bcode'>
028 *    <ja>@RestMethod</ja>(name=<jsf>GET</jsf>, path=<js>"/myurl/{foo}/{bar}/{baz}/*"</js>)
029 *    <jk>public void</jk> doGet(RestRequest req, RestResponse res,
030 *          <ja>@Path</ja> String foo, <ja>@Path</ja> <jk>int</jk> bar, <ja>@Path</ja> UUID baz) {
031 *       ...
032 *    }
033 * </p>
034 * 
035 * <p>
036 * The <ja>@Path</ja> annotation is optional if the parameters are specified immediately following the
037 * <code>RestRequest</code> and <code>RestResponse</code> parameters, and are specified in the same order as the
038 * variables in the URL path pattern.
039 * The following example is equivalent to the previous example.
040 * <p class='bcode'>
041 *    <ja>@RestMethod</ja>(name=<jsf>GET</jsf>, path=<js>"/myurl/{foo}/{bar}/{baz}/*"</js>)
042 *    <jk>public void</jk> doGet(RestRequest req, RestResponse res,
043 *          String foo, <jk>int</jk> bar, UUID baz) {
044 *       ...
045 *    }
046 * </p>
047 * 
048 * <p>
049 * If the order of parameters is not the default order shown above, the attribute names must be specified (since
050 * parameter names are lost during compilation).
051 * The following example is equivalent to the previous example, except the parameter order has been switched, requiring
052 * the use of the <ja>@Path</ja> annotations.
053 * <p class='bcode'>
054 *    <ja>@RestMethod</ja>(name=<jsf>GET</jsf>, path=<js>"/myurl/{foo}/{bar}/{baz}/*"</js>)
055 *    <jk>public void</jk> doGet(RestRequest req, RestResponse res,
056 *          <ja>@Path</ja>(<js>"baz"</js>) UUID baz, <ja>@Path</ja>(<js>"foo"</js>) String foo, <ja>@Path</ja>(<js>"bar"</js>) <jk>int</jk> bar) {
057 *       ...
058 *    }
059 * </p>
060 * 
061 * <p>
062 * You can also use <code>{#}</code> notation to specify path parameters without specifying names.
063 * <p class='bcode'>
064 *    <ja>@RestMethod</ja>(name=<jsf>GET</jsf>, path=<js>"/myurl/{0}/{1}/{2}/*"</js>)
065 *    <jk>public void</jk> doGet(RestRequest req, RestResponse res,
066 *          <ja>@Path</ja> String foo, <ja>@Path</ja> <jk>int</jk> bar, <ja>@Path</ja> UUID baz) {
067 *       ...
068 *    }
069 * </p>
070 * 
071 * <h5 class='section'>See Also:</h5>
072 * <ul>
073 *    <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-rest-server.MethodParameters">Overview &gt; juneau-rest-server &gt; Method Parameters</a>
074 * </ul>
075 */
076@Documented
077@Target(PARAMETER)
078@Retention(RUNTIME)
079@Inherited
080public @interface Path {
081
082   /**
083    * URL path variable name.
084    * 
085    * <p>
086    * Optional if the attributes are specified in the same order as in the URL path pattern.
087    */
088   String name() default "";
089   
090   /**
091    * Specifies the {@link HttpPartParser} class used for parsing values from strings.
092    * 
093    * <p>
094    * The default value for this parser is inherited from the servlet/method which defaults to {@link UonPartParser}.
095    * <br>You can use {@link SimplePartParser} to parse POJOs that are directly convertible from <code>Strings</code>.
096    */
097   Class<? extends HttpPartParser> parser() default HttpPartParser.Null.class;
098
099   /**
100    * A synonym for {@link #name()}.
101    * 
102    * <p>
103    * Allows you to use shortened notation if you're only specifying the name.
104    */
105   String value() default "";
106}