1 package net.sf.saxon.query; 2 3 import net.sf.saxon.Configuration; 4 import net.sf.saxon.StandardErrorListener; 5 import net.sf.saxon.functions.Component; 6 import net.sf.saxon.trans.XPathException; 7 import net.sf.saxon.trans.DynamicError; 8 import net.sf.saxon.om.Item; 9 import net.sf.saxon.om.NodeInfo; 10 import net.sf.saxon.value.DateTimeValue; 11 12 import javax.xml.transform.ErrorListener ; 13 import javax.xml.transform.URIResolver ; 14 import java.util.HashMap ; 15 16 22 23 public class DynamicQueryContext { 24 25 private Item contextItem; 26 private HashMap parameters; 27 private Configuration config; 28 private URIResolver uriResolver; 29 private ErrorListener errorListener; 30 31 private DateTimeValue currentDateTime; 32 33 public DynamicQueryContext(Configuration config) { 34 this.config = config; 35 uriResolver = config.getURIResolver(); 36 errorListener = config.getErrorListener(); 37 if (errorListener instanceof StandardErrorListener) { 38 ((StandardErrorListener)errorListener).setRecoveryPolicy(Configuration.DO_NOT_RECOVER); 39 } 40 } 41 42 53 54 public void setContextNode(NodeInfo node) { 55 if (node==null) { 56 throw new NullPointerException ("Context node cannot be null"); 57 } 58 contextItem = node; 59 } 60 61 71 72 public void setContextItem(Item item) { 73 if (item==null) { 74 throw new NullPointerException ("Context item cannot be null"); 75 } 76 contextItem = item; 77 } 78 79 84 85 public NodeInfo getContextNode() { 86 return (contextItem instanceof NodeInfo ? 87 (NodeInfo)contextItem : 88 null); 89 } 90 91 96 97 public Item getContextItem() { 98 return contextItem; 99 } 100 101 118 119 public void setParameter(String expandedName, Object value) { 120 if (parameters==null) { 121 parameters = new HashMap (10); 122 } 123 parameters.put(expandedName, value); 124 } 125 126 129 130 public void clearParameters() { 131 parameters = null; 132 } 133 134 141 142 public Object getParameter(String expandedName) { 143 if (parameters==null) return null; 144 return parameters.get(expandedName); 145 } 146 147 150 151 protected HashMap getParameters() { 152 return parameters; 153 } 154 155 163 164 public void setURIResolver(URIResolver resolver) { 165 uriResolver = resolver; 167 } 168 169 176 177 public URIResolver getURIResolver() { 178 return uriResolver; 179 } 180 181 188 189 public void setErrorListener(ErrorListener listener) { 190 errorListener = listener; 191 } 192 193 199 200 public ErrorListener getErrorListener() { 201 return errorListener; 202 } 203 204 205 211 212 public DateTimeValue getCurrentDateTime() { 213 return currentDateTime; 214 } 215 216 223 224 public void setCurrentDateTime(DateTimeValue dateTime) throws XPathException { 225 this.currentDateTime = dateTime; 226 if (dateTime.getComponent(Component.TIMEZONE) == null) { 227 throw new DynamicError("Supplied date/time must include a timezone"); 228 } 229 } 230 231 } 232 233 234 | Popular Tags |