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.jsonschema.*; 020import org.apache.juneau.parser.*; 021import org.apache.juneau.reflect.*; 022import org.apache.juneau.rest.*; 023import org.apache.juneau.rest.annotation.*; 024import org.apache.juneau.serializer.*; 025import org.apache.juneau.utils.*; 026 027/** 028 * Resolves method parameters on {@link RestOp}-annotated Java methods of types found on the {@link RestOpContext} object. 029 * 030 * <ul class='javatree'> 031 * <li class='jc'>{@link JsonSchemaGenerator} 032 * <li class='jc'>{@link ParserSet} 033 * <li class='jc'>{@link RestOpContext} 034 * <li class='jc'>{@link SerializerSet} 035 * </ul> 036 * 037 * <h5 class='section'>See Also:</h5><ul> 038 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JavaMethodParameters">Java Method Parameters</a> 039 * </ul> 040 */ 041public class RestOpContextArgs extends SimpleRestOperationArg { 042 043 /** 044 * Static creator. 045 * 046 * @param paramInfo The Java method parameter being resolved. 047 * @return A new arg, or <jk>null</jk> if the parameter type is not one of the supported types. 048 */ 049 public static RestOpContextArgs create(ParamInfo paramInfo) { 050 if (paramInfo.isType(JsonSchemaGenerator.class)) 051 return new RestOpContextArgs(RestOpContext::getJsonSchemaGenerator); 052 if (paramInfo.isType(ParserSet.class)) 053 return new RestOpContextArgs(RestOpContext::getParsers); 054 if (paramInfo.isType(RestOpContext.class)) 055 return new RestOpContextArgs(x->x); 056 if (paramInfo.isType(SerializerSet.class)) 057 return new RestOpContextArgs(RestOpContext::getSerializers); 058 return null; 059 } 060 061 /** 062 * Constructor. 063 * 064 * @param <T> The function return type. 065 * @param function The function for finding the arg. 066 */ 067 protected <T> RestOpContextArgs(ThrowingFunction<RestOpContext,T> function) { 068 super(session -> function.apply(session.getContext())); 069 } 070}