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