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; 014 015import org.apache.juneau.rest.annotation.*; 016 017/** 018 * Class used to resolve {@link Class} objects to instances. 019 * 020 * <p> 021 * Used to convert classes defined via {@link RestResource#children() @RestResource.children()} into child instances. 022 * 023 * <p> 024 * Subclasses can be created to provide customized resource resolution. 025 * These can be associated with REST resources in one of the following ways: 026 * <ul> 027 * <li>{@link RestResource#resourceResolver() @RestResource.resourceResolver()} annotation. 028 * <li>{@link RestContextBuilder#resourceResolver(Class)}/{@link RestContextBuilder#resourceResolver(RestResourceResolver)} 029 * methods. 030 * </ul> 031 * 032 * Implementations must provide one of the following public constructors: 033 * <ul> 034 * <li>RestResourceResolver() 035 * <li>RestResourceResolver(RestContext) 036 * </ul> 037 * 038 * <h5 class='section'>See Also:</h5> 039 * <ul> 040 * <li class='link'><a class="doclink" href="../../../../overview-summary.html#juneau-rest-server.ResourceResolvers">Overview > juneau-rest-server > Resource Resolvers</a> 041 * </ul> 042 */ 043public interface RestResourceResolver { 044 045 /** 046 * Represents no RestResourceResolver. 047 * 048 * <p> 049 * Used on annotation to indicate that the value should be inherited from the parent class, and 050 * ultimately {@link BasicRestResourceResolver} if not specified at any level. 051 */ 052 public interface Null extends RestResourceResolver {} 053 054 /** 055 * Resolves the specified class to a resource object. 056 * 057 * <p> 058 * Subclasses can override this method to provide their own custom resolution. 059 * 060 * <p> 061 * The default implementation simply creates a new class instance using {@link Class#newInstance()}. 062 * 063 * @param parent 064 * The parent resource (i.e. the instance whose class has the {@link RestResource#children() @RestResource.children()} annotation. 065 * @param c The class to resolve. 066 * @param builder The initialization configuration for the resource. 067 * @return The instance of that class. 068 * @throws Exception If class could not be resolved. 069 */ 070 Object resolve(Object parent, Class<?> c, RestContextBuilder builder) throws Exception; 071}