1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.flatfile.morph; |
18 | |
|
19 | |
import java.util.Locale; |
20 | |
|
21 | |
import org.apache.commons.flatfile.Entity; |
22 | |
|
23 | |
import net.sf.morph.Defaults; |
24 | |
import net.sf.morph.transform.DecoratedCopier; |
25 | |
import net.sf.morph.transform.converters.TextConverter; |
26 | |
import net.sf.morph.transform.transformers.BaseTransformer; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class TextToEntityCopier extends BaseTransformer implements |
33 | |
DecoratedCopier { |
34 | |
private TextConverter textConverter; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
@Override |
40 | |
protected void copyImpl(Object destination, Object source, Locale locale, |
41 | |
Integer preferredTransformationType) throws Exception { |
42 | 0 | byte[] b = |
43 | 0 | (byte[]) getTextConverter().convert(byte[].class, source, locale); |
44 | 0 | ((Entity) destination).setValue(b); |
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
@Override |
51 | |
public synchronized void setSourceClasses(@SuppressWarnings("rawtypes") Class[] sourceClasses) { |
52 | 0 | super.setSourceClasses(sourceClasses); |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
@Override |
59 | |
public synchronized void setDestinationClasses(@SuppressWarnings("rawtypes") Class[] destinationClasses) { |
60 | 0 | super.setDestinationClasses(destinationClasses); |
61 | 0 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
@Override |
67 | |
protected Class<?>[] getDestinationClassesImpl() throws Exception { |
68 | 0 | return new Class[] { Entity.class }; |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
@Override |
75 | |
protected Class<?>[] getSourceClassesImpl() throws Exception { |
76 | 0 | return getTextConverter().getSourceClasses(); |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public synchronized TextConverter getTextConverter() { |
84 | 0 | if (textConverter == null) { |
85 | 0 | setTextConverter(Defaults.createTextConverter()); |
86 | |
} |
87 | 0 | return textConverter; |
88 | |
} |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public synchronized void setTextConverter(TextConverter textConverter) { |
95 | 0 | this.textConverter = textConverter; |
96 | 0 | } |
97 | |
|
98 | |
} |