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