1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.commons.betwixt.schema; |
18 |
|
|
19 |
|
import java.beans.IntrospectionException; |
20 |
|
import java.util.ArrayList; |
21 |
|
import java.util.List; |
22 |
|
|
23 |
|
import org.apache.commons.betwixt.AttributeDescriptor; |
24 |
|
import org.apache.commons.betwixt.ElementDescriptor; |
25 |
|
import org.apache.commons.betwixt.XMLBeanInfo; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
public abstract class ComplexType { |
36 |
|
|
37 |
663 |
protected List elements = new ArrayList(); |
38 |
|
|
39 |
663 |
protected List attributes = new ArrayList(); |
40 |
|
|
41 |
130 |
public ComplexType() { |
42 |
130 |
} |
43 |
|
|
44 |
533 |
public ComplexType(TranscriptionConfiguration configuration, |
45 |
|
ElementDescriptor elementDescriptor, Schema schema) |
46 |
|
throws IntrospectionException { |
47 |
533 |
elementDescriptor = fillDescriptor(elementDescriptor, schema); |
48 |
533 |
init(configuration, elementDescriptor, schema); |
49 |
533 |
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
protected ElementDescriptor fillDescriptor( |
60 |
|
ElementDescriptor elementDescriptor, Schema schema) |
61 |
|
throws IntrospectionException { |
62 |
1001 |
if (elementDescriptor.isHollow()) { |
63 |
|
|
64 |
442 |
Class type = elementDescriptor.getSingularPropertyType(); |
65 |
442 |
if (type == null) { |
66 |
0 |
type = elementDescriptor.getPropertyType(); |
67 |
|
} |
68 |
442 |
if (type == null) { |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
} else { |
74 |
442 |
XMLBeanInfo filledBeanInfo = schema.introspect(type); |
75 |
442 |
elementDescriptor = filledBeanInfo.getElementDescriptor(); |
76 |
|
} |
77 |
|
} |
78 |
1001 |
return elementDescriptor; |
79 |
|
} |
80 |
|
|
81 |
|
protected void init(TranscriptionConfiguration configuration, |
82 |
|
ElementDescriptor elementDescriptor, Schema schema) |
83 |
|
throws IntrospectionException { |
84 |
|
|
85 |
1066 |
AttributeDescriptor[] attributeDescriptors = elementDescriptor |
86 |
533 |
.getAttributeDescriptors(); |
87 |
1456 |
for (int i = 0, length = attributeDescriptors.length; i < length; i++) { |
88 |
|
|
89 |
|
|
90 |
923 |
String uri = attributeDescriptors[i].getURI(); |
91 |
923 |
if (!SchemaTranscriber.W3C_SCHEMA_INSTANCE_URI.equals(uri)) { |
92 |
845 |
attributes.add(new Attribute(attributeDescriptors[i])); |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
1066 |
ElementDescriptor[] elementDescriptors = elementDescriptor |
98 |
533 |
.getElementDescriptors(); |
99 |
1560 |
for (int i = 0, length = elementDescriptors.length; i < length; i++) { |
100 |
1027 |
if (elementDescriptors[i].isHollow()) { |
101 |
494 |
elements.add(new ElementReference(configuration, |
102 |
247 |
elementDescriptors[i], schema)); |
103 |
780 |
} else if (elementDescriptors[i].isSimple()) { |
104 |
1430 |
elements.add(new SimpleLocalElement(configuration, |
105 |
715 |
elementDescriptors[i], schema)); |
106 |
|
} else { |
107 |
130 |
elements.add(new ComplexLocalElement(configuration, |
108 |
65 |
elementDescriptors[i], schema)); |
109 |
|
} |
110 |
|
} |
111 |
533 |
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
public List getElements() { |
119 |
403 |
return elements; |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
public void addElement(ElementReference element) { |
128 |
52 |
elements.add(element); |
129 |
52 |
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
public void addElement(LocalElement element) { |
137 |
299 |
elements.add(element); |
138 |
299 |
} |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
public List getAttributes() { |
146 |
403 |
return attributes; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
public void addAttribute(Attribute attribute) { |
155 |
260 |
attributes.add(attribute); |
156 |
260 |
} |
157 |
|
|
158 |
|
} |