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 java.util.logging.*; 016 017import org.apache.juneau.*; 018import org.apache.juneau.config.*; 019import org.apache.juneau.cp.*; 020import org.apache.juneau.encoders.*; 021import org.apache.juneau.reflect.*; 022import org.apache.juneau.rest.*; 023import org.apache.juneau.rest.annotation.*; 024import org.apache.juneau.rest.debug.*; 025import org.apache.juneau.rest.logger.*; 026import org.apache.juneau.rest.staticfile.*; 027import org.apache.juneau.rest.stats.*; 028import org.apache.juneau.utils.*; 029 030/** 031 * Resolves method parameters on {@link RestOp}-annotated Java methods of types found on the {@link RestContext} object. 032 * 033 * <ul class='javatree'> 034 * <li class='jc'>{@link BeanContext} 035 * <li class='jc'>{@link Config} 036 * <li class='jc'>{@link DebugEnablement} 037 * <li class='jc'>{@link EncoderSet} 038 * <li class='jc'>{@link FileFinder} 039 * <li class='jc'>{@link Logger} 040 * <li class='jc'>{@link MethodExecStore} 041 * <li class='jc'>{@link RestChildren} 042 * <li class='jc'>{@link RestContext} 043 * <li class='jc'>{@link RestContextStats} 044 * <li class='jc'>{@link CallLogger} 045 * <li class='jc'>{@link RestOperations} 046 * <li class='jc'>{@link StaticFiles} 047 * <li class='jc'>{@link ThrownStore} 048 * </ul> 049 * 050 * <h5 class='section'>See Also:</h5><ul> 051 * <li class='link'><a class="doclink" href="../../../../../index.html#jrs.JavaMethodParameters">Java Method Parameters</a> 052 * </ul> 053 */ 054public class RestContextArgs extends SimpleRestOperationArg { 055 056 /** 057 * Static creator. 058 * 059 * @param paramInfo The Java method parameter being resolved. 060 * @return A new arg, or <jk>null</jk> if the parameter type is not one of the supported types. 061 */ 062 public static RestContextArgs create(ParamInfo paramInfo) { 063 if (paramInfo.isType(BeanContext.class)) 064 return new RestContextArgs(RestContext::getBeanContext); 065 if (paramInfo.isType(Config.class)) 066 return new RestContextArgs(RestContext::getConfig); 067 if (paramInfo.isType(DebugEnablement.class)) 068 return new RestContextArgs(RestContext::getDebugEnablement); 069 if (paramInfo.isType(EncoderSet.class)) 070 return new RestContextArgs(RestContext::getEncoders); 071 if (paramInfo.isType(Logger.class)) 072 return new RestContextArgs(RestContext::getLogger); 073 if (paramInfo.isType(MethodExecStore.class)) 074 return new RestContextArgs(RestContext::getMethodExecStore); 075 if (paramInfo.isType(RestChildren.class)) 076 return new RestContextArgs(RestContext::getRestChildren); 077 if (paramInfo.isType(RestContext.class)) 078 return new RestContextArgs(x->x); 079 if (paramInfo.isType(RestContextStats.class)) 080 return new RestContextArgs(RestContext::getStats); 081 if (paramInfo.isType(CallLogger.class)) 082 return new RestContextArgs(RestContext::getCallLogger); 083 if (paramInfo.isType(RestOperations.class)) 084 return new RestContextArgs(RestContext::getRestOperations); 085 if (paramInfo.isType(StaticFiles.class)) 086 return new RestContextArgs(RestContext::getStaticFiles); 087 if (paramInfo.isType(ThrownStore.class)) 088 return new RestContextArgs(RestContext::getThrownStore); 089 return null; 090 } 091 092 /** 093 * Constructor. 094 * 095 * @param <T> The function return type. 096 * @param function The function for finding the arg. 097 */ 098 protected <T> RestContextArgs(ThrowingFunction<RestContext,T> function) { 099 super(session -> function.apply(session.getRestContext())); 100 } 101}