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