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.*; 020import org.apache.juneau.http.annotation.*; 021import org.apache.juneau.httppart.bean.*; 022import org.apache.juneau.reflect.*; 023import org.apache.juneau.rest.*; 024import org.apache.juneau.rest.annotation.*; 025 026/** 027 * Resolves method parameters annotated with {@link Request} on {@link RestOp}-annotated Java methods. 028 * 029 * <p> 030 * The parameter value is resolved using: 031 * <p class='bjava'> 032 * <jv>opSession</jv> 033 * .{@link RestOpSession#getRequest() getRequest}() 034 * .{@link RestRequest#getRequest(RequestBeanMeta) getRequest}(<jv>meta</jv>); 035 * </p> 036 * 037 * <p> 038 * {@link RequestBeanMeta meta} is derived from the {@link Request} annotation and context configuration. 039 * 040 * <h5 class='section'>See Also:</h5><ul> 041 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RequestBeans">Request Beans</a> 042 * </ul> 043 */ 044public class RequestBeanArg implements RestOpArg { 045 private final RequestBeanMeta meta; 046 047 /** 048 * Static creator. 049 * 050 * @param paramInfo The Java method parameter being resolved. 051 * @param annotations The annotations to apply to any new part parsers. 052 * @return A new {@link RequestBeanArg}, or <jk>null</jk> if the parameter is not annotated with {@link Request}. 053 */ 054 public static RequestBeanArg create(ParamInfo paramInfo, AnnotationWorkList annotations) { 055 if (paramInfo.hasAnnotation(Request.class)) 056 return new RequestBeanArg(paramInfo, annotations); 057 return null; 058 } 059 060 /** 061 * Constructor. 062 * 063 * @param paramInfo The Java method parameter being resolved. 064 * @param annotations The annotations to apply to any new part parsers. 065 */ 066 protected RequestBeanArg(ParamInfo paramInfo, AnnotationWorkList annotations) { 067 this.meta = RequestBeanMeta.create(paramInfo, annotations); 068 } 069 070 @Override /* RestOpArg */ 071 public Object resolve(RestOpSession opSession) throws Exception { 072 return opSession.getRequest().getRequest(meta); 073 } 074}