From e34a779a52a3815912b3fff0dae85a69beba5772 Mon Sep 17 00:00:00 2001 From: lexi Date: Thu, 25 Sep 2014 23:06:06 +0000 Subject: [PATCH] Fixed the creation order of things. --- .../bind/model/concrete/CMInfoFactory.java | 139 ++++++++++-------- 1 file changed, 79 insertions(+), 60 deletions(-) diff --git a/basics/trunk/runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMInfoFactory.java b/basics/trunk/runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMInfoFactory.java index 8fecc6d6..49521b5d 100644 --- a/basics/trunk/runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMInfoFactory.java +++ b/basics/trunk/runtime/src/main/java/org/jvnet/jaxb2_commons/xml/bind/model/concrete/CMInfoFactory.java @@ -101,36 +101,75 @@ public CMInfoFactory(TIS typeInfoSet) { } - @SuppressWarnings("unchecked") public MModelInfo createModel() { final CMModel model = new CMModel( createModelInfoOrigin(typeInfoSet)); + createBuiltinLeafInfos(model); + createEnumLeafInfos(model); + createClassInfos(model); + createElementInfos(model); + return model; + + } + + private void createElementInfos(final CMModel model) { + Iterable> elements = typeInfoSet + .getAllElements(); + for (ElementInfo element : elements) { + final EI ei = (EI) element; + elementInfos.put(ei, createElementInfo(ei)); + } + for (ElementInfo element : elements) { + model.addElementInfo(getElementInfo((EI) element)); + } + } + + private void createEnumLeafInfos(final CMModel model) { + Collection> enums = typeInfoSet.enums() + .values(); + for (EnumLeafInfo enumLeafInfo : enums) { + @SuppressWarnings("unchecked") + final ELI eli = (ELI) enumLeafInfo; + enumLeafInfos.put(eli, createEnumLeafInfo(eli)); + } + for (Map.Entry> entry : enumLeafInfos + .entrySet()) { + populateEnumLeafInfo(entry.getKey(), entry.getValue()); + } + for (EnumLeafInfo enumLeafInfo : enums) { + model.addEnumLeafInfo(getTypeInfo((ELI) enumLeafInfo)); + } + } + + private void createBuiltinLeafInfos(final CMModel model) { Collection> builtins = typeInfoSet .builtins().values(); + for (BuiltinLeafInfo builtinLeafInfo : builtins) { + @SuppressWarnings("unchecked") + final BLI bli = (BLI) builtinLeafInfo; + builtinLeafInfos.put(bli, createBuiltinLeafInfo(bli)); + } for (BuiltinLeafInfo builtinLeafInfo : builtins) { model.addBuiltinLeafInfo(getTypeInfo((BLI) builtinLeafInfo)); } + } + private void createClassInfos(final CMModel model) { Collection> beans = typeInfoSet.beans() .values(); + for (ClassInfo classInfo : beans) { - model.addClassInfo(getTypeInfo((CI) classInfo)); + @SuppressWarnings("unchecked") + final CI ci = (CI) classInfo; + classInfos.put(ci, createClassInfo(ci)); } - - Collection> enums = typeInfoSet.enums() - .values(); - for (EnumLeafInfo enumLeafInfo : enums) { - model.addEnumLeafInfo(getTypeInfo((ELI) enumLeafInfo)); + for (Map.Entry> entry : classInfos.entrySet()) { + populateClassInfo(entry.getKey(), entry.getValue()); } - - Iterable> elements = typeInfoSet - .getAllElements(); - for (ElementInfo element : elements) { - model.addElementInfo(getElementInfo((EI) element)); + for (ClassInfo classInfo : beans) { + model.addClassInfo(getTypeInfo((CI) classInfo)); } - return model; - } protected MTypeInfo getTypeInfo(PropertyInfo propertyInfo, @@ -182,13 +221,7 @@ protected MTypeInfo getTypeInfo(TI typeInfo) { } private MBuiltinLeafInfo getTypeInfo(BLI typeInfo) { - MBuiltinLeafInfo builtinLeafInfo = builtinLeafInfos.get(typeInfo); - if (builtinLeafInfo == null) { - builtinLeafInfo = createBuiltinLeafInfo(typeInfo); - builtinLeafInfos.put(typeInfo, builtinLeafInfo); - return builtinLeafInfo; - } - return builtinLeafInfo; + return builtinLeafInfos.get(typeInfo); } private MTypeInfo getTypeInfo(EI info) { @@ -201,53 +234,27 @@ private MTypeInfo getTypeInfo(EI info) { } protected MClassInfo getTypeInfo(CI info) { - - MClassInfo classInfo = classInfos.get(info); - - if (classInfo == null) { - - classInfo = createClassInfo(info); - classInfos.put(info, classInfo); - - if (info.hasAttributeWildcard()) { - classInfo - .addProperty(createAnyAttributePropertyInfo(classInfo)); - } - - for (PropertyInfo p : (List>) info - .getProperties()) { - classInfo.addProperty(createPropertyInfo(classInfo, (PI) p)); - } - } - return classInfo; + return classInfos.get(info); } private MEnumLeafInfo getTypeInfo(ELI info) { - MEnumLeafInfo enumLeafInfo = enumLeafInfos.get(info); - if (enumLeafInfo == null) { - enumLeafInfo = createEnumLeafInfo(info); - enumLeafInfos.put(info, enumLeafInfo); + return enumLeafInfos.get(info); - @SuppressWarnings("rawtypes") - Iterable _constants = info.getConstants(); - @SuppressWarnings("unchecked") - final Iterable> enumConstants = (Iterable>) _constants; - for (EnumConstant enumConstant : enumConstants) { - enumLeafInfo.addEnumConstantInfo(createEnumContantInfo( - enumLeafInfo, (EC) enumConstant)); - } - } - return enumLeafInfo; + } + private void populateEnumLeafInfo(ELI info, MEnumLeafInfo enumLeafInfo) { + @SuppressWarnings("rawtypes") + Iterable _constants = info.getConstants(); + @SuppressWarnings("unchecked") + final Iterable> enumConstants = (Iterable>) _constants; + for (EnumConstant enumConstant : enumConstants) { + enumLeafInfo.addEnumConstantInfo(createEnumContantInfo( + enumLeafInfo, (EC) enumConstant)); + } } protected MElementInfo getElementInfo(EI info) { - MElementInfo mElementInfo = elementInfos.get(info); - if (mElementInfo == null) { - mElementInfo = createElementInfo(info); - elementInfos.put(info, mElementInfo); - } - return mElementInfo; + return elementInfos.get(info); } @@ -258,6 +265,18 @@ protected MClassInfo createClassInfo(CI info) { info.isElement() ? info.getElementName() : null); } + private void populateClassInfo(CI info, MClassInfo classInfo) { + + if (info.hasAttributeWildcard()) { + classInfo.addProperty(createAnyAttributePropertyInfo(classInfo)); + } + + for (PropertyInfo p : (List>) info + .getProperties()) { + classInfo.addProperty(createPropertyInfo(classInfo, (PI) p)); + } + } + protected MClassTypeInfo createBaseTypeInfo(CI info) { return info.getBaseClass() == null ? null : getTypeInfo((CI) info .getBaseClass());