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 * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
29 * @version $Revision: 1.2 $
30 */
31 public abstract class ComplexType {
32
33 protected List elements = new ArrayList();
34
35 protected List attributes = new ArrayList();
36
37 public ComplexType() {}
38
39 public ComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
40 if (elementDescriptor.isHollow()) {
41
42 Class type = elementDescriptor.getSingularPropertyType();
43 if (type == null) {
44 type = elementDescriptor.getPropertyType();
45 }
46 XMLBeanInfo filledBeanInfo = schema.introspect(type);
47 elementDescriptor = filledBeanInfo.getElementDescriptor();
48 }
49 init(configuration, elementDescriptor, schema);
50 }
51
52 protected void init(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
53
54 AttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributeDescriptors();
55 for (int i=0,length=attributeDescriptors.length; i<length ; i++) {
56
57
58 String uri = attributeDescriptors[i].getURI();
59 if (! SchemaTranscriber.W3C_SCHEMA_INSTANCE_URI.equals(uri)) {
60 attributes.add(new Attribute(attributeDescriptors[i]));
61 }
62 }
63
64
65 ElementDescriptor[] elementDescriptors = elementDescriptor.getElementDescriptors();
66 for (int i=0,length=elementDescriptors.length; i<length ; i++) {
67 if (elementDescriptors[i].isHollow()) {
68 elements.add(new ElementReference(configuration, elementDescriptors[i], schema));
69 } else if (elementDescriptors[i].isSimple()){
70 elements.add(new SimpleLocalElement(configuration, elementDescriptors[i], schema));
71 } else {
72 elements.add(new ComplexLocalElement(configuration, elementDescriptors[i], schema));
73 }
74 }
75 }
76
77 /***
78 * Gets the elements contained by this type
79 * @return
80 */
81 public List getElements() {
82 return elements;
83 }
84
85 /***
86 * Adds an element to those contained by this type
87 * @param element
88 */
89 public void addElement(ElementReference element) {
90 elements.add(element);
91 }
92
93 /***
94 * Adds an element to those contained by this type
95 * @param element
96 */
97 public void addElement(LocalElement element) {
98 elements.add(element);
99 }
100
101
102 /***
103 * Gets the attributes contained by this type.
104 * @return
105 */
106 public List getAttributes() {
107 return attributes;
108 }
109
110 /***
111 * Adds an attribute to those contained by this type
112 * @param attribute
113 */
114 public void addAttribute(Attribute attribute) {
115 attributes.add(attribute);
116 }
117
118 }