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.convert;
18  
19  /**
20   * <p>
21   * Definition of an interface used by {@link ListDelimiterHandler} to perform additional transformations on behalf of a
22   * configuration when a property value is escaped.
23   * </p>
24   * <p>
25   * Some {@code Configuration} implementations require a special encoding of their property values before they get
26   * written on disk. In some constellations, e.g. when a property with multiple values is to be forced on a single line,
27   * this encoding has to be done together with the escaping of list delimiter characters - which is in the responsibility
28   * of {@link ListDelimiterHandler}.
29   * </p>
30   * <p>
31   * In order to allow a proper collaboration between the parties involved, this interface was introduced. A configuration
32   * object provides an implementation of {@code ValueTransformer} and passes it to the {@code ListDelimiterHandler} when
33   * escaping of properties is needed. The delimiter handler can then call back to perform the additional encoding as its
34   * pleasure.
35   * </p>
36   *
37   * @since 2.0
38   */
39  public interface ValueTransformer {
40      /**
41       * Performs an arbitrary encoding of the passed in value object. This method is called by a {@link ListDelimiterHandler}
42       * implementation before or after list delimiters have been escaped.
43       *
44       * @param value the property value to be transformed
45       * @return the transformed property value
46       */
47      Object transformValue(Object value);
48  }