Skip to content

Commit e34a779

Browse files
author
lexi
committed
Fixed the creation order of things.
1 parent 105ff10 commit e34a779

File tree

1 file changed

+79
-60
lines changed
  • basics/trunk/runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete

1 file changed

+79
-60
lines changed

basics/trunk/runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMInfoFactory.java

Lines changed: 79 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -101,36 +101,75 @@ public CMInfoFactory(TIS typeInfoSet) {
101101

102102
}
103103

104-
@SuppressWarnings("unchecked")
105104
public MModelInfo<T, C> createModel() {
106105
final CMModel<T, C> model = new CMModel<T, C>(
107106
createModelInfoOrigin(typeInfoSet));
108107

108+
createBuiltinLeafInfos(model);
109+
createEnumLeafInfos(model);
110+
createClassInfos(model);
111+
createElementInfos(model);
112+
return model;
113+
114+
}
115+
116+
private void createElementInfos(final CMModel<T, C> model) {
117+
Iterable<? extends ElementInfo<T, C>> elements = typeInfoSet
118+
.getAllElements();
119+
for (ElementInfo<T, C> element : elements) {
120+
final EI ei = (EI) element;
121+
elementInfos.put(ei, createElementInfo(ei));
122+
}
123+
for (ElementInfo<T, C> element : elements) {
124+
model.addElementInfo(getElementInfo((EI) element));
125+
}
126+
}
127+
128+
private void createEnumLeafInfos(final CMModel<T, C> model) {
129+
Collection<? extends EnumLeafInfo<T, C>> enums = typeInfoSet.enums()
130+
.values();
131+
for (EnumLeafInfo<T, C> enumLeafInfo : enums) {
132+
@SuppressWarnings("unchecked")
133+
final ELI eli = (ELI) enumLeafInfo;
134+
enumLeafInfos.put(eli, createEnumLeafInfo(eli));
135+
}
136+
for (Map.Entry<ELI, MEnumLeafInfo<T, C>> entry : enumLeafInfos
137+
.entrySet()) {
138+
populateEnumLeafInfo(entry.getKey(), entry.getValue());
139+
}
140+
for (EnumLeafInfo<T, C> enumLeafInfo : enums) {
141+
model.addEnumLeafInfo(getTypeInfo((ELI) enumLeafInfo));
142+
}
143+
}
144+
145+
private void createBuiltinLeafInfos(final CMModel<T, C> model) {
109146
Collection<? extends BuiltinLeafInfo<T, C>> builtins = typeInfoSet
110147
.builtins().values();
148+
for (BuiltinLeafInfo<T, C> builtinLeafInfo : builtins) {
149+
@SuppressWarnings("unchecked")
150+
final BLI bli = (BLI) builtinLeafInfo;
151+
builtinLeafInfos.put(bli, createBuiltinLeafInfo(bli));
152+
}
111153
for (BuiltinLeafInfo<T, C> builtinLeafInfo : builtins) {
112154
model.addBuiltinLeafInfo(getTypeInfo((BLI) builtinLeafInfo));
113155
}
156+
}
114157

158+
private void createClassInfos(final CMModel<T, C> model) {
115159
Collection<? extends ClassInfo<T, C>> beans = typeInfoSet.beans()
116160
.values();
161+
117162
for (ClassInfo<T, C> classInfo : beans) {
118-
model.addClassInfo(getTypeInfo((CI) classInfo));
163+
@SuppressWarnings("unchecked")
164+
final CI ci = (CI) classInfo;
165+
classInfos.put(ci, createClassInfo(ci));
119166
}
120-
121-
Collection<? extends EnumLeafInfo<T, C>> enums = typeInfoSet.enums()
122-
.values();
123-
for (EnumLeafInfo<T, C> enumLeafInfo : enums) {
124-
model.addEnumLeafInfo(getTypeInfo((ELI) enumLeafInfo));
167+
for (Map.Entry<CI, MClassInfo<T, C>> entry : classInfos.entrySet()) {
168+
populateClassInfo(entry.getKey(), entry.getValue());
125169
}
126-
127-
Iterable<? extends ElementInfo<T, C>> elements = typeInfoSet
128-
.getAllElements();
129-
for (ElementInfo<T, C> element : elements) {
130-
model.addElementInfo(getElementInfo((EI) element));
170+
for (ClassInfo<T, C> classInfo : beans) {
171+
model.addClassInfo(getTypeInfo((CI) classInfo));
131172
}
132-
return model;
133-
134173
}
135174

136175
protected MTypeInfo<T, C> getTypeInfo(PropertyInfo<T, C> propertyInfo,
@@ -182,13 +221,7 @@ protected MTypeInfo<T, C> getTypeInfo(TI typeInfo) {
182221
}
183222

184223
private MBuiltinLeafInfo<T, C> getTypeInfo(BLI typeInfo) {
185-
MBuiltinLeafInfo<T, C> builtinLeafInfo = builtinLeafInfos.get(typeInfo);
186-
if (builtinLeafInfo == null) {
187-
builtinLeafInfo = createBuiltinLeafInfo(typeInfo);
188-
builtinLeafInfos.put(typeInfo, builtinLeafInfo);
189-
return builtinLeafInfo;
190-
}
191-
return builtinLeafInfo;
224+
return builtinLeafInfos.get(typeInfo);
192225
}
193226

194227
private MTypeInfo<T, C> getTypeInfo(EI info) {
@@ -201,53 +234,27 @@ private MTypeInfo<T, C> getTypeInfo(EI info) {
201234
}
202235

203236
protected MClassInfo<T, C> getTypeInfo(CI info) {
204-
205-
MClassInfo<T, C> classInfo = classInfos.get(info);
206-
207-
if (classInfo == null) {
208-
209-
classInfo = createClassInfo(info);
210-
classInfos.put(info, classInfo);
211-
212-
if (info.hasAttributeWildcard()) {
213-
classInfo
214-
.addProperty(createAnyAttributePropertyInfo(classInfo));
215-
}
216-
217-
for (PropertyInfo<T, C> p : (List<? extends PropertyInfo<T, C>>) info
218-
.getProperties()) {
219-
classInfo.addProperty(createPropertyInfo(classInfo, (PI) p));
220-
}
221-
}
222-
return classInfo;
237+
return classInfos.get(info);
223238
}
224239

225240
private MEnumLeafInfo<T, C> getTypeInfo(ELI info) {
226-
MEnumLeafInfo<T, C> enumLeafInfo = enumLeafInfos.get(info);
227-
if (enumLeafInfo == null) {
228-
enumLeafInfo = createEnumLeafInfo(info);
229-
enumLeafInfos.put(info, enumLeafInfo);
241+
return enumLeafInfos.get(info);
230242

231-
@SuppressWarnings("rawtypes")
232-
Iterable<? extends EnumConstant> _constants = info.getConstants();
233-
@SuppressWarnings("unchecked")
234-
final Iterable<? extends EnumConstant<T, C>> enumConstants = (Iterable<? extends EnumConstant<T, C>>) _constants;
235-
for (EnumConstant<?, ?> enumConstant : enumConstants) {
236-
enumLeafInfo.addEnumConstantInfo(createEnumContantInfo(
237-
enumLeafInfo, (EC) enumConstant));
238-
}
239-
}
240-
return enumLeafInfo;
243+
}
241244

245+
private void populateEnumLeafInfo(ELI info, MEnumLeafInfo<T, C> enumLeafInfo) {
246+
@SuppressWarnings("rawtypes")
247+
Iterable<? extends EnumConstant> _constants = info.getConstants();
248+
@SuppressWarnings("unchecked")
249+
final Iterable<? extends EnumConstant<T, C>> enumConstants = (Iterable<? extends EnumConstant<T, C>>) _constants;
250+
for (EnumConstant<?, ?> enumConstant : enumConstants) {
251+
enumLeafInfo.addEnumConstantInfo(createEnumContantInfo(
252+
enumLeafInfo, (EC) enumConstant));
253+
}
242254
}
243255

244256
protected MElementInfo<T, C> getElementInfo(EI info) {
245-
MElementInfo<T, C> mElementInfo = elementInfos.get(info);
246-
if (mElementInfo == null) {
247-
mElementInfo = createElementInfo(info);
248-
elementInfos.put(info, mElementInfo);
249-
}
250-
return mElementInfo;
257+
return elementInfos.get(info);
251258

252259
}
253260

@@ -258,6 +265,18 @@ protected MClassInfo<T, C> createClassInfo(CI info) {
258265
info.isElement() ? info.getElementName() : null);
259266
}
260267

268+
private void populateClassInfo(CI info, MClassInfo<T, C> classInfo) {
269+
270+
if (info.hasAttributeWildcard()) {
271+
classInfo.addProperty(createAnyAttributePropertyInfo(classInfo));
272+
}
273+
274+
for (PropertyInfo<T, C> p : (List<? extends PropertyInfo<T, C>>) info
275+
.getProperties()) {
276+
classInfo.addProperty(createPropertyInfo(classInfo, (PI) p));
277+
}
278+
}
279+
261280
protected MClassTypeInfo<T, C> createBaseTypeInfo(CI info) {
262281
return info.getBaseClass() == null ? null : getTypeInfo((CI) info
263282
.getBaseClass());

0 commit comments

Comments
 (0)