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