Back to project page sana.
The source code is released under:
Copyright (c) 2010, Moca All rights reserved. The source code for Moca is licensed under the BSD license as follows: Redistribution and use in source and binary forms, with or without modification, ...
If you think the Android project sana listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.moca.procedure.branching; // w w w. j a v a 2s . c o m import java.util.HashMap; import org.moca.procedure.ProcedureElement; import org.moca.procedure.ProcedureParseException; import org.moca.procedure.branching.Criterion.CriterionType; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; /** * LogicBase is a Criteria subclass that serves as a container for a single * Criterion. */ public class LogicBase extends Criteria { private Criterion criterion; public LogicBase(Criterion crit) { this.criterion = crit; } public boolean criteriaMet() { return criterion.criterionMet(); } public static LogicBase fromXML(Node node, HashMap<String, ProcedureElement> elts) throws ProcedureParseException { if(!node.getNodeName().equals("Criteria")) { throw new ProcedureParseException("LogicBase got NodeName " + node.getNodeName()); } if(node.getChildNodes().getLength() != 0) { throw new ProcedureParseException("A single criteria has children."); } NamedNodeMap attributes = node.getAttributes(); Node typeNode = attributes.getNamedItem("type"); String type = ""; CriterionType critType; if(typeNode != null) { type = typeNode.getNodeValue(); if (type.equals("EQUALS")) critType = CriterionType.EQUALS; else if (type.equals("GREATER")) critType = CriterionType.GREATER; else if (type.equals("LESS")) critType = CriterionType.LESS; else throw new ProcedureParseException("LogicBase bad type for NodeName " + node.getNodeName()); } else { throw new ProcedureParseException("LogicBase no type for NodeName " + node.getNodeName()); } Node elementIdNode = attributes.getNamedItem("id"); String elementId = ""; if(elementIdNode != null) { elementId = elementIdNode.getNodeValue(); } else { throw new ProcedureParseException("LogicBase no id for NodeName " + node.getNodeName()); } Node valueNode = attributes.getNamedItem("value"); String value = ""; if(valueNode != null) { value = valueNode.getNodeValue(); } else { throw new ProcedureParseException("LogicBase no value for NodeName " + node.getNodeName()); } ProcedureElement elt = elts.get(elementId); if (elt == null) throw new ProcedureParseException("LogicBase cannot resolve element #" + elementId); return new LogicBase(new Criterion(critType, elt, value)); } }