1 package org.xmldb.xupdate.lexus.commands; 2 3 55 56 import org.w3c.dom.Document ; 57 import org.w3c.dom.Node ; 58 import org.w3c.dom.NodeList ; 59 import org.xmldb.common.xml.queries.XObject; 60 import org.xmldb.common.xml.queries.XPathQuery; 61 import org.xmldb.common.xml.queries.XPathQueryFactory; 62 63 import java.util.Hashtable ; 64 import java.util.Vector ; 65 66 71 public abstract class CommandObject extends Object { 72 73 74 private XPathQuery xpath = null; 75 76 protected Document document = null; 77 78 protected Node contextNode = null; 79 80 protected NodeList selectionNodeList = null; 81 82 protected Hashtable attributes = null; 83 84 protected Vector characters = null; 85 86 87 96 public CommandObject(Node contextNode) throws Exception { 97 if (contextNode == null) { 98 throw new IllegalArgumentException ("Argument contextNode must not be null."); 99 } 100 if (xpath == null) { 101 xpath = XPathQueryFactory.newInstance().newXPathQuery(); 102 } 103 this.contextNode = contextNode; 104 switch (contextNode.getNodeType()) { 105 case Node.DOCUMENT_NODE: 106 document = (Document ) contextNode; 107 break; 108 default: 109 document = contextNode.getOwnerDocument(); 110 } 111 characters = new Vector (); 112 } 113 114 117 public void reset() { 118 characters.clear(); 119 } 120 121 130 public synchronized void selectNodes(String qString) throws Exception { 131 if (qString == null) { 132 throw new IllegalArgumentException ("Argument qString must not be null."); 133 } 134 xpath.setQString(qString); 135 XObject result = xpath.execute(contextNode); 136 if (result.getType() != XObject.CLASS_NODESET) { 137 throw new Exception ("XPath leads not to a Node or NodeList !"); 138 } 139 selectionNodeList = result.nodeset(); 140 if (selectionNodeList.getLength() == 0) { 141 throw new Exception (".selectNodes(): No nodes selected: " + qString); 143 } 144 } 145 146 147 150 public void submitAttributes(Hashtable attributes) { 151 this.attributes = attributes; 152 } 153 154 155 158 public void submitCharacters(String data) { 159 characters.addElement(data); 160 } 161 162 163 166 public abstract boolean submitInstruction(int instruction) throws Exception ; 167 168 169 172 public abstract boolean executeInstruction() throws Exception ; 173 174 175 178 public abstract Node execute() throws Exception ; 179 180 } 181 182 | Popular Tags |