View Javadoc

1   /*
2    * Copyright 2004-2005, 2007-2008 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.converters;
17  
18  import net.sf.morph.Defaults;
19  import net.sf.morph.transform.Converter;
20  import net.sf.morph.transform.Transformer;
21  import net.sf.morph.transform.transformers.SimpleDelegatingTransformer;
22  
23  /**
24   * Converts an object to a textual representation by delegating to
25   * {@link net.sf.morph.transform.converters.ContainerToPrettyTextConverter},
26   * {@link net.sf.morph.transform.converters.BooleanToTextConverter}, 
27   * {@link net.sf.morph.transform.converters.TimeToTextConverter},
28   * {@link net.sf.morph.transform.converters.NumberToTextConverter} and
29   * {@link net.sf.morph.transform.converters.ObjectToTextConverter}.
30   * 
31   * @author Matt Sgarlata
32   * @since Jan 1, 2005
33   */
34  public class DefaultToTextConverter extends SimpleDelegatingTransformer {
35  
36  	/**
37  	 * Used to specify the destination classes of this converter, and to
38  	 * determine if a transformation is possible.
39  	 * 
40  	 * @see {@link DefaultToTextConverter#isTransformableImpl(Class, Class)}
41  	 * @see {@link DefaultToTextConverter#getDestinationClassesImpl()}
42  	 */
43  	private Converter textConverter;
44  
45  	/**
46  	 * Create a new DefaultToTextConverter.
47  	 */
48  	public DefaultToTextConverter() {
49  	    super();
50      }
51  
52  	/**
53  	 * Create a new DefaultToTextConverter.
54  	 * @param components
55  	 * @param appendDefaultComponents
56  	 */
57  	public DefaultToTextConverter(Transformer[] components, boolean appendDefaultComponents) {
58  	    super(components, appendDefaultComponents);
59      }
60  
61  	/**
62  	 * Create a new DefaultToTextConverter.
63  	 * @param components
64  	 */
65  	public DefaultToTextConverter(Transformer[] components) {
66  	    super(components);
67      }
68  
69  	/**
70  	 * {@inheritDoc}
71  	 */
72  	protected Transformer[] createDefaultComponents() {
73  		return new Transformer[] { new ContainerToPrettyTextConverter(),
74  		        new BooleanToTextConverter(), new TimeToTextConverter(),
75  		        new NumberToTextConverter(), new ObjectToTextConverter() };
76  	}
77  
78  	/**
79  	 * Unused
80  	 * @return
81  	 * @deprecated since Morph 1.1
82  	 */
83  	public Converter getTextConverter() {
84  		if (textConverter == null) {
85  			setTextConverter(Defaults.createTextConverter());
86  		}
87  		return textConverter;
88  	}
89  
90  	/**
91  	 * Unused
92  	 * @param textConverter
93  	 * @deprecated since Morph 1.1
94  	 */
95  	public void setTextConverter(Converter textConverter) {
96  		this.textConverter = textConverter;
97  	}
98  }