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