1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.betwixt.strategy;
19
20 import org.apache.commons.betwixt.ElementDescriptor;
21 import org.apache.commons.betwixt.io.read.ArrayBindAction;
22 import org.apache.commons.betwixt.io.read.BeanBindAction;
23 import org.apache.commons.betwixt.io.read.MappingAction;
24 import org.apache.commons.betwixt.io.read.ReadContext;
25 import org.apache.commons.betwixt.io.read.SimpleTypeBindAction;
26 import org.xml.sax.Attributes;
27
28
29
30
31
32 public class DefaultActionMappingStrategy extends ActionMappingStrategy {
33
34
35
36
37
38
39
40
41
42
43 public MappingAction getMappingAction(
44 String namespace,
45 String name,
46 Attributes attributes,
47 ReadContext context)
48 throws Exception {
49 MappingAction result = MappingAction.EMPTY;
50
51 ElementDescriptor activeDescriptor = context.getCurrentDescriptor();
52 if (activeDescriptor != null) {
53 if (activeDescriptor.isHollow()) {
54 if (isArrayDescriptor(activeDescriptor)) {
55 result = ArrayBindAction.createMappingAction(activeDescriptor);
56 } else {
57 result = BeanBindAction.INSTANCE;
58 }
59 }
60 else if (activeDescriptor.isSimple())
61 {
62 result = SimpleTypeBindAction.INSTANCE;
63 }
64 else
65 {
66 ElementDescriptor[] descriptors
67 = activeDescriptor.getElementDescriptors();
68 if (descriptors.length == 1) {
69 ElementDescriptor childDescriptor = descriptors[0];
70 if (childDescriptor.isHollow()
71 && isArrayDescriptor(childDescriptor)) {
72 result = ArrayBindAction.createMappingAction(childDescriptor);
73 }
74 }
75 }
76 }
77 return result;
78 }
79
80
81
82
83
84
85 private boolean isArrayDescriptor(ElementDescriptor descriptor) {
86 boolean result = false;
87 if (descriptor != null) {
88 Class propertyType = descriptor.getPropertyType();
89 if (propertyType != null) {
90 result = propertyType.isArray();
91 }
92 }
93 return result;
94 }
95 }