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 * https://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.io;
18
19 /**
20 * <p>
21 * Definition of an interface to be implemented by {@link FileBased} objects which need access to the current
22 * {@link FileLocator}.
23 * </p>
24 * <p>
25 * When loading or saving a {@code FileBased} object using {@code FileHandler} the handler eventually invokes the
26 * {@code read()} or {@code write()} methods passing in a reader or writer. For some implementations this may not be
27 * sufficient because they need information about the current location. For instance, a concrete {@code FileBased}
28 * implementation may have to resolve other data sources based on relative file names which have to be interpreted in
29 * the context of the current file location.
30 * </p>
31 * <p>
32 * To deal with such scenarios, affected implementations can choose to implement this interface. They are then passed
33 * the current location to the file being accessed before their {@code read()} or {@code write()} method is called.
34 * </p>
35 *
36 * @since 2.0
37 */
38 public interface FileLocatorAware {
39 /**
40 * Passes the current {@code FileLocator} to this object. Note that this {@code FileLocator} object is only temporarily
41 * valid for the following invocation of {@code read()} or {@code write(}. Depending on the state of the
42 * {@code FileHandler} and which of its methods was called, the object may not be fully initialized. For instance, if
43 * the {@code FileHandler}'s {@code load(InputStream)} method was called, no file information is available, and all
44 * methods of the {@code FileLocator} will return <strong>null</strong>.
45 *
46 * @param locator the current {@code FileLocator}
47 */
48 void initFileLocator(FileLocator locator);
49 }