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.rest.*;
016import org.apache.juneau.rest.annotation.*;
017
018/**
019 * REST java method parameter resolver.
020 *
021 * <p>
022 * Used to resolve parameter values when invoking {@link RestOp}-annotated methods.
023 *
024 * <h5 class='figure'>Example:</h5>
025 * <p class='bjava'>
026 *    <jc>// A simple parameter resolver that resolves TimeZone parameters.</jc>
027 *    <jk>public class</jk> TimeZoneArg <jk>implements</jk> RestOpArg {
028 *
029 *       <jc>// Implementers must provide a static creator method that returns a RestParam if it's
030 *       // applicable to the specified parameter.</jc>
031 *       <jk>public static</jk> TimeZoneArg <jsm>create</jsm>(ParamInfo <jv>paramInfo</jv>) {
032 *          <jk>if</jk> (<jv>paramInfo</jv>.isType(TimeZone.<jk>class</jk>))
033 *             <jk>return new</jk> TimeZoneArg();
034 *          <jk>return null</jk>;
035 *       }
036 *
037 *       <jk>protected</jk> TimeZoneArg() {}
038 *
039 *       <ja>@Override</ja>
040 *       <jk>public</jk> Object resolve(RestOpSession <jv>opSession</jv>) <jk>throws</jk> Exception {
041 *          <jk>return</jk> <jv>opSession</jv>.getRequest().getHeaders().getTimeZone();
042 *       }
043 *    }
044 * </p>
045 *
046 * <h5 class='section'>See Also:</h5><ul>
047 *    <li class='jm'>{@link org.apache.juneau.rest.RestContext.Builder#restOpArgs(Class...)}
048 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.RestOpAnnotatedMethods">@RestOp-Annotated Methods</a>
049 * </ul>
050 */
051public interface RestOpArg {
052
053   /**
054    * Resolves the parameter object.
055    *
056    * @param opSession The rest call.
057    * @return The resolved object.
058    * @throws Exception Generic error occurred.
059    */
060   Object resolve(RestOpSession opSession) throws Exception;
061}