return parentNode;
}
public static SupposeBlock newInstance(INode parentNode, LinkedList<XMLElement> xmlElementList) throws ElementParseException {
SupposeBlock supposeBlock = new SupposeBlock(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 (supposeBlock.line == null){
try {supposeBlock.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 (supposeBlock.col == null){
try {supposeBlock.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()){
boolean isFirst = true;
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 (isFirst) {
if (xmlElement.getName().equals("BlockThesis")){
supposeBlock.isBlockThesisFirst = true;
}
isFirst = false;
}
if (xmlElement.getName().equals("BlockThesis")){
if (supposeBlock.blockThesis == null) {
supposeBlock.blockThesis = BlockThesis.newInstance(supposeBlock, xmlElementList);
} else {
throw new ElementParseException(ElementParseException.DUPLICATE_ELEMENT, "XMLElement list contains a duplicated <BlockThesis> in element " + NAME, xmlElementList);
}
} else if (xmlElement.getName().equals("Suppose")){
if (supposeBlock.suppose == null) {
supposeBlock.suppose = Suppose.newInstance(supposeBlock, xmlElementList);
} else {
throw new ElementParseException(ElementParseException.DUPLICATE_ELEMENT, "XMLElement list contains a duplicated <Suppose> in element " + NAME, xmlElementList);
}
} else if (xmlElement.getName().equals("Thesis")){
if (supposeBlock.thesis == null) {
supposeBlock.thesis = Thesis.newInstance(supposeBlock, xmlElementList);
} else {
throw new ElementParseException(ElementParseException.DUPLICATE_ELEMENT, "XMLElement list contains a duplicated <Thesis> in element " + NAME, xmlElementList);
}
} else if (ReasoningItem.isReasoningItem(xmlElement.getName())){
supposeBlock.reasoningItemList.add(ReasoningItem.newInstance(supposeBlock, xmlElementList));
} else if (xmlElement.getName().equals("PerCasesReasoning")){
if (supposeBlock.perCasesReasoning == null) {
supposeBlock.perCasesReasoning = PerCasesReasoning.newInstance(supposeBlock, xmlElementList);
} else {
throw new ElementParseException(ElementParseException.DUPLICATE_ELEMENT, "XMLElement list contains a duplicated <PerCasesReasoning> in element " + NAME, xmlElementList);
}
} else if (xmlElement.getName().equals("EndPosition")){
if (supposeBlock.endPosition == null) {
supposeBlock.endPosition = EndPosition.newInstance(supposeBlock, 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 supposeBlock;
}