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