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;
84 final String typeName =
parseTypeName(typeElement, isDefaultType);
85 if (LOG.isDebugEnabled()) {
86 LOG.debug(
"loadAttributeList: " + typeName);
88 final int typeNo =
parseTypeNo(typeElement, isDefaultType, typeName, errorViewCollector);
90 final String display = typeElementAttribute == null ?
"" : typeElementAttribute.getValue();
91 final boolean map =
parseMap(typeElement);
92 final int[] inv =
parseInv(typeElement, typeName, errorViewCollector);
94 final Collection<String> ignoreTable =
new HashSet<>();
97 final Collection<String> importTypes =
new LinkedHashSet<>();
99 final String importType =
parseImportType(importTypeElement, typeName, errorViewCollector);
100 if (importType != null && !importTypes.add(importType)) {
108 final Iterable<ArchetypeAttributeSection> attributeList =
addAttributeList(typeElement, attributeSection, errorViewCollector, typeName, archetypeTypeSet);
109 if (LOG.isDebugEnabled()) {
110 LOG.debug(
"loadAttributeList: adding default section " + attributeSection);
114 if (LOG.isDebugEnabled()) {
115 LOG.debug(
"loadAttributeList: adding section " + archetypeAttributeSection);
119 if (parentArchetypeType != null) {
120 if (LOG.isDebugEnabled()) {
121 LOG.debug(
"loadAttributeList: importing attributes from parent archetype type " + parentArchetypeType.getTypeName());
123 final Collection<String> autoIgnoreTable =
new HashSet<>();
126 if (LOG.isDebugEnabled()) {
127 LOG.debug(
"loadAttributeList: auto-ignore: " + attribute.getArchetypeAttributeName() +
" [parent]");
129 autoIgnoreTable.add(attribute.getArchetypeAttributeName());
133 if (LOG.isDebugEnabled()) {
134 LOG.debug(
"loadAttributeList: auto-ignore: " + attribute.getArchetypeAttributeName() +
" [this]");
136 autoIgnoreTable.add(attribute.getArchetypeAttributeName());
139 if (parentArchetypeType.hasAttribute()) {
140 for (
final String importType : importTypes) {
141 if (LOG.isDebugEnabled()) {
142 LOG.debug(
"loadAttributeList: importing attributes from " + importType);
144 addImportList(importType, newArchetypeType, errorViewCollector, typeName, archetypeTypeSet, autoIgnoreTable);
148 if (LOG.isDebugEnabled()) {
149 LOG.debug(
"loadAttributeList: importing default attributes from " + parentArchetypeType.getTypeName());
151 addDefaultList(parentArchetypeType, newArchetypeType, autoIgnoreTable, ignoreTable);
154 return newArchetypeType;
165 private static void addDefaultList(@NotNull
final Iterable<ArchetypeAttributeSection> archetypeType, @NotNull
final ArchetypeType newArchetypeType, @NotNull
final Collection<String> autoIgnoreTable, @NotNull
final Collection<String> ignoreTable) {
169 final String archetypeAttributeName = archetypeAttribute.getArchetypeAttributeName();
170 if (ignoreTable.contains(archetypeAttributeName)) {
171 if (LOG.isDebugEnabled()) {
172 LOG.debug(
"addDefaultList: skipping " + archetypeAttributeName +
" because of ignoreTable");
176 if (autoIgnoreTable.contains(archetypeAttributeName)) {
177 if (LOG.isDebugEnabled()) {
178 LOG.debug(
"addDefaultList: skipping " + archetypeAttributeName +
" because of autoIgnoreTable");
182 if (LOG.isDebugEnabled()) {
183 LOG.debug(
"addDefaultList: adding " + archetypeAttributeName +
" to section " + archetypeAttributeSection);
185 newArchetypeType.addArchetypeAttribute(archetypeAttributeSection.getSectionName(), archetypeAttribute);
201 final ArchetypeType importType = archetypeTypeSet.getArchetypeType(importName);
202 if (importType == null) {
203 if (LOG.isDebugEnabled()) {
204 LOG.debug(
"addImportList: skipping " + importName +
" because it does not exist");
211 final String sectionName = archetypeAttributeSection.getSectionName();
213 if (LOG.isDebugEnabled()) {
214 LOG.debug(
"addImportList: skipping section " + sectionName +
" because it is the general section");
220 final String attributeName = archetypeAttribute.getArchetypeAttributeName();
221 if (autoIgnoreTable.contains(attributeName)) {
222 if (LOG.isDebugEnabled()) {
223 LOG.debug(
"addImportList: skipping " + attributeName +
" because of autoIgnoreTable");
228 if (LOG.isDebugEnabled()) {
229 LOG.debug(
"addImportList: adding " + archetypeAttribute +
" to section " + sectionName);
232 if (LOG.isDebugEnabled()) {
233 LOG.debug(
"addImportList: auto-ignore: " + attributeName +
" [import]");
235 autoIgnoreTable.add(attributeName);
253 if (nameAttribute == null) {
258 final String name = nameAttribute.getValue();
259 if (name.isEmpty()) {
275 private static String
parseTypeName(@NotNull
final Element typeElement,
final boolean isDefaultType) {
287 private static int parseTypeNo(@NotNull
final Element typeElement,
final boolean isDefaultType, @NotNull
final String typeName, @NotNull
final ErrorViewCollector errorViewCollector) {
294 return Integer.parseInt(number);
295 }
catch (
final NumberFormatException ignored) {
306 private static boolean parseMap(@NotNull
final Element typeElement) {
308 return attribute != null && attribute.getValue().equals(
"yes");
320 private static int[]
parseInv(@NotNull
final Element typeElement, @NotNull
final String typeName, @NotNull
final ErrorViewCollector errorViewCollector) {
322 if (attribute == null) {
326 final String inv = attribute.getValue();
330 if (inv.equals(
"*")) {
335 final int[] result =
new int[types.length];
336 for (
int i = 0; i < types.length; i++) {
338 result[i] = Integer.parseInt(types[i]);
339 }
catch (
final NumberFormatException ignored) {
354 return attribute != null && attribute.getValue().equals(
"yes");
372 if (ignoreElements.size() > 0) {
373 final Element ignoreElement = ignoreElements.get(0);
378 return typeAttributes;
392 if (requiredElements.size() > 0) {
395 if (archAttribute == null) {
399 final String attributeValue = archAttribute.getValue();
400 if (attributeValue.isEmpty()) {
406 if (valueAttribute == null) {
410 final String value = valueAttribute.getValue();
411 if (value.isEmpty()) {
432 if (archAttribute == null) {
437 final String attributeValue = archAttribute.getValue();
438 if (attributeValue.isEmpty()) {
443 ignoreTable.add(attributeValue);
458 if (nameAttribute == null) {
463 final String name = nameAttribute.getValue();
464 final Iterable<String> ignoreList = ignorelistsDefinition.get(name);
465 if (ignoreList == null) {
470 for (
final String ignoreItem : ignoreList) {
471 ignoreTable.add(ignoreItem);
484 return elements.size() == 0 ? null : elements.get(0).getValue().trim();
493 private static String
parseUse(@NotNull
final Element root) {
495 return elements.size() == 0 ? null : elements.get(0).getValue().trim();
513 for (
final Element childElement :
new ElementsIterable(typeElement.getChildElements())) {
514 final String childName = childElement.getLocalName();
517 parseAttribute(childElement, errorViewCollector, typeName, archetypeTypeSet, sections, defaultAttributeSection.getSectionName());
520 if (nameAttribute == null) {
525 final String sectionName = nameAttribute.getValue();
526 if (sectionName.isEmpty()) {
532 parseAttribute(element, errorViewCollector, typeName, archetypeTypeSet, sections, sectionName);
551 if (archetypeAttribute == null) {
556 sections.addArchetypeAttribute(effectiveSectionName, archetypeAttribute);
573 return archetypeAttributeParser.
load(attributeElement, errorViewCollector, archetypeTypeSet, typeName);
static ArchetypeAttributesDefinition parseTypeAttributes(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection< String > ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition)
Parses the type attributes of a "type" or "default_type" Element.
Utility class for parsing ArchetypeAttributes.
Utility class for string manipulation.
static final String XML_IMPORT_TYPE_NAME
The "name" attribute name of a XML_ELEMENT_IMPORT_TYPE element.
Convenience class for adding messages to a ErrorView instance using a fixed category name...
static final String XML_DESCRIPTION
Description Element Name.
ArchetypeAttribute load(@NotNull final Element attributeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final String typeName)
Loading the data from an xml element into this object.
A set of ArchetypeAttributeDefinitions.
ArchetypeTypeParser(@NotNull final ArchetypeAttributeParser archetypeAttributeParser)
Creates a new instance.
static final String GENERAL_SECTION
The name of the "General" section.
Manages ArchetypeType instances, list, and bitmask definitions.
This Class contains the data of one archetype attribute.
static final String XML_ELEMENT_IMPORT_TYPE
Import Type Element Name.
static int [] parseInv(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector)
Parses the "inv" attribute of a "type" Element.
void parseAttribute(@NotNull final Element attributeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final ArchetypeAttributeSections sections, @NotNull final String sectionName)
Parses an Constants#XML_ELEMENT_ATTRIBUTE element.
Contains the data of one Gridarta Object-Type.
An Exception thrown if an attribute key does not exist.
Utility class for parsing ArchetypeType instances.
static void addDefaultList(@NotNull final Iterable< ArchetypeAttributeSection > archetypeType, @NotNull final ArchetypeType newArchetypeType, @NotNull final Collection< String > autoIgnoreTable, @NotNull final Collection< String > ignoreTable)
Adds all attributes of an ArchetypeType to an ArchetypeAttributeSection that are not ignored...
Constants needed to parse "types.xml" files.
static final String XML_ELEMENT_SECTION
Section Element Name.
static final String SPECIAL_SECTION
The name of the "Special" section.
static final Category LOG
The logger for printing log messages.
static void parseIgnoreListAttribute(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection< String > ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition)
Parses the "ignore_list" children.
final ArchetypeAttributeParser archetypeAttributeParser
The parser to use.
Defines possible error categories for ErrorView instances.
static String parseImportType(@NotNull final Element importTypeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector)
Parses the Constants#XML_ELEMENT_IMPORT_TYPE of an Constants#XML_ELEMENT_TYPE or Constants#XML_ELEMEN...
static final String XML_TYPE_INV
The name of the "inv" attribute within XML_ELEMENT_TYPE elements.
Base package of all Gridarta classes.
static final String XML_ELEMENT_REQUIRED
Required Element Name.
static final String XML_ELEMENT_IGNORE_LIST
The name of the "ignore_list" element.
static boolean parseMap(@NotNull final Element typeElement)
Parses the "map" attribute of a "type" Element.
A set of ArchetypeAttributes.
static final String XML_TYPE_ALLOWS_ALL_INV
The name of the "allows_all_inv" attribute within XML_ELEMENT_TYPE elements.
ArchetypeType loadAttributeList(@NotNull final Element typeElement, @NotNull final ErrorViewCollector errorViewCollector, @Nullable final ArchetypeType parentArchetypeType, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final IgnorelistsDefinition ignorelistsDefinition, final boolean isDefaultType)
Parses an element which contains a list of Constants#XML_ELEMENT_ATTRIBUTE elements from a types...
static final String XML_ATTRIBUTE_ARCH
The name of the "arch" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_TYPE_NAME
The name of the "name" attribute within XML_ELEMENT_TYPE or XML_ELEMENT_DEFAULT_TYPE elements...
String getAttributeName()
Returns the user interface attribute name.
static final int [] EMPTY_INT_ARRAY
An empty array of.
static final String XML_USE
Use Element Name.
static final String XML_TYPE_MAP
The name of the "map" attribute within XML_ELEMENT_TYPE elements.
A list of ArchetypeAttributeSection instances.
Holds the key/value pair of an archetype attribute definition.
static final String XML_IGNORE_LIST_NAME
The "name" attribute name of a XML_ELEMENT_IGNORE_LIST element.
static final Pattern PATTERN_COMMA
The pattern that matches a single comma (",").
Iterable< ArchetypeAttributeSection > addAttributeList(@NotNull final Element typeElement, @NotNull final ArchetypeAttributeSection defaultAttributeSection, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet)
Parses the Constants#XML_ELEMENT_ATTRIBUTE and Constants#XML_ELEMENT_SECTION children of a "type" or ...
static final String XML_SECTION_NAME
The "name" attribute name of a XML_ELEMENT_SECTION element.
static String parseDescription(@NotNull final Element root)
Parses the Constants#XML_DESCRIPTION child.
static void parseAttributeAttributes(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection< String > ignoreTable)
Parses the Constants#XML_ELEMENT_ATTRIBUTE child.
static int parseTypeNo(@NotNull final Element typeElement, final boolean isDefaultType, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector)
Parses the type number of a "type" or "default_type" Element.
The contents of an <ignorelists> element of a types.xml file.
static final String XML_TYPE_DISPLAY
The name of the "display" attribute within XML_ELEMENT_TYPE elements.
static final String XML_ATTRIBUTE_VALUE
The name of the "value" attribute within XML_ELEMENT_ATTRIBUTE elements.
static String parseUse(@NotNull final Element root)
Parses the Constants#XML_USE child.
void addAttributeSection(@NotNull final ArchetypeAttributeSection newArchetypeAttributeSection)
Adds an ArchetypeAttributeSection.
static final String XML_ELEMENT_IGNORE
Ignore Element Name.
static ArchetypeAttributesDefinition parseRequiredAttribute(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector)
Parses the Constants#XML_ELEMENT_REQUIRED child.
static final String XML_ELEMENT_ATTRIBUTE
The name of the "attribute" element.
An ArchetypeAttribute for selecting text fields.
void addArchetypeAttribute(@NotNull final String sectionName, @NotNull final ArchetypeAttribute archetypeAttribute)
Adds an ArchetypeAttribute to this archetype type.
static void addImportList(@NotNull final String importName, @NotNull final ArchetypeType newArchetypeType, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Collection< String > autoIgnoreTable)
Adds all imported attributes to an ArchetypeAttributeSection.
static final String XML_TYPE_NUMBER
The name of the "number" attribute within XML_ELEMENT_TYPE elements.
static boolean parseAllowsAllInv(@NotNull final Element typeElement)
Parses the "allows_all_inv" attribute of a "type" Element.
static String parseTypeName(@NotNull final Element typeElement, final boolean isDefaultType)
Parses the type name of an Constants#XML_ELEMENT_TYPE or Constants#XML_ELEMENT_DEFAULT_TYPE Element...
ArchetypeAttribute parseAttribute(@NotNull final Element attributeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet)
Parses an XML attribute element.
void add(@NotNull final ArchetypeAttributeDefinition archetypeAttribute)
Adds an ArchetypeAttributeDefinition.