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.server.arg;
018
019import org.apache.juneau.rest.server.*;
020
021/**
022 * REST java method parameter resolver.
023 *
024 * <p>
025 * Used to resolve parameter values when invoking {@link RestOp}-annotated methods.
026 *
027 * <h5 class='figure'>Example:</h5>
028 * <p class='bjava'>
029 *    <jc>// A simple parameter resolver that resolves TimeZone parameters from the Time-Zone header.</jc>
030 *    <jc>// (TimeZone parameters are already resolved out-of-the-box; this is purely illustrative.)</jc>
031 *    <jk>public class</jk> TimeZoneArg <jk>implements</jk> RestOpArg {
032 *
033 *       <jc>// Implementers must provide a static creator method that returns a RestParam if it's
034 *       // applicable to the specified parameter.</jc>
035 *       <jk>public static</jk> TimeZoneArg <jsm>create</jsm>(ParameterInfo <jv>paramInfo</jv>) {
036 *          <jk>if</jk> (<jv>paramInfo</jv>.isType(TimeZone.<jk>class</jk>))
037 *             <jk>return new</jk> TimeZoneArg();
038 *          <jk>return null</jk>;
039 *       }
040 *
041 *       <jk>protected</jk> TimeZoneArg() {}
042 *
043 *       <ja>@Override</ja>
044 *       <jk>public</jk> Object resolve(RestOpSession <jv>opSession</jv>) <jk>throws</jk> Exception {
045 *          <jk>return</jk> <jv>opSession</jv>.getRequest().getTimeZone().<jsm>orElse</jsm>(<jk>null</jk>);
046 *       }
047 *    }
048 * </p>
049 *
050 * <h5 class='section'>See Also:</h5><ul>
051 *    <li class='ja'>{@link Rest#restOpArgs()}
052 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestOpAnnotatedMethods">@RestOp-Annotated Method</a>
053 * </ul>
054 */
055public interface RestOpArg {
056
057   /**
058    * Resolves the parameter object.
059    *
060    * @param opSession The rest call.
061    * @return The resolved object.
062    * @throws Exception Generic error occurred.
063    */
064   @SuppressWarnings({
065      "java:S112" // throws Exception intentional - callback/lifecycle method
066   })
067   Object resolve(RestOpSession opSession) throws Exception;
068}