001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest; 018 019import java.util.function.*; 020 021/** 022 * A supplier of a REST resource bean. 023 * 024 * <p> 025 * Pretty much just a normal supplier, but wrapped in a concrete class so that it can be retrieved by class name. 026 */ 027public class ResourceSupplier implements Supplier<Object> { 028 029 private final Supplier<?> supplier; 030 private final Class<?> resourceClass; 031 032 /** 033 * Constructor. 034 * 035 * @param resourceClass The resource class. 036 * <br>May or may not be the same as the object returned by the supplier (e.g. supplier returns a proxy). 037 * @param supplier The supplier of the bean. 038 */ 039 public ResourceSupplier(Class<?> resourceClass, Supplier<?> supplier) { 040 this.resourceClass = resourceClass; 041 this.supplier = supplier; 042 } 043 044 /** 045 * Returns the resource class. 046 * 047 * <p> 048 * May or may not be the same as the object returned by the supplier (e.g. supplier returns a proxy). 049 * 050 * @return The resource class. 051 */ 052 public Class<?> getResourceClass() { 053 return resourceClass; 054 } 055 056 @Override 057 public Object get() { 058 return supplier.get(); 059 } 060}