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