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.internal.*; 016 017/** 018 * Denotes the default resolver for child resources. 019 * 020 * The default implementation simply instantiates the class using one of the following constructors: 021 * <ul> 022 * <li><code><jk>public</jk> T(RestContextBuilder)</code> 023 * <li><code><jk>public</jk> T()</code> 024 * </ul> 025 * 026 * <p> 027 * The former constructor can be used to get access to the {@link RestContextBuilder} object to get access to the 028 * config file and initialization information or make programmatic modifications to the resource before 029 * full initialization. 030 * 031 * <p> 032 * Child classes can also be defined as inner-classes of the parent resource class. 033 * 034 * <h5 class='section'>See Also:</h5> 035 * <ul> 036 * <li class='link'><a class="doclink" href="../../../../overview-summary.html#juneau-rest-server.ResourceResolvers">Overview > juneau-rest-server > Resource Resolvers</a> 037 * </ul> 038 */ 039public class BasicRestResourceResolver implements RestResourceResolver { 040 041 @Override /* RestResourceResolver */ 042 public Object resolve(Object parent, Class<?> c, RestContextBuilder builder) throws Exception { 043 try { 044 Object r = ClassUtils.newInstanceFromOuter(parent, Object.class, c, true, builder); 045 if (r != null) 046 return r; 047 } catch (Exception e) { 048 throw new RestServletException("Could not instantiate resource class ''{0}''", c.getName()).initCause(e); 049 } 050 throw new RestServletException("Could not find public constructor for class ''{0}''.", c); 051 } 052}