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   * This class provides dummy implementations for the <code>Transformer</code>
21   * and the <code>Validator</code> interfaces.
22   * </p>
23   * <p>
24   * Validation is implemented by always returning a validation result object
25   * indicating a successful validation. Transformation is implemented as a noop,
26   * by simply returning the passed in object. The services of this class can be
27   * obtained using a singleton instance.
28   * </p>
29   *
30   * @author Oliver Heger
31   * @version $Id: DummyTransformer.java 205 2012-01-29 18:29:57Z oheger $
32   */
33  public class DummyTransformer implements Validator, Transformer
34  {
35      /** Stores a reference to the singleton instance. */
36      private static final DummyTransformer INSTANCE = new DummyTransformer();
37  
38      /**
39       * Performs validation. Always returns a positive result.
40       *
41       * @param o the object to check
42       * @param ctx the transformer context (ignored)
43       * @return validation results
44       */
45      public ValidationResult isValid(Object o, TransformerContext ctx)
46      {
47          return DefaultValidationResult.VALID;
48      }
49  
50      /**
51       * Transforms the passed in object. This implementation simply returns the
52       * same object.
53       *
54       * @param o the object to be transformed
55       * @param ctx the transformer context (ignored)
56       * @return the resulting object
57       */
58      public Object transform(Object o, TransformerContext ctx)
59      {
60          return o;
61      }
62  
63      /**
64       * Returns the singleton instance of this class.
65       * @return the shared instance
66       */
67      public static DummyTransformer getInstance()
68      {
69          return INSTANCE;
70      }
71  }