View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.configuration2.interpol;
18  
19  /**
20   * <p>
21   * Definition of an interface for looking up variables during interpolation.
22   * </p>
23   * <p>
24   * Objects implementing this interface can be assigned a variable prefix and added to a
25   * {@link ConfigurationInterpolator} object. Whenever the {@code ConfigurationInterpolator} encounters a property value
26   * referencing a variable, e.g. {@code ${prefix:variableName}}, it extracts the prefix and finds the matching
27   * {@code Lookup} object. Then this object is asked to resolve the variable name and provide the corresponding value.
28   * </p>
29   * <p>
30   * This interface defines a single method for performing variable lookup. It is passed the name of a variable and has to
31   * return the corresponding value. It is of course up to a specific implementation how this is done. If the variable
32   * name cannot be resolved, an implementation has to return <b>null</b>.
33   * </p>
34   * <p>
35   * Note: Implementations must be aware that they can be accessed concurrently. This is for instance the case if a
36   * configuration object is read by multiple threads or if a {@code Lookup} object is shared by multiple configurations.
37   * </p>
38   *
39   * @since 2.0
40   */
41  public interface Lookup {
42      /**
43       * Looks up the value of the specified variable. This method is called by {@link ConfigurationInterpolator} with the
44       * variable name extracted from the expression to interpolate (i.e. the prefix name has already been removed). A
45       * concrete implementation has to return the value of this variable or <b>null</b> if the variable name is unknown.
46       *
47       * @param variable the name of the variable to be resolved
48       * @return the value of this variable or <b>null</b>
49       */
50      Object lookup(String variable);
51  }