1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.morph.transform.copiers;
17
18 import java.util.Locale;
19
20 import net.sf.morph.transform.Copier;
21 import net.sf.morph.transform.DecoratedConverter;
22 import net.sf.morph.transform.DecoratedCopier;
23 import net.sf.morph.transform.Transformer;
24 import net.sf.morph.transform.transformers.BaseCompositeTransformer;
25 import net.sf.morph.util.TransformerUtils;
26
27 /**
28 * Composite Transformer whose children must be Copiers and which invokes
29 * each child Copier in turn in the course of performing a copy operation.
30 *
31 * @author Matt Benson
32 * @since Morph 1.1
33 */
34 public class CumulativeCopier extends BaseCompositeTransformer implements
35 DecoratedCopier, DecoratedConverter {
36
37 /**
38 * Create a new CumulativeCopier.
39 */
40 public CumulativeCopier() {
41 super();
42 }
43
44 /**
45 * Create a new CumulativeCopier.
46 * @param components
47 */
48 public CumulativeCopier(Transformer[] components) {
49 this();
50 setComponents(components);
51 }
52
53 /**
54 * {@inheritDoc}
55 * @see net.sf.morph.transform.transformers.BaseTransformer#setSourceClasses(java.lang.Class[])
56 */
57 public synchronized void setSourceClasses(Class[] sourceClasses) {
58 super.setSourceClasses(sourceClasses);
59 }
60
61 /**
62 * Returns the source classes supported by <em>all</em> components.
63 *
64 * @return Class[]
65 */
66 protected Class[] getSourceClassesImpl() throws Exception {
67 return TransformerUtils
68 .getSourceClassIntersection((Transformer[]) getComponents());
69 }
70
71 /**
72 * {@inheritDoc}
73 * @see net.sf.morph.transform.transformers.BaseTransformer#setDestinationClasses(java.lang.Class[])
74 */
75 public synchronized void setDestinationClasses(Class[] destinationClasses) {
76 super.setDestinationClasses(destinationClasses);
77 }
78
79 /**
80 * Returns the destination classes supported by <em>all</em> components.
81 *
82 * @return Class[]
83 */
84 protected synchronized Class[] getDestinationClassesImpl() throws Exception {
85 return TransformerUtils
86 .getDestinationClassIntersection((Transformer[]) getComponents());
87 }
88
89 /**
90 * {@inheritDoc}
91 */
92 public Class getComponentType() {
93 return Copier.class;
94 }
95
96 /**
97 * {@inheritDoc}
98 * @see net.sf.morph.transform.transformers.BaseTransformer#copyImpl(java.lang.Object, java.lang.Object, java.util.Locale, java.lang.Integer)
99 */
100 protected void copyImpl(Object destination, Object source, Locale locale,
101 Integer preferredTransformationType) throws Exception {
102 Object[] copiers = getComponents();
103 for (int i = 0; i < copiers.length; i++) {
104 ((Copier) copiers[i]).copy(destination, source, locale);
105 }
106 }
107
108 /**
109 * {@inheritDoc}
110 * @see net.sf.morph.transform.transformers.BaseCompositeTransformer#isWrappingRuntimeExceptions()
111 */
112 protected boolean isWrappingRuntimeExceptions() {
113 return false;
114 }
115
116 }