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 * Definition of an interface for looking up variables during interpolation.
022 * </p>
023 * <p>
024 * Objects implementing this interface can be assigned a variable prefix and added to a
025 * {@link ConfigurationInterpolator} object. Whenever the {@code ConfigurationInterpolator} encounters a property value
026 * referencing a variable, e.g. {@code ${prefix:variableName}}, it extracts the prefix and finds the matching
027 * {@code Lookup} object. Then this object is asked to resolve the variable name and provide the corresponding value.
028 * </p>
029 * <p>
030 * This interface defines a single method for performing variable lookup. It is passed the name of a variable and has to
031 * return the corresponding value. It is of course up to a specific implementation how this is done. If the variable
032 * name cannot be resolved, an implementation has to return <b>null</b>.
033 * </p>
034 * <p>
035 * Note: Implementations must be aware that they can be accessed concurrently. This is for instance the case if a
036 * configuration object is read by multiple threads or if a {@code Lookup} object is shared by multiple configurations.
037 * </p>
038 *
039 * @since 2.0
040 */
041public interface Lookup {
042    /**
043     * Looks up the value of the specified variable. This method is called by {@link ConfigurationInterpolator} with the
044     * variable name extracted from the expression to interpolate (i.e. the prefix name has already been removed). A
045     * concrete implementation has to return the value of this variable or <b>null</b> if the variable name is unknown.
046     *
047     * @param variable the name of the variable to be resolved
048     * @return the value of this variable or <b>null</b>
049     */
050    Object lookup(String variable);
051}