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.arg;
014
015import org.apache.juneau.reflect.*;
016import org.apache.juneau.rest.*;
017import org.apache.juneau.rest.annotation.*;
018
019/**
020 * Resolves method parameters annotated with {@link Method} on {@link RestOp}-annotated Java methods.
021 *
022 * <p>
023 * The parameter value is resolved using:
024 * <p class='bjava'>
025 *    <jv>opSession</jv>
026 *       .{@link RestOpSession#getRequest() getRequest}()
027 *       .{@link RestRequest#getMethod() getMethod}();
028 * </p>
029 *
030 * <p>
031 * The parameter type must be {@link String}.
032 *
033 * <h5 class='section'>See Also:</h5><ul>
034 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.JavaMethodParameters">Java Method Parameters</a>
035 * </ul>
036 */
037public class MethodArg implements RestOpArg {
038
039   /**
040    * Static creator.
041    *
042    * @param paramInfo The Java method parameter being resolved.
043    * @return A new {@link MethodArg}, or <jk>null</jk> if the parameter isn't annotated with {@link Method}.
044    */
045   public static MethodArg create(ParamInfo paramInfo) {
046      if (paramInfo.hasAnnotation(Method.class))
047         return new MethodArg();
048      return null;
049   }
050
051   /**
052    * Constructor.
053    */
054   protected MethodArg() {
055   }
056
057   @Override /* RestOpArg */
058   public Object resolve(RestOpSession opSession) throws Exception {
059      return opSession.getRequest().getMethod();
060   }
061}