1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.ExplicitTransformer;
22 import net.sf.morph.transform.transformers.BaseTransformer;
23 import net.sf.morph.util.ClassUtils;
24
25 /**
26 * Converts an object into that object's class.
27 *
28 * @author Matt Sgarlata
29 * @since Feb 10, 2006
30 */
31 public class ObjectToClassConverter extends BaseTransformer implements DecoratedConverter, ExplicitTransformer {
32 private static final Class[] DEST = new Class[] { Class.class };
33
34 /**
35 * {@inheritDoc}
36 */
37 protected Object convertImpl(Class destinationClass, Object source, Locale locale) throws Exception {
38 return ClassUtils.getClass(source);
39 }
40
41 /**
42 * {@inheritDoc}
43 */
44
45
46 protected boolean isTransformableImpl(Class destinationType, Class sourceType) throws Exception {
47 return destinationType == Class.class;
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 protected boolean isWrappingRuntimeExceptions() {
54 return true;
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 protected Class[] getSourceClassesImpl() throws Exception {
61 return new Class[] { Object.class, float.class, double.class,
62 byte.class, short.class, int.class, long.class, boolean.class, char.class };
63 }
64
65 /**
66 * {@inheritDoc}
67 */
68 protected Class[] getDestinationClassesImpl() throws Exception {
69 return DEST;
70 }
71
72 }