20 package net.sf.gridarta.model.archetypetype;
28 import nu.xom.Attribute;
29 import nu.xom.Document;
30 import nu.xom.Element;
31 import nu.xom.Elements;
33 import org.apache.log4j.Category;
34 import org.apache.log4j.Logger;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
75 final Element rootElement = document.getRootElement();
80 if (attributeOrderElements.size() > 0) {
86 parseTypes(archetypeTypeSet, element, errorViewCollector, defaultArchetypeType, ignorelistsDefinition);
89 if (LOG.isInfoEnabled()) {
92 return archetypeTypeSet;
106 if (attributeBitmask != null) {
107 archetypeTypeSet.addBitmask(name, attributeBitmask);
127 parseBmentry(element, errorViewCollector, name, isNamed, attributeBitmask);
143 return attributeBitmask;
158 final String bitAttribute = tmpBitAttribute == null ?
"" : tmpBitAttribute.getValue();
161 final String valueAttribute = tmpValueAttribute == null ?
"" : tmpValueAttribute.getValue();
162 if (!bitAttribute.isEmpty() && !valueAttribute.isEmpty()) {
170 if (bitAttribute.isEmpty()) {
176 value = Integer.parseInt(valueAttribute);
177 }
catch (
final NumberFormatException ignored) {
184 bitValue = Integer.parseInt(bitAttribute);
185 }
catch (
final NumberFormatException ignored) {
189 if (bitValue < 0 || bitValue >= 32) {
193 if (!attributeBitmask.addBitName(bitValue, name)) {
197 value = 1 << bitValue;
200 attributeBitmask.addName(name, value);
203 final String encoding = tmpEncodingAttribute == null ?
"" : tmpEncodingAttribute.getValue();
205 if (encoding.isEmpty()) {
209 attributeBitmask.addNamedValue(encoding, value);
211 if (!encoding.isEmpty()) {
228 parseList(archetypeTypeSet, element, errorViewCollector);
245 archetypeTypeSet.addList(name, list);
260 value = Integer.valueOf(valueString);
261 }
catch (
final NumberFormatException ignore) {
266 list.add(value, name);
267 }
catch (
final IllegalArgumentException ex) {
285 return ignorelistsDefinition;
297 if (!value.isEmpty()) {
298 if (archetypeTypeSet.addAttributeOrder(value)) {
314 if (ignorelistsDefinition.containsKey(name)) {
320 if (archAttribute != null) {
322 ignorelistsDefinition.put(name, archAttribute.getValue());
323 }
catch (
final IllegalArgumentException ex) {
331 rejectAttributes(attributeElement,
Constants.
XML_ATTRIBUTE_TYPE,
Constants.
XML_ATTRIBUTE_ARCH_BEGIN,
Constants.
XML_ATTRIBUTE_ARCH_END,
Constants.
XML_ATTRIBUTE_EDITOR,
Constants.
XML_ATTRIBUTE_VALUE,
Constants.
XML_ATTRIBUTE_MIN,
Constants.
XML_ATTRIBUTE_MAX,
Constants.
XML_ATTRIBUTE_CHECK_MIN,
Constants.
XML_ATTRIBUTE_CHECK_MAX,
Constants.
XML_ATTRIBUTE_LENGTH,
Constants.
XML_ATTRIBUTE_TRUE,
Constants.
XML_ATTRIBUTE_FALSE,
Constants.
XML_ATTRIBUTE_MARKER);
349 return archetypeTypeParser.
loadAttributeList(defaultTypeElement, errorViewCollector, null, archetypeTypeSet, ignorelistsDefinition,
true);
364 archetypeTypeSet.addArchetypeType(archetypeTypeParser.
loadAttributeList(typeElement, errorViewCollector, defaultArchetypeType, archetypeTypeSet, ignorelistsDefinition,
false));
375 for (
final String attribute : attributes) {
376 if (element.getAttribute(attribute) != null) {
static void parseIgnoreList(@NotNull final Element ignoreListElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final IgnorelistsDefinition ignorelistsDefinition)
Parses the Constants#XML_ELEMENT_IGNORE_LIST section of a types.xml file.
static final String XML_ELEMENT_BITMASKS
The name of the "bitmasks" element.
static void parseBmentry(@NotNull final Element bmentryElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String bitmaskName, final boolean isNamed, @NotNull final AttributeBitmask attributeBitmask)
Parses a Constants#XML_ELEMENT_BMENTRY section of a types.xml file.
Utility class for string manipulation.
void parseTypes(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element typeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final ArchetypeType defaultArchetypeType, @NotNull final IgnorelistsDefinition ignorelistsDefinition)
Parses an Constants#XML_ELEMENT_TYPE element of a types.xml file.
final ArchetypeTypeParser archetypeTypeParser
The ArchetypeTypeParser }to use.
static final String XML_LIST_NAME
The name of the "name" attribute within XML_ELEMENT_LIST elements.
Convenience class for adding messages to a ErrorView instance using a fixed category name...
static final String XML_ATTRIBUTE_CHECK_MIN
The name of the "check_min" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ELEMENT_DEFAULT_TYPE
The name of the "default_type" element.
XML related utility functions.
Manages ArchetypeType instances, list, and bitmask definitions.
static final String XML_ELEMENT_LIST
The name of the "list" element.
static final String XML_ATTRIBUTE_MAX
The name of the "max" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ATTRIBUTE_ARCH_END
The name of the "arch_end" attribute within XML_ELEMENT_ATTRIBUTE elements.
static void parseAttributeOrder(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Node attributeOrderElement, @NotNull final ErrorViewCollector errorViewCollector)
Parses the Constants#XML_ELEMENT_ATTRIBUTE_ORDER section of a types.xml file.
Contains the data of one Gridarta Object-Type.
Utility class for parsing ArchetypeType instances.
static final String XML_ATTRIBUTE_LENGTH
The name of the "length" attribute within XML_ELEMENT_ATTRIBUTE elements.
static IgnorelistsDefinition parseIgnoreLists(@NotNull final Element ignorelistsElement, @NotNull final ErrorViewCollector errorViewCollector)
Parses the Constants#XML_ELEMENT_IGNORELISTS section of a types.xml file.
static final String XML_ELEMENT_BMENTRY
The name of the "bmentry" element.
Constants needed to parse "types.xml" files.
static void parseLists(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element listsElement, @NotNull final ErrorViewCollector errorViewCollector)
Parses the Constants#XML_ELEMENT_LISTS section of a types.xml file.
static final String XML_BITMASK_NAME
The name of the "name" attribute within XML_ELEMENT_BITMASK elements.
ArchetypeTypeSet loadTypesFromXML(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final Document document)
Loads a types.xml file.
static final Category LOG
The logger for printing log messages.
static final String XML_TYPE_AVAILABLE
The name of the "available" attribute within XML_ELEMENT_TYPE elements.
static final String XML_ATTRIBUTE_EDITOR
The name of the "editor" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_BITMASK_IS_NAMED
The name of the "is_named" attribute within XML_ELEMENT_BITMASK elements.
Defines possible error categories for ErrorView instances.
int getMaxValue()
Returns the maximum allowed bitmask value.
static void parseListEntry(@NotNull final Element listentryElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final ArchetypeTypeList list)
Parses an Constants#XML_ELEMENT_LISTENTRY section of a types.xml file and adds it to an ArchetypeType...
static final String XML_LISTENTRY_NAME
The name of the "name" attribute within XML_ELEMENT_LISTENTRY elements.
Base package of all Gridarta classes.
static final String XML_BMENTRY_NAME
The name of the "name" attribute within XML_ELEMENT_BMENTRY elements.
static final String XML_ATTRIBUTE_TRUE
The name of the "true" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ELEMENT_IGNORE_LIST
The name of the "ignore_list" element.
static AttributeBitmask parseBitmask(@NotNull final Element bitmaskElement, @NotNull final String name, @NotNull final ErrorViewCollector errorViewCollector)
Parses a Constants#XML_ELEMENT_BITMASK section of a types.xml file.
static final String XML_BMENTRY_BIT
The name of the "bit" attribute within XML_ELEMENT_BMENTRY elements.
int getNumber()
Returns the number of bitmask entries (not counting zero).
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 void rejectAttributes(@NotNull final Element element, @NotNull final String... attributes)
Makes sure an Element does not define attributes.
static final String XML_ELEMENT_IGNORELISTS
The name of the "ignorelists" element.
static void parseList(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element listElement, @NotNull final ErrorViewCollector errorViewCollector)
Parses an Constants#XML_ELEMENT_LIST section of a types.xml file and adds it to.
This class manages bitmask values which appear in Gridarta archetype attributes.
static final String XML_ATTRIBUTE_TYPE
The name of the "type" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ELEMENT_BITMASK
The name of the "bitmask" element.
static final String XML_ATTRIBUTE_FALSE
The name of the "false" attribute within XML_ELEMENT_ATTRIBUTE elements.
Exception thrown for incorrect arguments.
static final String XML_IGNORE_LIST_NAME
The "name" attribute name of a XML_ELEMENT_IGNORE_LIST element.
int getArchetypeTypeCount()
Returns the number of ArchetypeTypes in the list.
static final String XML_ATTRIBUTE_CHECK_MAX
The name of the "check_max" attribute within XML_ELEMENT_ATTRIBUTE elements.
Parser for ArchetypeTypeSets ("types.xml" files).
static Element getChild(@NotNull final Element parentElement, @NotNull final String childName)
Returns a child Element of a parent element.
static final String XML_LISTENTRY_VALUE
The name of the "value" attribute within XML_ELEMENT_LISTENTRY elements.
The contents of an <ignorelists> element of a types.xml file.
static final String XML_ATTRIBUTE_MIN
The name of the "min" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ATTRIBUTE_VALUE
The name of the "value" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ELEMENT_LISTS
The name of the "lists" element.
static final String XML_ELEMENT_LISTENTRY
The name of the "listentry" element.
static final String XML_ATTRIBUTE_MARKER
The name of the "marker" attribute within XML_ELEMENT_ATTRIBUTE elements.
static void parseBitmasks(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element bitmasksElement, @NotNull final ErrorViewCollector errorViewCollector)
Parses the Constants#XML_ELEMENT_BITMASKS section of a types.xml file.
static final Pattern PATTERN_WHITESPACE_NEWLINE
Pattern to match whitespace including NL and CR.
static final String XML_ELEMENT_ATTRIBUTE
The name of the "attribute" element.
static final String XML_ELEMENT_TYPE
The name of the "type" element.
ArchetypeTypeSetParser(@NotNull final ArchetypeTypeParser archetypeTypeParser)
Creates a new instance.
static final String XML_BMENTRY_VALUE
The name of the "value" attribute within XML_ELEMENT_BMENTRY elements.
static final String XML_ATTRIBUTE_ARCH_BEGIN
The name of the "arch_begin" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ELEMENT_ATTRIBUTE_ORDER
The name of the "attribute_order" element.
ArchetypeType parseDefaultType(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element defaultTypeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final IgnorelistsDefinition ignorelistsDefinition)
Parses the Constants#XML_ELEMENT_DEFAULT_TYPE element of a types.xml file.
boolean containsEncoding(final int value)
Returns whether an external encoding for value exists.
static final String XML_BMENTRY_ENCODING
The name of the "encoding" attribute within XML_ELEMENT_BMENTRY elements.