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.parser.*; 016import org.apache.juneau.reflect.*; 017import org.apache.juneau.rest.*; 018import org.apache.juneau.rest.annotation.*; 019import org.apache.juneau.rest.httppart.*; 020 021/** 022 * Resolves method parameters of type {@link ReaderParser} on {@link RestOp}-annotated Java methods. 023 * 024 * <p> 025 * The parameter value is resolved using: 026 * <p class='bjava'> 027 * <jv>opSession</jv> 028 * .{@link RestOpSession#getRequest() getRequest}() 029 * .{@link RestRequest#getContent() getContent}() 030 * .{@link RequestContent#getParserMatch() getParserMatch}() 031 * .{@link ParserMatch#getParser() getParser}(); 032 * </p> 033 * 034 * <h5 class='section'>See Also:</h5><ul> 035 * <li class='link'><a class="doclink" href="../../../../../index.html#jrs.JavaMethodParameters">Java Method Parameters</a> 036 * </ul> 037 */ 038public class ReaderParserArg extends SimpleRestOperationArg { 039 040 /** 041 * Static creator. 042 * 043 * @param paramInfo The Java method parameter being resolved. 044 * @return A new {@link ReaderParserArg}, or <jk>null</jk> if the parameter type is not {@link ReaderParser}. 045 */ 046 public static ReaderParserArg create(ParamInfo paramInfo) { 047 if (paramInfo.isType(ReaderParser.class)) 048 return new ReaderParserArg(); 049 return null; 050 } 051 052 /** 053 * Constructor. 054 */ 055 protected ReaderParserArg() { 056 super(opSession -> opSession.getRequest().getContent().getParserMatch().map(ParserMatch::getParser).filter(ReaderParser.class::isInstance).orElse(null)); 057 } 058}