001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2017-2018 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.configuration.spi;
018
019import java.io.Serializable;
020
021import java.util.Collections;
022import java.util.Map;
023import java.util.Set;
024
025import org.microbean.configuration.Configurations;
026
027import org.microbean.configuration.api.ConfigurationValue;
028
029/**
030 * An {@link AbstractConfiguration} conceptually housing only the
031 * configuration property that returns a {@link Map}-convertible
032 * {@link String} representing configuration coordinates for the
033 * calling application.
034 *
035 * @author <a href="https://about.me/lairdnelson"
036 * target="_parent">Laird Nelson</a>
037 *
038 * @see Configurations#getConfigurationCoordinates()
039 */
040public final class ConfigurationCoordinates extends AbstractConfiguration implements Serializable {  
041
042
043  /*
044   * Static fields.
045   */
046
047
048  /**
049   * The version of this class for {@linkplain Serializable
050   * serialization} purposes.
051   */
052  private static final long serialVersionUID = 1L;
053  
054
055  /*
056   * Constructors.
057   */
058
059  
060  /**
061   * Creates a new {@link ConfigurationCoordinates}.
062   */
063  public ConfigurationCoordinates() {
064    super();
065  }
066
067
068  /*
069   * Instance methods.
070   */
071
072  
073  /**
074   * Attempts to return a value for the {@linkplain
075   * System#getProperty(String, String) System property} named {@value
076   * org.microbean.configuration.Configurations#CONFIGURATION_COORDINATES}.
077   *
078   * <p>This method may return {@code null}.</p>
079   *
080   * @param ignoredConfigurationCoordinates a {@link Map} of
081   * configuration coordinates in effect for the request; effectively
082   * ignored since by definition this method will be returning a
083   * {@link ConfigurationValue} {@linkplain
084   * ConfigurationValue#getValue() containing} a {@link String} value
085   * representing a {@link Map} of configuration coordinates for the
086   * caller; may be {@code null}; not used by this implementation
087   *
088   * @param name the name of the configuration property for which a
089   * value should be returned; may be {@code null}
090   *
091   * @return a {@link ConfigurationValue} representing the
092   * configuration coordinates to assign to the caller, or {@code
093   * null}
094   */
095  @Override
096  public final ConfigurationValue getValue(final Map<String, String> ignoredConfigurationCoordinates, final String name) {
097    ConfigurationValue returnValue = null;
098    if (Configurations.CONFIGURATION_COORDINATES.equals(name)) {
099      final String configurationCoordinates = System.getProperty(Configurations.CONFIGURATION_COORDINATES);
100      if (configurationCoordinates != null) {
101        returnValue = new ConfigurationValue(this, null, name, configurationCoordinates, true);
102      }
103    }
104    return returnValue;
105  }
106
107  /**
108   * Returns a {@link Set} of the names of all {@link
109   * ConfigurationValue}s that might be returned by this {@link
110   * Configuration}.
111   *
112   * <p>This method never returns {@code null}.</p>
113   *
114   * <p>This implementation returns a {@link Set} with only the value
115   * of {@link Configurations#CONFIGURATION_COORDINATES} in it.</p>
116   *
117   * @return a non-{@code null} {@link Set} of names
118   */
119  public final Set<String> getNames() {
120    return Collections.singleton(Configurations.CONFIGURATION_COORDINATES);
121  }
122  
123}