001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest.arg; 018 019import org.apache.juneau.reflect.*; 020import org.apache.juneau.rest.*; 021import org.apache.juneau.rest.annotation.*; 022import org.apache.juneau.rest.util.*; 023import org.apache.juneau.utils.*; 024 025/** 026 * Resolves method parameters on {@link RestOp}-annotated Java methods of types found on the {@link RestSession} object. 027 * 028 * <ul class='javatree'> 029 * <li class='jc'>{@link RestSession} 030 * <li class='jc'>{@link UrlPath} 031 * <li class='jc'>{@link UrlPathMatch} 032 * </ul> 033 * 034 * <h5 class='section'>See Also:</h5><ul> 035 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JavaMethodParameters">Java Method Parameters</a> 036 * </ul> 037 */ 038public class RestSessionArgs extends SimpleRestOperationArg { 039 040 /** 041 * Static creator. 042 * 043 * @param paramInfo The Java method parameter being resolved. 044 * @return A new arg, or <jk>null</jk> if the parameter type is not one of the supported types. 045 */ 046 public static RestSessionArgs create(ParamInfo paramInfo) { 047 if (paramInfo.isType(RestSession.class)) 048 return new RestSessionArgs(x->x); 049 if (paramInfo.isType(UrlPath.class)) 050 return new RestSessionArgs(RestSession::getUrlPath); 051 if (paramInfo.isType(UrlPathMatch.class)) 052 return new RestSessionArgs(RestSession::getUrlPathMatch); 053 return null; 054 } 055 056 /** 057 * Constructor. 058 * 059 * @param <T> The function return type. 060 * @param function The function for finding the arg. 061 */ 062 protected <T> RestSessionArgs(ThrowingFunction<RestSession,T> function) { 063 super(session -> function.apply(session.getRestSession())); 064 } 065}