1 package net.sf.saxon; 2 import net.sf.saxon.event.*; 3 import net.sf.saxon.expr.XPathContext; 4 import net.sf.saxon.expr.XPathContextMajor; 5 import net.sf.saxon.functions.Component; 6 import net.sf.saxon.instruct.*; 7 import net.sf.saxon.om.*; 8 import net.sf.saxon.tinytree.TinyBuilder; 9 import net.sf.saxon.trace.*; 10 import net.sf.saxon.trans.*; 11 import net.sf.saxon.tree.TreeBuilder; 12 import net.sf.saxon.value.DateTimeValue; 13 import org.xml.sax.SAXParseException ; 14 15 import javax.xml.transform.*; 16 import javax.xml.transform.dom.DOMSource ; 17 import javax.xml.transform.stream.StreamResult ; 18 import java.io.OutputStream ; 19 import java.io.PrintStream ; 20 import java.util.*; 21 22 53 54 public class Controller extends Transformer implements InstructionInfoProvider { 55 56 private Configuration config; 57 private DocumentInfo principalSourceDocument; 58 private Bindery bindery; private NamePool namePool; 60 private Emitter messageEmitter; 61 private RuleManager ruleManager; 62 private Properties outputProperties; 63 private GlobalParameterSet parameters; 64 private PreparedStylesheet preparedStylesheet; 65 private TraceListener traceListener; 66 private boolean tracingPaused; 67 private URIResolver standardURIResolver; 68 private URIResolver userURIResolver; 69 private Result principalResult; 70 private String principalResultURI; 71 private OutputURIResolver outputURIResolver; 72 private ErrorListener errorListener; 73 private Executable executable; 74 private int treeModel = Builder.TINY_TREE; 75 private Template initialTemplate = null; 76 private HashSet allOutputDestinations; 77 private DocumentPool sourceDocumentPool; 78 private HashMap userDataTable; 79 private DateTimeValue currentDateTime; 80 private boolean dateTimePreset = false; 81 private int initialMode = -1; 82 private NodeInfo lastRememberedNode = null; 83 private int lastRememberedNumber = -1; 84 private ClassLoader classLoader; 85 87 94 95 public Controller(Configuration config) { 96 this.config = config; 97 executable = new Executable(); 99 executable.setConfiguration(config); 100 executable.setHostLanguage(config.getHostLanguage()); 101 sourceDocumentPool = new DocumentPool(); 102 reset(); 103 } 104 105 113 114 public Controller(Configuration config, Executable executable) { 115 this.config = config; 116 this.executable = executable; 117 sourceDocumentPool = new DocumentPool(); 118 reset(); 119 } 120 121 144 145 public void reset() { 146 bindery = new Bindery(); 147 namePool = NamePool.getDefaultNamePool(); 148 standardURIResolver = config.getSystemURIResolver(); 149 userURIResolver = config.getURIResolver(); 150 151 outputURIResolver = config.getOutputURIResolver(); 152 errorListener = config.getErrorListener(); 153 if (errorListener instanceof StandardErrorListener) { 154 PrintStream ps = ((StandardErrorListener)errorListener).getErrorOutput(); 158 errorListener = ((StandardErrorListener)errorListener).makeAnother(executable.getHostLanguage()); 159 ((StandardErrorListener)errorListener).setErrorOutput(ps); 160 ((StandardErrorListener)errorListener).setRecoveryPolicy( 161 config.getRecoveryPolicy()); 162 } 163 164 userDataTable = new HashMap(20); 165 166 traceListener = null; 167 tracingPaused = false; 168 TraceListener tracer = config.getTraceListener(); 169 if (tracer!=null) { 170 addTraceListener(tracer); 171 } 172 173 setTreeModel(config.getTreeModel()); 174 principalSourceDocument = null; 175 messageEmitter = null; 176 outputProperties = null; 177 parameters = null; 178 179 principalResult = null; 180 principalResultURI = null; 181 initialTemplate = null; 182 allOutputDestinations = null; 183 currentDateTime = null; 184 dateTimePreset = false; 185 initialMode = -1; 186 lastRememberedNode = null; 187 lastRememberedNumber = -1; 188 classLoader = null; 189 190 } 191 192 198 public Configuration getConfiguration() { 199 return config; 200 } 201 202 216 217 public void setInitialMode(String expandedModeName) { 218 if (expandedModeName==null) return; 219 if (expandedModeName.equals("")) return; 220 initialMode = namePool.allocateClarkName(expandedModeName); 221 } 222 223 227 246 247 public void setOutputProperties(Properties properties) { 248 if (properties == null) { 249 outputProperties = null; 250 } else { 251 Enumeration keys = properties.propertyNames(); 252 while(keys.hasMoreElements()) { 253 String key = (String )keys.nextElement(); 254 setOutputProperty(key, properties.getProperty(key)); 255 } 256 } 257 } 258 259 275 276 public Properties getOutputProperties() { 277 if (outputProperties == null) { 278 if (executable==null) { 279 return new Properties(); 280 } else { 281 outputProperties = executable.getDefaultOutputProperties(); 282 } 283 } 284 285 287 Properties newProps = new Properties(); 288 Enumeration keys = outputProperties.propertyNames(); 289 while(keys.hasMoreElements()) { 290 String key = (String )keys.nextElement(); 291 newProps.put(key, outputProperties.getProperty(key)); 292 } 293 return newProps; 294 } 295 296 311 312 public void setOutputProperty(String name, String value) { 313 if (outputProperties == null) { 314 outputProperties = getOutputProperties(); 315 } 316 try { 317 SaxonOutputKeys.checkOutputProperty(name, value); 318 } catch (DynamicError err) { 319 throw new IllegalArgumentException (err.getMessage()); 320 } 321 outputProperties.put(name, value); 322 } 323 324 339 340 public String getOutputProperty(String name) { 341 try { 342 SaxonOutputKeys.checkOutputProperty(name, null); 343 } catch (DynamicError err) { 344 throw new IllegalArgumentException (err.getMessage()); 345 } 346 if (outputProperties == null) { 347 if (executable==null) { 348 return null; 349 } else { 350 outputProperties = executable.getDefaultOutputProperties(); 351 } 352 } 353 return outputProperties.getProperty(name); 354 } 355 356 370 371 public void setBaseOutputURI(String uri) { 372 principalResultURI = uri; 373 } 374 375 389 390 public String getBaseOutputURI() { 391 return principalResultURI; 392 } 393 394 399 400 public Result getPrincipalResult() { 401 return principalResult; 402 } 403 404 409 410 public boolean checkUniqueOutputDestination(String uri) { 411 if (allOutputDestinations == null) { 412 allOutputDestinations = new HashSet(20); 413 } 414 if (allOutputDestinations.contains(uri)) { 415 return false; 416 } 417 allOutputDestinations.add(uri); 418 return true; 419 } 420 421 423 441 442 public void setInitialTemplate(String expandedName) throws XPathException { 443 int fingerprint = namePool.allocateClarkName(expandedName); 444 Template t = getExecutable().getNamedTemplate(fingerprint); 445 if (t == null) { 446 DynamicError err = new DynamicError("There is no named template with expanded name " 447 + expandedName); 448 err.setErrorCode("XTDE0040"); 449 throw err; 450 } else { 451 initialTemplate = t; 452 } 453 } 454 455 457 464 465 public PipelineConfiguration makePipelineConfiguration() { 466 PipelineConfiguration pipe = new PipelineConfiguration(); 467 pipe.setConfiguration(getConfiguration()); 468 pipe.setErrorListener(getErrorListener()); 469 pipe.setURIResolver(userURIResolver==null ? standardURIResolver : userURIResolver); 470 pipe.setController(this); 471 if (getExecutable() != null) { 472 pipe.setLocationProvider(getExecutable().getLocationMap()); 474 } 475 return pipe; 476 } 477 478 488 489 public Emitter makeMessageEmitter() throws XPathException { 490 String emitterClass = config.getMessageEmitterClass(); 491 492 Object emitter = config.getInstance(emitterClass, getClassLoader()); 493 if (!(emitter instanceof Emitter)) { 494 throw new DynamicError(emitterClass + " is not an Emitter"); 495 } 496 setMessageEmitter((Emitter)emitter); 497 return messageEmitter; 498 } 499 500 521 522 public void setMessageEmitter(Emitter emitter) { 523 messageEmitter = emitter; 524 messageEmitter.setPipelineConfiguration(makePipelineConfiguration()); 525 } 526 527 534 535 public Emitter getMessageEmitter() { 536 return messageEmitter; 537 } 538 539 553 554 public CharacterMapExpander makeCharacterMapExpander(String useMaps) throws XPathException { 555 CharacterMapExpander characterMapExpander = null; 556 HashMap characterMapIndex = getExecutable().getCharacterMapIndex(); 557 if (useMaps != null && characterMapIndex != null) { 558 List characterMaps = new ArrayList(5); 559 StringTokenizer st = new StringTokenizer(useMaps); 560 while (st.hasMoreTokens()) { 561 String expandedName = st.nextToken(); 562 int f = namePool.getFingerprintForExpandedName(expandedName); 563 HashMap map = (HashMap)characterMapIndex.get(new Integer (f)); 564 if (map==null) { 565 throw new DynamicError("Character map '" + expandedName + "' has not been defined"); 566 } 567 characterMaps.add(map); 568 } 569 if (characterMaps.size() > 0) { 570 characterMapExpander = new CharacterMapExpander(); 571 characterMapExpander.setCharacterMaps(characterMaps); 572 } 573 } 574 return characterMapExpander; 575 } 576 577 585 586 public int getRecoveryPolicy() { 587 if (errorListener instanceof StandardErrorListener) { 588 return ((StandardErrorListener)errorListener).getRecoveryPolicy(); 589 } else { 590 return Configuration.RECOVER_WITH_WARNINGS; 591 } 592 } 593 594 599 600 public void setErrorListener(ErrorListener listener) { 601 errorListener = listener; 602 } 603 604 609 610 public ErrorListener getErrorListener() { 611 return errorListener; 612 } 613 614 625 626 public void recoverableError(XPathException err) throws DynamicError { 627 try { 628 if (executable.getHostLanguage() == Configuration.XQUERY) { 629 errorListener.fatalError(err); 630 throw err; 631 } else { 632 errorListener.error(err); 633 } 634 } catch (TransformerException e) { 635 throw DynamicError.makeDynamicError(e); 636 } 637 } 638 639 643 644 651 652 public Executable getExecutable() { 653 return executable; 654 } 655 656 663 664 public DocumentPool getDocumentPool() { 665 return sourceDocumentPool; 666 } 667 668 674 675 public void clearDocumentPool() { 676 sourceDocumentPool = new DocumentPool(); 677 } 678 679 689 690 public void setPrincipalSourceDocument(DocumentInfo doc) { 691 principalSourceDocument = doc; 692 } 693 694 701 702 public Bindery getBindery() { 703 return bindery; 704 } 705 706 713 714 public DocumentInfo getPrincipalSourceDocument() { 715 return principalSourceDocument; 716 } 717 718 725 726 public void setURIResolver(URIResolver resolver) { 727 userURIResolver = resolver; 728 } 729 730 739 740 public URIResolver getURIResolver() { 741 return userURIResolver; 742 } 743 744 752 753 public URIResolver getStandardURIResolver() { 754 return standardURIResolver; 755 } 756 757 772 773 public void setOutputURIResolver(OutputURIResolver resolver) { 774 if (resolver==null) { 775 outputURIResolver = StandardOutputResolver.getInstance(); 776 } else { 777 outputURIResolver = resolver; 778 } 779 } 780 781 789 790 public OutputURIResolver getOutputURIResolver() { 791 return outputURIResolver; 792 } 793 794 801 802 public KeyManager getKeyManager() { 803 return executable.getKeyManager(); 804 } 805 806 815 816 public NamePool getNamePool() { 817 return namePool; 818 } 819 820 830 831 public void setTreeModel(int model) { 832 treeModel = model; 833 } 834 835 841 842 public Builder makeBuilder() { 843 Builder b; 844 if (treeModel==Builder.TINY_TREE) { 845 b = new TinyBuilder(); 846 } else { 847 b = new TreeBuilder(); 848 } 849 b.setTiming(config.isTiming()); 850 b.setLineNumbering(config.isLineNumbering()); 851 b.setPipelineConfiguration(makePipelineConfiguration()); 852 return b; 853 } 854 855 873 874 public Stripper makeStripper(Receiver b) { 875 if (config.isStripsAllWhiteSpace()) { 876 if (b==null) { 877 return AllElementStripper.getInstance(); 878 } else { 879 Stripper s = new AllElementStripper(); 880 s.setUnderlyingReceiver(b); 881 return s; 882 } 883 } 884 Stripper stripper; 885 if (executable==null) { 886 stripper = new Stripper(new Mode(Mode.STRIPPER_MODE)); 887 } else { 888 stripper = executable.newStripper(); 889 } 890 stripper.setPipelineConfiguration(makePipelineConfiguration()); 891 if (b != null) { 893 stripper.setUnderlyingReceiver(b); 894 } 895 896 return stripper; 897 } 898 899 907 public void registerDocument(DocumentInfo doc, String systemId) { 908 sourceDocumentPool.add(doc, systemId); 909 } 911 912 916 923 public void setRuleManager(RuleManager r) { 924 ruleManager = r; 925 } 926 927 935 public RuleManager getRuleManager() { 936 return ruleManager; 937 } 938 939 943 953 public TraceListener getTraceListener() { return traceListener; 955 } 956 957 966 967 public final boolean isTracing() { return traceListener != null && !tracingPaused; 969 } 970 971 978 public final void pauseTracing(boolean pause) { 979 tracingPaused = pause; 980 } 981 982 996 997 public void addTraceListener(TraceListener trace) { traceListener = TraceEventMulticaster.add(traceListener, trace); 999 } 1000 1001 1008 1009 public void removeTraceListener(TraceListener trace) { traceListener = TraceEventMulticaster.remove(traceListener, trace); 1011 } 1012 1013 1020 1021 public void setPreparedStylesheet(PreparedStylesheet sheet) { 1022 preparedStylesheet = sheet; 1023 executable = sheet.getExecutable(); 1024 } 1027 1028 1036 1037 public void setExecutable(Executable exec) { 1038 executable = exec; 1039 } 1040 1041 1046 1047 public void initializeController() throws XPathException { 1048 setRuleManager(executable.getRuleManager()); 1049 1051 if (traceListener!=null) { 1052 traceListener.open(); 1053 } 1054 1055 1057 bindery = new Bindery(); 1058 executable.initialiseBindery(bindery); 1059 1060 1064 1066 1068 defineGlobalParameters(bindery); 1069 } 1070 1071 1077 1078 public void defineGlobalParameters(Bindery bindery) throws XPathException { 1079 executable.checkAllRequiredParamsArePresent(parameters); 1080 bindery.defineGlobalParameters(parameters); 1081 } 1082 1083 1084 1085 1089 1104 1105 public Object getUserData(Object key, String name) { 1106 String keyValue = key.hashCode() + " " + name; 1107 return userDataTable.get(keyValue); 1109 } 1110 1111 1127 1128 public void setUserData(Object key, String name, Object data) { 1129 String keyVal = key.hashCode() + " " + name; 1131 if (data==null) { 1132 userDataTable.remove(keyVal); 1133 } else { 1134 userDataTable.put(keyVal, data); 1135 } 1136 } 1137 1138 1139 1143 1154 1155 public void transform(Source source, Result result) throws TransformerException { 1156 if (preparedStylesheet==null) { 1157 throw new DynamicError("Stylesheet has not been prepared"); 1158 } 1159 1160 if (!dateTimePreset) { 1161 currentDateTime = null; } 1163 1164 try { 1165 NodeInfo startNode = null; 1166 boolean wrap = true; 1167 int validationMode = config.getSchemaValidationMode(); 1168 Source underSource = source; 1169 if (source instanceof AugmentedSource) { 1170 Boolean localWrap = ((AugmentedSource)source).getWrapDocument(); 1171 if (localWrap != null) { 1172 wrap = localWrap.booleanValue(); 1173 } 1174 int localValidate = ((AugmentedSource)source).getSchemaValidation(); 1175 if (localValidate != Validation.DEFAULT) { 1176 validationMode = localValidate; 1177 } 1178 if (validationMode == Validation.STRICT || validationMode == Validation.LAX) { 1179 wrap = false; 1181 } 1182 underSource = ((AugmentedSource)source).getContainedSource(); 1183 } 1184 Source s2 = config.getSourceResolver().resolveSource(underSource, config); 1185 if (s2 != null) { 1186 underSource = s2; 1187 } 1188 if (wrap && (underSource instanceof NodeInfo || underSource instanceof DOMSource )) { 1189 startNode = prepareInputTree(underSource); 1190 registerDocument(startNode.getDocumentRoot(), underSource.getSystemId()); 1191 1192 } else if (source == null) { 1193 if (initialTemplate == null) { 1194 throw new DynamicError("Either a source document or an initial template must be specified"); 1195 } 1196 1197 } else { 1198 1201 Builder sourceBuilder = makeBuilder(); 1202 Sender sender = new Sender(makePipelineConfiguration()); 1203 Receiver r = sourceBuilder; 1204 if (executable.stripsWhitespace()) { 1205 r = makeStripper(sourceBuilder); 1206 } 1207 if (executable.stripsInputTypeAnnotations()) { 1208 r = config.getAnnotationStripper(r); 1209 } 1210 sender.send(source, r); 1211 DocumentInfo doc = (DocumentInfo)sourceBuilder.getCurrentRoot(); 1212 registerDocument(doc, source.getSystemId()); 1213 startNode = doc; 1214 } 1215 1216 transformDocument(startNode, result); 1217 1218 } catch (TerminationException err) { 1219 throw err; 1221 } catch (XPathException err) { 1222 Throwable cause = err.getException(); 1223 if (cause != null && cause instanceof SAXParseException ) { 1224 SAXParseException spe = (SAXParseException )cause; 1229 cause = spe.getException(); 1230 if (cause instanceof RuntimeException ) { 1231 errorListener.fatalError(err); 1232 } 1233 } else { 1234 errorListener.fatalError(err); 1235 } 1236 throw err; 1237 } 1238 } 1239 1240 1252 1253 public NodeInfo prepareInputTree(Source source) { 1254 NodeInfo start = unravel(source, getConfiguration()); 1255 if (executable.stripsWhitespace()) { 1256 DocumentInfo docInfo = start.getDocumentRoot(); 1257 StrippedDocument strippedDoc = new StrippedDocument(docInfo, makeStripper(null)); 1258 start = strippedDoc.wrap(start); 1259 } 1260 return start; 1261 } 1262 1263 1268 1269 public static NodeInfo unravel(Source source, Configuration config) { 1270 List externalObjectModels = config.getExternalObjectModels(); 1271 for (int m=0; m<externalObjectModels.size(); m++) { 1272 ExternalObjectModel model = (ExternalObjectModel)externalObjectModels.get(m); 1273 NodeInfo node = model.unravel(source, config); 1274 if (node != null) { 1275 return node; 1276 } 1277 } 1278 if (source instanceof NodeInfo) { 1279 return (NodeInfo)source; 1280 } 1281 return null; 1282 } 1283 1284 1300 1301 public void transformDocument(NodeInfo startNode, Result result) 1302 throws TransformerException { 1303 1304 if (executable==null) { 1305 throw new DynamicError("Stylesheet has not been compiled"); 1306 } 1307 1308 1312 boolean mustClose = (result instanceof StreamResult && 1313 ((StreamResult )result).getOutputStream() == null); 1314 1315 principalResult = result; 1316 if (principalResultURI == null) { 1317 principalResultURI = result.getSystemId(); 1318 } 1319 1320 XPathContextMajor initialContext = newXPathContext(); 1321 initialContext.setOrigin(this); 1322 1323 if (startNode != null) { 1324 DocumentInfo sourceDoc; 1325 if (startNode instanceof DocumentInfo) { 1326 sourceDoc = (DocumentInfo)startNode; 1327 } else { 1328 sourceDoc = startNode.getDocumentRoot(); 1329 if (sourceDoc == null) { 1330 throw new DynamicError("Source tree must have a document node as its root"); 1331 } 1332 } 1333 1334 principalSourceDocument = sourceDoc; 1335 1336 if (sourceDoc.getConfiguration()==null) { 1337 throw new TransformerException("The supplied source document must be associated with a Configuration"); 1339 } 1341 1342 if (sourceDoc.getNamePool() != preparedStylesheet.getTargetNamePool()) { 1343 throw new DynamicError("Source document and stylesheet must use the same name pool"); 1344 } 1345 SequenceIterator currentIter = SingletonIterator.makeIterator(sourceDoc); 1346 currentIter.next(); 1347 initialContext.setCurrentIterator(currentIter); 1348 } 1349 1350 initializeController(); 1351 1352 if (getConfiguration().getTraceListener() != null) { 1354 preEvaluateGlobals(initialContext); 1355 } 1356 1357 Properties xslOutputProps = executable.getDefaultOutputProperties(); 1358 1359 if (outputProperties!=null) { 1361 Enumeration props = outputProperties.propertyNames(); 1362 while (props.hasMoreElements()) { 1363 String p = (String )props.nextElement(); 1364 String v = outputProperties.getProperty(p); 1365 xslOutputProps.put(p, v); 1366 } 1367 } 1368 1369 String nextInChain = xslOutputProps.getProperty(SaxonOutputKeys.NEXT_IN_CHAIN); 1371 if (nextInChain != null) { 1372 String baseURI = xslOutputProps.getProperty(SaxonOutputKeys.NEXT_IN_CHAIN_BASE_URI); 1373 result = prepareNextStylesheet(nextInChain, baseURI, result); 1374 } 1375 1376 initialContext.changeOutputDestination(xslOutputProps, result, true, Validation.PRESERVE, null); 1377 initialContext.getReceiver().startDocument(0); 1378 1379 1381 if (initialTemplate == null) { 1382 AxisIterator single = SingletonIterator.makeIterator(startNode); 1383 initialContext.setCurrentIterator(single); 1384 principalSourceDocument = (startNode==null ? null : startNode.getDocumentRoot()); 1385 if (principalSourceDocument == null) { 1386 throw new DynamicError("Source tree must be rooted at a document node"); 1387 } 1388 TailCall tc = ApplyTemplates.applyTemplates( 1389 initialContext.getCurrentIterator(), 1390 getRuleManager().getMode(initialMode), 1391 null, null, initialContext, false, 0); 1392 while (tc != null) { 1393 tc = tc.processLeavingTail(initialContext); 1394 } 1395 } else { 1396 Template t = initialTemplate; 1397 XPathContextMajor c2 = initialContext.newContext(); 1398 c2.setOrigin(this); 1399 c2.openStackFrame(t.getStackFrameMap()); 1400 c2.setLocalParameters(new ParameterSet()); 1401 c2.setTunnelParameters(new ParameterSet()); 1402 1403 TailCall tc = t.expand(c2); 1404 while (tc != null) { 1405 tc = tc.processLeavingTail(c2); 1406 } 1407 } 1408 1409 if (traceListener!=null) { 1410 traceListener.close(); 1411 } 1412 1413 initialContext.getReceiver().endDocument(); 1414 initialContext.getReceiver().close(); 1415 1416 if (mustClose && result instanceof StreamResult ) { 1417 OutputStream os = ((StreamResult )result).getOutputStream(); 1418 if (os != null) { 1419 try { 1420 os.close(); 1421 } catch (java.io.IOException err) { 1422 throw new DynamicError(err); 1423 } 1424 } 1425 } 1426 1427 } 1428 1429 1434 1435 public void preEvaluateGlobals(XPathContext context) throws XPathException { 1436 HashMap vars = getExecutable().getGlobalVariableIndex(); 1437 Iterator iter = vars.values().iterator(); 1438 while (iter.hasNext()) { 1439 GlobalVariable var = (GlobalVariable)iter.next(); 1440 var.evaluateVariable(context); 1441 } 1442 } 1443 1444 1457 1458 public Result prepareNextStylesheet(String href, String baseURI, Result result) 1459 throws TransformerException { 1460 1461 1464 Source source = null; 1465 if (userURIResolver != null) { 1466 source = userURIResolver.resolve(href, baseURI); 1467 } 1468 if (source == null) { 1469 source = standardURIResolver.resolve(href, baseURI); 1470 } 1471 TransformerFactoryImpl factory = new TransformerFactoryImpl(); 1472 factory.setConfiguration(config); 1473 Templates next = factory.newTemplates(source); 1474 TransformerReceiver nextTransformer = 1475 new TransformerReceiver((Controller) next.newTransformer()); 1476 1477 nextTransformer.setSystemId(principalResultURI); 1478 nextTransformer.setPipelineConfiguration(makePipelineConfiguration()); 1479 nextTransformer.setResult(result); 1480 1481 return nextTransformer; 1482 } 1483 1484 1488 1529 1530 public void setParameter(String expandedName, Object value) { 1531 1532 if (parameters == null) { 1533 parameters = new GlobalParameterSet(); 1534 } 1535 1536 int fingerprint = namePool.allocateClarkName(expandedName); 1537 parameters.put(fingerprint, value); 1538 1539 } 1540 1541 1544 1545 public void clearParameters() { 1546 parameters = null; 1547 } 1548 1549 1558 1559 public Object getParameter(String expandedName) { 1560 if (parameters==null) { 1561 return null; 1562 } 1563 int f = namePool.allocateClarkName(expandedName); 1564 return parameters.get(f); 1565 } 1566 1567 1577 1578 public void setCurrentDateTime(DateTimeValue dateTime) throws XPathException { 1579 if (currentDateTime==null) { 1580 if (dateTime.getComponent(Component.TIMEZONE) == null) { 1581 throw new DynamicError("No timezone is present in supplied value of current date/time"); 1582 } 1583 currentDateTime = dateTime; 1584 dateTimePreset = true; 1585 } 1586 } 1587 1588 1597 1598 public DateTimeValue getCurrentDateTime() { 1599 if (currentDateTime==null) { 1600 currentDateTime = new DateTimeValue(new GregorianCalendar(), true); 1601 } 1602 return currentDateTime; 1603 } 1604 1605 1609 1616 1617 public XPathContextMajor newXPathContext() { 1618 return new XPathContextMajor(this); 1619 } 1620 1621 1629 1630 public void setRememberedNumber(NodeInfo node, int number) { 1631 lastRememberedNode = node; 1632 lastRememberedNumber = number; 1633 } 1634 1635 1643 1644 public int getRememberedNumber(NodeInfo node) { 1645 if (lastRememberedNode == node) { 1646 return lastRememberedNumber; 1647 } 1648 return -1; 1649 } 1650 1651 1656 1657 public InstructionInfo getInstructionInfo() { 1658 InstructionDetails details = new InstructionDetails(); 1659 details.setConstructType(Location.CONTROLLER); 1660 return details; 1661 } 1662 1663 1674 1675 public void setClassLoader(ClassLoader loader) { 1676 this.classLoader = loader; 1677 } 1678 1679 1687 1688 public ClassLoader getClassLoader() { 1689 return classLoader; 1690 } 1691 1692 1699 1700} 1704 1705 | Popular Tags |