View Javadoc

1   /*
2    * Copyright 2004-2005 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * 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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package net.sf.morph.transform.transformers;
17  
18  import net.sf.morph.transform.DecoratedTransformer;
19  import net.sf.morph.transform.Transformer;
20  
21  /**
22   * Decorates any Transformer so that it implements DecoratedTransformer.  Example usage:
23   * 
24   * <pre>
25   * Transformer myTransformer = new MyTransformer();
26   * DecoratedTransformer decoratedTransformer = new DecoratedTransformer(myTransformer);
27   * 
28   * // now use decoratedTransformer instead of myTransformer
29   * if (decoratedTransformer.isTransformable(destinationType, sourceType)) {
30   *     ...
31   * }
32   * </pre>
33   * 
34   * @author Matt Sgarlata
35   * @since Dec 5, 2004
36   */
37  public class TransformerDecorator extends BaseTransformer implements DecoratedTransformer {
38  	
39  	private Transformer transformer;
40  	
41  	public TransformerDecorator() { }
42  		
43  	public TransformerDecorator(Transformer transformer) {
44  		this();
45  		this.transformer = transformer;
46  	}
47  
48  	public Class[] getSourceClassesImpl() {
49  		return transformer.getSourceClasses();
50  	}
51  
52  	public Class[] getDestinationClassesImpl() {
53  		return transformer.getDestinationClasses();
54  	}
55  
56  	protected boolean isWrappingRuntimeExceptions() {
57  	    // the whole point of this converter is for decorating user defined
58  		// transformers, so we don't want to eat their exceptions ;)
59  	    return false;
60      }
61  
62  	/**
63  	 * @return Returns the transformer.
64  	 */
65  	public Transformer getTransformer() {
66  		return transformer;
67  	}
68  
69  	/**
70  	 * @param transformer
71  	 *            The transformer to set.
72  	 */
73  	public void setTransformer(Transformer transformer) {
74  		this.transformer = transformer;
75  	}
76  }