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.commons.configuration2.interpol;
018
019/**
020 * <p>
021 * An enumeration class defining constants for the {@code Lookup} objects
022 * available for each {@code Configuration} object per default.
023 * </p>
024 * <p>
025 * When a new configuration object derived from {@code AbstractConfiguration} is
026 * created it installs a {@link ConfigurationInterpolator} with a default set of
027 * {@link Lookup} objects. These lookups are defined by this enumeration class.
028 * </p>
029 * <p>
030 * All the default {@code Lookup} classes are state-less, thus their instances
031 * can be shared between multiple configuration objects. Therefore, it makes
032 * sense to keep shared instances in this enumeration class.
033 * </p>
034 *
035 * @version $Id: DefaultLookups.java 1624601 2014-09-12 18:04:36Z oheger $
036 * @since 2.0
037 */
038public enum DefaultLookups
039{
040    /** The lookup for system properties. */
041    SYSTEM_PROPERTIES("sys", new SystemPropertiesLookup()),
042
043    /** The lookup for environment properties. */
044    ENVIRONMENT("env", new EnvironmentLookup()),
045
046    /** The lookup for constants. */
047    CONST("const", new ConstantLookup());
048
049    /** The prefix under which the associated lookup object is registered. */
050    private final String prefix;
051
052    /** The associated lookup instance. */
053    private final Lookup lookup;
054
055    /**
056     * Creates a new instance of {@code DefaultLookups} and sets the prefix and
057     * the associated lookup instance.
058     *
059     * @param prfx the prefix
060     * @param look the {@code Lookup} instance
061     */
062    private DefaultLookups(String prfx, Lookup look)
063    {
064        prefix = prfx;
065        lookup = look;
066    }
067
068    /**
069     * Returns the standard prefix for the lookup object of this kind.
070     *
071     * @return the prefix
072     */
073    public String getPrefix()
074    {
075        return prefix;
076    }
077
078    /**
079     * Returns the standard {@code Lookup} instance of this kind.
080     *
081     * @return the associated {@code Lookup} object
082     */
083    public Lookup getLookup()
084    {
085        return lookup;
086    }
087}