View Javadoc

1   /*
2    * Copyright 2004-2005, 2007 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 java.util.Locale;
19  
20  import net.sf.morph.transform.DecoratedConverter;
21  import net.sf.morph.transform.TransformationException;
22  import net.sf.morph.transform.transformers.BaseTransformer;
23  
24  /**
25   * Converts <code>null</code> to <code>null</code>.
26   * @deprecated an IdentityConverter can do the same thing.
27   * @author Matt Sgarlata
28   * @since Dec 31, 2004
29   */
30  public class NullConverter extends BaseTransformer implements DecoratedConverter {
31  
32  	private static final Class[] SOURCE_TYPES = { null };
33  	
34  	private static final Class[] DESTINATION_TYPES = { null, Object.class };
35  
36  	/**
37  	 * {@inheritDoc}
38  	 */
39  	protected Object convertImpl(Class destinationClass, Object source,
40  		Locale locale) throws Exception {
41  
42  		if (source == null) {
43  			return null;
44  		}
45  		throw new TransformationException(destinationClass, source);
46  	}
47  
48  	/**
49  	 * {@inheritDoc}
50  	 */
51  	protected boolean isPerformingLogging() {
52  		// this transformation is trivial; don't clutter the log with it
53  		return false;
54  	}
55  
56  	/**
57  	 * {@inheritDoc}
58  	 */
59  	protected boolean isWrappingRuntimeExceptions() {
60  	    return true;
61      }
62  
63  	/**
64  	 * {@inheritDoc}
65  	 */
66  	protected Class[] getSourceClassesImpl() throws Exception {
67  		return SOURCE_TYPES;
68  	}
69  
70  	/**
71  	 * {@inheritDoc}
72  	 */
73  	protected Class[] getDestinationClassesImpl() throws Exception {
74  		return DESTINATION_TYPES;
75  	}
76  
77  }