20 package net.sf.gridarta.model.archetypetype;
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.LinkedHashSet;
29 import nu.xom.Attribute;
30 import nu.xom.Element;
31 import nu.xom.Elements;
32 import org.apache.log4j.Category;
33 import org.apache.log4j.Logger;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
83 final String typeName =
parseTypeName(typeElement, isDefaultType);
84 if (
LOG.isDebugEnabled()) {
85 LOG.debug(
"loadAttributeList: " + typeName);
87 final int typeNo =
parseTypeNo(typeElement, isDefaultType, typeName, errorViewCollector);
89 final String display = typeElementAttribute ==
null ?
"" : typeElementAttribute.getValue();
90 final boolean map =
parseMap(typeElement);
91 final int[] inv =
parseInv(typeElement, typeName, errorViewCollector);
93 final Collection<String> ignoreTable =
new HashSet<>();
96 final Collection<String> importTypes =
new LinkedHashSet<>();
98 final String importType =
parseImportType(importTypeElement, typeName, errorViewCollector);
99 if (importType !=
null && !importTypes.add(importType)) {
107 final Iterable<ArchetypeAttributeSection> attributeList =
addAttributeList(typeElement, attributeSection, errorViewCollector, typeName, archetypeTypeSet);
108 if (
LOG.isDebugEnabled()) {
109 LOG.debug(
"loadAttributeList: adding default section " + attributeSection);
113 if (
LOG.isDebugEnabled()) {
114 LOG.debug(
"loadAttributeList: adding section " + archetypeAttributeSection);
118 if (parentArchetypeType !=
null) {
119 if (
LOG.isDebugEnabled()) {
120 LOG.debug(
"loadAttributeList: importing attributes from parent archetype type " + parentArchetypeType.getTypeName());
122 final Collection<String> autoIgnoreTable =
new HashSet<>();
125 if (
LOG.isDebugEnabled()) {
126 LOG.debug(
"loadAttributeList: auto-ignore: " + attribute.getArchetypeAttributeName() +
" [parent]");
128 autoIgnoreTable.add(attribute.getArchetypeAttributeName());
132 if (
LOG.isDebugEnabled()) {
133 LOG.debug(
"loadAttributeList: auto-ignore: " + attribute.getArchetypeAttributeName() +
" [this]");
135 autoIgnoreTable.add(attribute.getArchetypeAttributeName());
138 if (parentArchetypeType.hasAttribute()) {
139 for (
final String importType : importTypes) {
140 if (
LOG.isDebugEnabled()) {
141 LOG.debug(
"loadAttributeList: importing attributes from " + importType);
143 addImportList(importType, newArchetypeType, errorViewCollector, typeName, archetypeTypeSet, autoIgnoreTable);
147 if (
LOG.isDebugEnabled()) {
148 LOG.debug(
"loadAttributeList: importing default attributes from " + parentArchetypeType.getTypeName());
150 addDefaultList(parentArchetypeType, newArchetypeType, autoIgnoreTable, ignoreTable);
153 return newArchetypeType;
164 private static void addDefaultList(@NotNull
final Iterable<ArchetypeAttributeSection> archetypeType, @NotNull
final ArchetypeType newArchetypeType, @NotNull
final Collection<String> autoIgnoreTable, @NotNull
final Collection<String> ignoreTable) {
168 final String archetypeAttributeName = archetypeAttribute.getArchetypeAttributeName();
169 if (ignoreTable.contains(archetypeAttributeName)) {
170 if (
LOG.isDebugEnabled()) {
171 LOG.debug(
"addDefaultList: skipping " + archetypeAttributeName +
" because of ignoreTable");
175 if (autoIgnoreTable.contains(archetypeAttributeName)) {
176 if (
LOG.isDebugEnabled()) {
177 LOG.debug(
"addDefaultList: skipping " + archetypeAttributeName +
" because of autoIgnoreTable");
181 if (
LOG.isDebugEnabled()) {
182 LOG.debug(
"addDefaultList: adding " + archetypeAttributeName +
" to section " + archetypeAttributeSection);
184 newArchetypeType.addArchetypeAttribute(archetypeAttributeSection.getSectionName(), archetypeAttribute);
200 final ArchetypeType importType = archetypeTypeSet.getArchetypeType(importName);
201 if (importType ==
null) {
202 if (
LOG.isDebugEnabled()) {
203 LOG.debug(
"addImportList: skipping " + importName +
" because it does not exist");
210 final String sectionName = archetypeAttributeSection.getSectionName();
212 if (
LOG.isDebugEnabled()) {
213 LOG.debug(
"addImportList: skipping section " + sectionName +
" because it is the general section");
219 final String attributeName = archetypeAttribute.getArchetypeAttributeName();
220 if (autoIgnoreTable.contains(attributeName)) {
221 if (
LOG.isDebugEnabled()) {
222 LOG.debug(
"addImportList: skipping " + attributeName +
" because of autoIgnoreTable");
227 if (
LOG.isDebugEnabled()) {
228 LOG.debug(
"addImportList: adding " + archetypeAttribute +
" to section " + sectionName);
230 newArchetypeType.addArchetypeAttribute(sectionName, archetypeAttribute);
231 if (
LOG.isDebugEnabled()) {
232 LOG.debug(
"addImportList: auto-ignore: " + attributeName +
" [import]");
234 autoIgnoreTable.add(attributeName);
252 if (nameAttribute ==
null) {
257 final String name = nameAttribute.getValue();
258 if (name.isEmpty()) {
274 private static String
parseTypeName(@NotNull
final Element typeElement,
final boolean isDefaultType) {
286 private static int parseTypeNo(@NotNull
final Element typeElement,
final boolean isDefaultType, @NotNull
final String typeName, @NotNull
final ErrorViewCollector errorViewCollector) {
293 return Integer.parseInt(number);
294 }
catch (
final NumberFormatException ignored) {
305 private static boolean parseMap(@NotNull
final Element typeElement) {
307 return attribute !=
null && attribute.getValue().equals(
"yes");
318 private static int @Nullable []
parseInv(@NotNull
final Element typeElement, @NotNull
final String typeName, @NotNull
final ErrorViewCollector errorViewCollector) {
320 if (attribute ==
null) {
324 final String inv = attribute.getValue();
328 if (inv.equals(
"*")) {
333 final int[] result =
new int[types.length];
334 for (
int i = 0; i < types.length; i++) {
336 result[i] = Integer.parseInt(types[i]);
337 }
catch (
final NumberFormatException ignored) {
352 return attribute !=
null && attribute.getValue().equals(
"yes");
370 if (ignoreElements.size() > 0) {
371 final Element ignoreElement = ignoreElements.get(0);
376 return typeAttributes;
390 if (requiredElements.size() > 0) {
393 if (archAttribute ==
null) {
397 final String attributeValue = archAttribute.getValue();
398 if (attributeValue.isEmpty()) {
404 if (valueAttribute ==
null) {
408 final String value = valueAttribute.getValue();
409 if (value.isEmpty()) {
430 if (archAttribute ==
null) {
435 final String attributeValue = archAttribute.getValue();
436 if (attributeValue.isEmpty()) {
441 ignoreTable.add(attributeValue);
456 if (nameAttribute ==
null) {
461 final String name = nameAttribute.getValue();
462 final Iterable<String> ignoreList = ignorelistsDefinition.get(name);
463 if (ignoreList ==
null) {
468 for (
final String ignoreItem : ignoreList) {
469 ignoreTable.add(ignoreItem);
482 return elements.size() == 0 ? null : elements.get(0).getValue().trim();
491 private static String
parseUse(@NotNull
final Element root) {
493 return elements.size() == 0 ? null : elements.get(0).getValue().trim();
511 for (
final Element childElement :
new ElementsIterable(typeElement.getChildElements())) {
512 final String childName = childElement.getLocalName();
515 parseAttribute(childElement, errorViewCollector, typeName, archetypeTypeSet, sections, defaultAttributeSection.getSectionName());
518 if (nameAttribute ==
null) {
523 final String sectionName = nameAttribute.getValue();
524 if (sectionName.isEmpty()) {
530 parseAttribute(element, errorViewCollector, typeName, archetypeTypeSet, sections, sectionName);
549 if (archetypeAttribute ==
null) {
554 sections.addArchetypeAttribute(effectiveSectionName, archetypeAttribute);