1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.betwixt.schema;
19
20 import java.beans.IntrospectionException;
21 import java.util.Collection;
22 import java.util.Iterator;
23
24 import org.apache.commons.betwixt.ElementDescriptor;
25
26
27
28
29
30
31
32 public class GlobalComplexType extends ComplexType {
33
34 private String name;
35 private TranscriptionConfiguration configuration;
36
37 public GlobalComplexType() {}
38
39
40
41
42
43 public GlobalComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
44 super(configuration, elementDescriptor, schema);
45 }
46
47 protected void init(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
48 this.configuration = configuration;
49 setName(nameFromDescriptor( elementDescriptor ));
50 }
51
52
53
54
55
56
57
58
59
60 protected void fill(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException
61 {
62 elementDescriptor = fillDescriptor(elementDescriptor, schema);
63 super.init(configuration, elementDescriptor, schema);
64 }
65
66 private String nameFromDescriptor( ElementDescriptor elementDescriptor ) {
67 return configuration.getSchemaTypeNamingStrategy().nameSchemaType(elementDescriptor);
68 }
69
70
71
72
73
74
75
76 public boolean matches(ElementDescriptor elementDescriptor) {
77 String nameFromDescriptor = nameFromDescriptor ( elementDescriptor );
78 return nameFromDescriptor.equals(getName());
79 }
80
81
82
83
84
85 public String getName() {
86 return name;
87 }
88
89
90
91
92
93 public void setName(String string) {
94 name = string;
95 }
96
97 public boolean equals(Object obj) {
98 boolean result = false;
99 if (obj instanceof GlobalComplexType) {
100 GlobalComplexType complexType = (GlobalComplexType) obj;
101 result = isEqual(name, complexType.name) &&
102 equalContents(attributes, complexType.attributes) &&
103 equalContents(elements, complexType.elements);
104
105 }
106 return result;
107 }
108
109 public int hashCode() {
110 return 0;
111 }
112
113 private boolean equalContents(Collection one, Collection two)
114 {
115
116 if (one.size() != two.size()) {
117 return false;
118 }
119 for (Iterator it=one.iterator();it.hasNext();) {
120 Object object = it.next();
121 if (!two.contains(object)) {
122 return false;
123 }
124 }
125 return true;
126 }
127
128
129
130
131
132
133
134 private boolean isEqual(String one, String two) {
135 boolean result = false;
136 if (one == null) {
137 result = (two == null);
138 }
139 else
140 {
141 result = one.equals(two);
142 }
143
144 return result;
145 }
146
147 public String toString() {
148 StringBuffer buffer = new StringBuffer();
149 buffer.append("<xsd:complexType name='");
150 buffer.append(name);
151 buffer.append("'>");
152 buffer.append("<xsd:sequence>");
153 for (Iterator it=elements.iterator(); it.hasNext();) {
154 buffer.append(it.next());
155 }
156 buffer.append("</xsd:sequence>");
157
158 for (Iterator it=attributes.iterator(); it.hasNext();) {
159 buffer.append(it.next());
160 }
161 buffer.append("</xsd:complexType>");
162 return buffer.toString();
163 }
164 }