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 java.util.function.*;
016
017/**
018 * A supplier of a REST resource bean.
019 *
020 * <p>
021 * Pretty much just a normal supplier, but wrapped in a concrete class so that it can be retrieved by class name.
022 */
023public class ResourceSupplier implements Supplier<Object> {
024
025   private final Supplier<?> supplier;
026   private final Class<?> resourceClass;
027
028   /**
029    * Constructor.
030    *
031    * @param resourceClass The resource class.
032    *    <br>May or may not be the same as the object returned by the supplier (e.g. supplier returns a proxy).
033    * @param supplier The supplier of the bean.
034    */
035   public ResourceSupplier(Class<?> resourceClass, Supplier<?> supplier) {
036      this.resourceClass = resourceClass;
037      this.supplier = supplier;
038   }
039
040   /**
041    * Returns the resource class.
042    *
043    * <p>
044    * May or may not be the same as the object returned by the supplier (e.g. supplier returns a proxy).
045    *
046    * @return The resource class.
047    */
048   public Class<?> getResourceClass() {
049      return resourceClass;
050   }
051
052   @Override
053   public Object get() {
054      return supplier.get();
055   }
056}