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