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.io;
018
019/**
020 * <p>
021 * Definition of an interface to be implemented by {@link FileBased} objects
022 * which need access to the current {@link FileLocator}.
023 * </p>
024 * <p>
025 * When loading or saving a {@code FileBased} object using {@code FileHandler}
026 * the handler eventually invokes the {@code read()} or {@code write()} methods
027 * passing in a reader or writer. For some implementations this may not be
028 * sufficient because they need information about the current location. For
029 * instance, a concrete {@code FileBased} implementation may have to resolve
030 * other data sources based on relative file names which have to be interpreted
031 * in the context of the current file location.
032 * </p>
033 * <p>
034 * To deal with such scenarios, affected implementations can choose to implement
035 * this interface. They are then passed the current location to the file being
036 * accessed before their {@code read()} or {@code write()} method is called.
037 * </p>
038 *
039 * @since 2.0
040 */
041public interface FileLocatorAware
042{
043    /**
044     * Passes the current {@code FileLocator} to this object. Note that this
045     * {@code FileLocator} object is only temporarily valid for the following
046     * invocation of {@code read()} or {@code write(}. Depending on the state of
047     * the {@code FileHandler} and which of its methods was called, the object
048     * may not be fully initialized. For instance, if the {@code FileHandler}'s
049     * {@code load(InputStream)} method was called, no file information is
050     * available, and all methods of the {@code FileLocator} will return
051     * <b>null</b>.
052     *
053     * @param locator the current {@code FileLocator}
054     */
055    void initFileLocator(FileLocator locator);
056}