View Javadoc

1   /*
2    * Copyright 2006-2016 The JGUIraffe Team.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License")
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.jguiraffe.transform;
17  
18  /**
19   * <p>
20   * Definition of the <code>Transformer</code> interface.
21   * </p>
22   * <p>
23   * A <code>Transformer</code> is an object that converts a given object into a
24   * different format or type. It is completely up to a concrete implementation
25   * how this conversion works. An example would be a formatter object that
26   * creates formatted string representations for objects. The other direction
27   * (from a formatted user input to a specific Java class) could also be done by
28   * a transformer.
29   * </p>
30   *
31   * @author Oliver Heger
32   * @version $Id: Transformer.java 205 2012-01-29 18:29:57Z oheger $
33   */
34  public interface Transformer
35  {
36      /**
37       * The main method of the <code>Transformer</code> interface. This method
38       * takes the object to be transformed and returns an appropriate converted
39       * representation of it. The also passed in <code>TransformerContext</code>
40       * object can be used to access system information that may be needed for
41       * generating the transformed representation, e.g. the actual
42       * <code>Locale</code>.
43       *
44       * @param o the object to be transformed
45       * @param ctx the <code>TransformerContext</code> object
46       * @return the transformed instance
47       * @throws Exception Transformers can throw arbitrary exceptions if the
48       * conversion is not possible
49       */
50      Object transform(Object o, TransformerContext ctx) throws Exception;
51  }