1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package goldengate.common.xml;
22
23
24
25
26
27
28
29
30 public class XmlDecl {
31 private final String name;
32
33 private final XmlType type;
34
35 private final String xmlPath;
36
37 private final XmlDecl[] subXml;
38
39 private final boolean isMultiple;
40
41 public XmlDecl(String name, String xmlPath) {
42 this.name = name;
43 this.type = XmlType.EMPTY;
44 this.xmlPath = xmlPath;
45 this.isMultiple = false;
46 this.subXml = null;
47 }
48
49 public XmlDecl(XmlType type, String xmlPath) {
50 this.name = xmlPath;
51 this.type = type;
52 this.xmlPath = xmlPath;
53 this.isMultiple = false;
54 this.subXml = null;
55 }
56
57 public XmlDecl(String name, XmlType type, String xmlPath) {
58 this.name = name;
59 this.type = type;
60 this.xmlPath = xmlPath;
61 this.isMultiple = false;
62 this.subXml = null;
63 }
64
65 public XmlDecl(String name, XmlType type, String xmlPath, boolean isMultiple) {
66 this.name = name;
67 this.type = type;
68 this.xmlPath = xmlPath;
69 this.isMultiple = isMultiple;
70 this.subXml = null;
71 }
72
73 public XmlDecl(String name, XmlType type, String xmlPath, XmlDecl[] decls,
74 boolean isMultiple) {
75 this.name = name;
76 this.type = type;
77 this.xmlPath = xmlPath;
78 this.isMultiple = isMultiple;
79 this.subXml = decls;
80 }
81
82
83
84
85
86
87 public String getName() {
88 return name;
89 }
90
91
92
93
94 public Class<?> getClassType() {
95 return type.getClassType();
96 }
97
98
99
100
101 public XmlType getType() {
102 return type;
103 }
104
105
106
107
108 public String getXmlPath() {
109 return xmlPath;
110 }
111
112
113
114
115
116 public boolean isSubXml() {
117 return this.subXml != null;
118 }
119
120
121
122
123 public XmlDecl[] getSubXml() {
124 return subXml;
125 }
126
127
128
129
130 public int getSubXmlSize() {
131 if (subXml == null) return 0;
132 return subXml.length;
133 }
134
135
136
137
138 public boolean isMultiple() {
139 return isMultiple;
140 }
141
142
143
144
145
146
147
148 public boolean isCompatible(XmlDecl xmlDecl) {
149 if (((isMultiple && xmlDecl.isMultiple) || ((!isMultiple) && (!xmlDecl.isMultiple))) &&
150 ((isSubXml() && xmlDecl.isSubXml()) ||
151 ((!isSubXml()) && (!xmlDecl.isSubXml())))) {
152 if (!isSubXml()) {
153 return type == xmlDecl.type;
154 }
155 if (subXml.length != xmlDecl.subXml.length) {
156 return false;
157 }
158 for (int i = 0; i < subXml.length; i ++) {
159 if (!subXml[i].isCompatible(xmlDecl.subXml[i])) {
160 return false;
161 }
162 }
163 return true;
164 }
165 return false;
166 }
167
168 public String toString() {
169 return "Decl: " + name + " Type: " + type.name() + " XmlPath: " +
170 xmlPath + " isMultiple: " + isMultiple + " isSubXml: " +
171 isSubXml();
172 }
173 }