return parentNode;
}
public static RegistrationBlock newInstance(INode parentNode, LinkedList<XMLElement> xmlElementList) throws ElementParseException {
RegistrationBlock registrationBlock = new RegistrationBlock(parentNode);
XMLElement xmlElement = xmlElementList.poll();
if (!xmlElement.getName().equals(NAME)){
throw new ElementParseException(ElementParseException.NOT_VALID_ELEMENT, "XMLElement is a " + xmlElement.getName() + " not a " + NAME, xmlElementList);
}
for (XMLAttribute xmlAttribute : xmlElement.getXMLAttributeList()){
if (xmlAttribute.getName().equals("line")){
if (registrationBlock.line == null){
try {registrationBlock.line = Integer.parseInt(xmlAttribute.getValue());}
catch (Exception e) {throw new ElementParseException(ElementParseException.NOT_VALID_TYPE_OF_ATTRIBUTE_ELEMENT, "XMLElement has an attribute " + xmlAttribute.getName() + " with an invalid type", xmlElementList);};
} else {
throw new ElementParseException(ElementParseException.DUPLICATE_ATTRIBUTE_ELEMENT, "XMLElement has a duplicate attribute " + xmlAttribute.getName(), xmlElementList);
}
} else
if (xmlAttribute.getName().equals("col")){
if (registrationBlock.col == null){
try {registrationBlock.col = Integer.parseInt(xmlAttribute.getValue());}
catch (Exception e) {throw new ElementParseException(ElementParseException.NOT_VALID_TYPE_OF_ATTRIBUTE_ELEMENT, "XMLElement has an attribute " + xmlAttribute.getName() + " with an invalid type", xmlElementList);};
} else {
throw new ElementParseException(ElementParseException.DUPLICATE_ATTRIBUTE_ELEMENT, "XMLElement has a duplicate attribute " + xmlAttribute.getName(), xmlElementList);
}
} else
throw new ElementParseException(ElementParseException.NOT_VALID_ATTRIBUTE_ELEMENT, "XMLElement has not a valid attribute " + xmlAttribute.getName(), xmlElementList);
}
if (!xmlElement.isEmpty()){
while (true){
xmlElement = xmlElementList.peek();
if (xmlElement == null){
throw new ElementParseException(ElementParseException.UNEXPECTED_END_OF_FILE, "Unexpected end of XMLElement list");
}
if (xmlElement.getName().equals(NAME) && xmlElement.isEndElement()){
xmlElement = xmlElementList.poll();
break;
}
if (xmlElement.getName().equals("Let")){
registrationBlock.elementList.add(Let.newInstance(registrationBlock, xmlElementList));
} else if (AuxiliaryItem.isAuxiliaryItem(xmlElement.getName())){
registrationBlock.elementList.add(AuxiliaryItem.newInstance(registrationBlock, xmlElementList));
} else if (xmlElement.getName().equals("Registration")){
registrationBlock.elementList.add(Registration.newInstance(registrationBlock, xmlElementList));
} else if (xmlElement.getName().equals("IdentifyRegistration")){
registrationBlock.elementList.add(IdentifyRegistration.newInstance(registrationBlock, xmlElementList));
} else if (xmlElement.getName().equals("PropertyRegistration")){
registrationBlock.elementList.add(PropertyRegistration.newInstance(registrationBlock, xmlElementList));
} else if (xmlElement.getName().equals("ReductionRegistration")){
registrationBlock.elementList.add(ReductionRegistration.newInstance(registrationBlock, xmlElementList));
} else if (xmlElement.getName().equals("Canceled")){
registrationBlock.elementList.add(Canceled.newInstance(registrationBlock, xmlElementList));
} else if (xmlElement.getName().equals("EndPosition")){
if (registrationBlock.endPosition == null) {
registrationBlock.endPosition = EndPosition.newInstance(registrationBlock, xmlElementList);
} else {
throw new ElementParseException(ElementParseException.DUPLICATE_ELEMENT, "XMLElement list contains a duplicated <EndPosition> in element " + NAME, xmlElementList);
}
} else
throw new ElementParseException(ElementParseException.NOT_VALID_ELEMENT, "The XMLElement " + xmlElement.getName() + " is not valid in " + NAME, xmlElementList);
}
}
return registrationBlock;
}