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.*;
018import org.apache.juneau.rest.util.*;
019import org.apache.juneau.utils.*;
020
021/**
022 * Resolves method parameters on {@link RestOp}-annotated Java methods of types found on the {@link RestSession} object.
023 *
024 * <ul class='javatree'>
025 *    <li class='jc'>{@link RestSession}
026 *    <li class='jc'>{@link UrlPath}
027 *    <li class='jc'>{@link UrlPathMatch}
028 * </ul>
029 *
030 * <h5 class='section'>See Also:</h5><ul>
031 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.JavaMethodParameters">Java Method Parameters</a>
032 * </ul>
033 */
034public class RestSessionArgs extends SimpleRestOperationArg {
035
036   /**
037    * Static creator.
038    *
039    * @param paramInfo The Java method parameter being resolved.
040    * @return A new arg, or <jk>null</jk> if the parameter type is not one of the supported types.
041    */
042   public static RestSessionArgs create(ParamInfo paramInfo) {
043      if (paramInfo.isType(RestSession.class))
044         return new RestSessionArgs(x->x);
045      if (paramInfo.isType(UrlPath.class))
046         return new RestSessionArgs(RestSession::getUrlPath);
047      if (paramInfo.isType(UrlPathMatch.class))
048         return new RestSessionArgs(RestSession::getUrlPathMatch);
049      return null;
050   }
051
052   /**
053    * Constructor.
054    *
055    * @param <T> The function return type.
056    * @param function The function for finding the arg.
057    */
058   protected <T> RestSessionArgs(ThrowingFunction<RestSession,T> function) {
059      super(session -> function.apply(session.getRestSession()));
060   }
061}