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.rest.*;
020import org.apache.juneau.rest.annotation.*;
021
022/**
023 * REST java method parameter resolver.
024 *
025 * <p>
026 * Used to resolve parameter values when invoking {@link RestOp}-annotated methods.
027 *
028 * <h5 class='figure'>Example:</h5>
029 * <p class='bjava'>
030 *    <jc>// A simple parameter resolver that resolves TimeZone parameters.</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>(ParamInfo <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().getHeaders().getTimeZone();
046 *       }
047 *    }
048 * </p>
049 *
050 * <h5 class='section'>See Also:</h5><ul>
051 *    <li class='jm'>{@link org.apache.juneau.rest.RestContext.Builder#restOpArgs(Class...)}
052 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestOpAnnotatedMethodBasics">@RestOp-Annotated Method Basics</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   Object resolve(RestOpSession opSession) throws Exception;
065}