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 * <ul class='seealso'> 040 * <li class='link'>{@doc juneau-rest-server.Instantiation.ResourceResolvers} 041 * </ul> 042 */ 043public interface RestResourceResolver extends ResourceResolver { 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 * @param args Optional arguments to pass to constructor 068 * @return The instance of that class. 069 * @throws Exception If class could not be resolved. 070 */ 071 <T> T resolve(Object parent, Class<T> c, RestContextBuilder builder, Object...args) throws Exception; 072}