001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2021–2022 microBean™.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * 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
014 * implied.  See the License for the specific language governing
015 * permissions and limitations under the License.
016 */
017package org.microbean.loader.jackson.properties;
018
019import java.lang.reflect.Type;
020
021import java.util.function.Supplier;
022
023import com.fasterxml.jackson.databind.ObjectMapper;
024
025import com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper;
026
027import org.microbean.loader.jackson.InputStreamJacksonProvider;
028
029import org.microbean.invoke.CachingSupplier;
030
031/**
032 * An {@link InputStreamJacksonProvider} that reads Java
033 * properties-formatted files and classpath resources.
034 *
035 * @author <a href="https://about.me/lairdnelson"
036 * target="_parent">Laird Nelson</a>
037 *
038 * @see InputStreamJacksonProvider
039 */
040public class PropertiesProvider extends InputStreamJacksonProvider {
041
042
043  /*
044   * Constructors.
045   */
046
047
048  /**
049   * Creates a new {@link PropertiesProvider} that reads Java
050   * properties-formatted {@code application.properties} classpath
051   * resources.
052   *
053   * @see #PropertiesProvider(Type, String)
054   */
055  public PropertiesProvider() {
056    this(null, "application.properties");
057  }
058
059  /**
060   * Creates a new {@link PropertiesProvider}.
061   *
062   * @param resourceName the name of the classpath resource to read
063   * from; must not be {@code null}
064   *
065   * @exception NullPointerException if {@code resourceName} is {@code
066   * null}
067   *
068   * @see #PropertiesProvider(Type, String)
069   */
070  public PropertiesProvider(final String resourceName) {
071    this(null, resourceName);
072  }
073
074  /**
075   * Creates a new {@link PropertiesProvider}.
076   *
077   * @param lowerBound the {@linkplain #lowerBound() lower type bound}
078   * of this {@link InputStreamJacksonProvider} implementation; may be
079   * {@code null}
080   *
081   * @param resourceName the name of the classpath resource to read
082   * from; must not be {@code null}
083   *
084   * @exception NullPointerException if {@code resourceName} is {@code
085   * null}
086   */
087  public PropertiesProvider(final Type lowerBound, final String resourceName) {
088    super(lowerBound, new CachingSupplier<>(JavaPropsMapper::new), resourceName);
089  }
090
091}