1 package net.sf.saxon.instruct; 2 import net.sf.saxon.Configuration; 3 import net.sf.saxon.event.Stripper; 4 import net.sf.saxon.functions.FunctionLibrary; 5 import net.sf.saxon.om.NamespaceConstant; 6 import net.sf.saxon.query.StaticQueryContext; 7 import net.sf.saxon.query.QueryReader; 8 import net.sf.saxon.sort.CodepointCollator; 9 import net.sf.saxon.trans.*; 10 11 import javax.xml.transform.TransformerException ; 12 import java.io.Serializable ; 13 import java.util.*; 14 15 19 20 public class Executable implements Serializable { 21 22 private transient Configuration config; 24 25 private Mode stripperRules; 27 28 private boolean stripsWhitespace; 30 31 private RuleManager ruleManager; 33 34 private KeyManager keyManager; 36 37 private DecimalFormatManager decimalFormatManager; 39 40 private SlotManager globalVariableMap; 42 43 private HashMap globalVariableIndex = new HashMap(32); 47 48 private String defaultCollationName; 50 51 private Properties defaultOutputProperties; 53 54 private HashMap namedTemplateTable = new HashMap(32); 56 57 private int largestPatternStackFrame = 0; 59 60 private HashMap collationTable = new HashMap(10); 62 63 private HashMap characterMapIndex; 65 66 private LocationMap locationMap; 68 69 private HashMap queryLibraryModules; 71 72 private boolean stripsInputTypeAnnotations; 74 75 private FunctionLibrary functionLibrary; 77 78 private int hostLanguage = Configuration.XSLT; 80 81 private Set requiredParams = null; 83 84 private String reasonUnableToCompile = null; 86 87 public Executable() { 88 89 } 90 91 94 95 public void setConfiguration(Configuration config) { 96 this.config = config; 97 } 98 99 102 103 public Configuration getConfiguration() { 104 return config; 105 } 106 107 110 111 public void setHostLanguage(int language) { 112 hostLanguage = language; 113 } 114 115 120 121 public int getHostLanguage() { 122 return hostLanguage; 123 } 124 128 129 public void setRuleManager(RuleManager rm) { 130 ruleManager = rm; 131 } 132 133 137 138 public RuleManager getRuleManager() { 139 return ruleManager; 140 } 141 142 147 148 public HashMap getNamedTemplateTable() { 149 if (namedTemplateTable==null) { 150 namedTemplateTable = new HashMap(32); 151 } 152 return namedTemplateTable; 153 } 154 155 161 162 public Template getNamedTemplate(int fingerprint) { 163 return (Template)namedTemplateTable.get(new Integer (fingerprint)); 164 } 165 166 170 171 public FunctionLibrary getFunctionLibrary() { 172 return functionLibrary; 173 } 174 175 179 180 public void setFunctionLibrary(FunctionLibrary functionLibrary) { 181 this.functionLibrary = functionLibrary; 183 } 184 185 190 191 public void setCharacterMapIndex(HashMap cmi) { 192 characterMapIndex = cmi; 193 } 194 195 200 201 public HashMap getCharacterMapIndex() { 202 if (characterMapIndex==null) { 203 characterMapIndex = new HashMap(10); 204 } 205 return characterMapIndex; 206 } 207 208 214 215 public void setStripperRules(Mode rules) { 216 stripperRules = rules; 217 } 218 219 225 226 public Mode getStripperRules() { 227 return stripperRules; 228 } 229 230 235 236 public void setStripsWhitespace(boolean strips) { 237 stripsWhitespace = strips; 238 } 239 240 244 245 public Stripper newStripper() { 246 return new Stripper(stripperRules); 247 } 248 249 254 255 public boolean stripsWhitespace() { 256 return stripsWhitespace; 257 } 258 259 262 263 public void setStripsInputTypeAnnotations(boolean strips) { 264 stripsInputTypeAnnotations = strips; 265 } 266 267 270 271 public boolean stripsInputTypeAnnotations() { 272 return stripsInputTypeAnnotations; 273 } 274 275 279 280 public void setKeyManager(KeyManager km) { 281 keyManager = km; 282 } 283 284 288 289 public KeyManager getKeyManager() { 290 if (keyManager==null) { 291 keyManager = new KeyManager(getConfiguration()); 292 } 293 return keyManager; 294 } 295 296 301 302 public void setDefaultOutputProperties(Properties properties) { 303 defaultOutputProperties = properties; 304 } 305 306 310 311 public Properties getDefaultOutputProperties() { 312 if (defaultOutputProperties==null) { 313 defaultOutputProperties = new Properties(); 314 } 315 return defaultOutputProperties; 316 } 317 318 322 323 public void setDecimalFormatManager(DecimalFormatManager dfm) { 324 decimalFormatManager = dfm; 325 } 326 327 331 332 public DecimalFormatManager getDecimalFormatManager() { 333 if (decimalFormatManager==null) { 334 decimalFormatManager = new DecimalFormatManager(); 335 } 336 return decimalFormatManager; 337 } 338 339 343 344 public void setDefaultCollationName(String name) { 345 defaultCollationName = name; 346 } 347 348 353 354 public String getDefaultCollationName() { 355 if (defaultCollationName==null) { 356 return NamespaceConstant.CODEPOINT_COLLATION_URI; 357 } else { 358 return defaultCollationName; 359 } 360 } 361 362 366 367 public Comparator getDefaultCollation() { 368 if (defaultCollationName==null) { 369 return CodepointCollator.getInstance(); 370 } else { 371 return getNamedCollation(defaultCollationName); 372 } 373 } 374 375 380 381 public void setCollationTable(HashMap table) { 382 collationTable = table; 383 } 384 385 390 391 public HashMap getCollationTable() { 392 return collationTable; 393 } 394 395 401 402 public Comparator getNamedCollation(String name) { 403 if (collationTable==null) { 404 collationTable = new HashMap(10); 405 } 406 return (Comparator)collationTable.get(name); 407 } 408 409 415 416 public void addQueryLibraryModule(StaticQueryContext module) { 417 if (queryLibraryModules==null) { 418 queryLibraryModules = new HashMap(5); 419 } 420 String uri = module.getModuleNamespace(); 421 List existing = (List)queryLibraryModules.get(uri); 422 if (existing == null) { 423 existing = new ArrayList(5); 424 existing.add(module); 425 queryLibraryModules.put(uri, existing); 426 } else { 427 existing.add(module); 428 } 429 } 430 431 437 438 public List getQueryLibraryModules(String namespace) { 439 if (queryLibraryModules == null) { 440 return null; 441 } 442 return (List)queryLibraryModules.get(namespace); 443 } 444 445 449 450 public void fixupQueryModules(StaticQueryContext main) throws XPathException { 451 HashMap varMap = new HashMap(10); 452 if (queryLibraryModules != null) { 453 Iterator iter = queryLibraryModules.values().iterator(); 454 while (iter.hasNext()) { 455 List modules = (List)iter.next(); 456 Iterator iter2 = modules.iterator(); 457 while (iter2.hasNext()) { 458 StaticQueryContext env = (StaticQueryContext)iter2.next(); 459 List vars = fixupQueryModule(env); 460 varMap.put(env, vars); 461 } 462 } 463 } 464 List vars = fixupQueryModule(main); 465 varMap.put(main, vars); 466 Iterator iter = varMap.keySet().iterator(); 467 while (iter.hasNext()) { 468 StaticQueryContext env = (StaticQueryContext)iter.next(); 469 List varList = (List)varMap.get(env); 470 env.typeCheckGlobalVariables(varList); 471 } 472 } 473 474 private List fixupQueryModule(StaticQueryContext module) throws XPathException { 475 try { 476 Iterator iter = module.iterateImportedNamespaces(); 478 while (iter.hasNext()) { 479 List modules = (List)queryLibraryModules.get(iter.next()); 480 Iterator iter3 = modules.iterator(); 481 while (iter3.hasNext()) { 482 StaticQueryContext other = (StaticQueryContext)iter3.next(); 483 if (module != other) { 484 QueryReader.importModuleContents(other, module); 485 } 486 } 487 } 488 module.bindUnboundFunctionCalls(); 490 List compiledVars = module.fixupGlobalVariables(module.getGlobalStackFrameMap()); 491 module.fixupGlobalFunctions(); 492 return compiledVars; 493 } catch (XPathException err) { 494 try { 495 module.getConfiguration().getErrorListener().fatalError(err); 496 throw err; 497 } catch (TransformerException err2) { 498 if (err2 instanceof XPathException) { 499 throw (XPathException) err2; 500 } else { 501 throw new StaticError(err2); 502 } 503 } 504 } 505 } 506 507 511 512 public void setPatternSlotSpace(int patternLocals) { 513 largestPatternStackFrame = patternLocals; 514 } 515 516 520 521 public SlotManager getGlobalVariableMap() { 522 if (globalVariableMap == null) { 523 globalVariableMap = config.makeSlotManager(); 524 } 525 return globalVariableMap; 526 } 527 528 533 534 public HashMap getGlobalVariableIndex() { 535 return globalVariableIndex; 536 } 537 538 541 542 public void registerGlobalVariable(GeneralVariable variable) { 543 globalVariableIndex.put(new Integer (variable.getVariableFingerprint()), variable); 544 } 545 546 550 551 public void initialiseBindery(Bindery bindery) { 552 bindery.allocateGlobals(getGlobalVariableMap()); 553 } 554 555 558 559 public int getLargestPatternStackFrame() { 560 return largestPatternStackFrame; 561 } 562 563 566 567 public void setLocationMap(LocationMap map) { 568 locationMap = map; 569 } 570 571 574 575 public LocationMap getLocationMap() { 576 return locationMap; 577 } 578 579 582 583 public void addRequiredParam(int fingerprint) { 584 if (requiredParams == null) { 585 requiredParams = new HashSet(5); 586 } 587 requiredParams.add(new Integer (fingerprint)); 588 } 589 590 593 594 public void checkAllRequiredParamsArePresent(GlobalParameterSet params) throws XPathException { 595 if (requiredParams == null) { 596 return; 597 } 598 Iterator iter = requiredParams.iterator(); 599 while (iter.hasNext()) { 600 int req = ((Integer )iter.next()).intValue(); 601 if (params==null || params.get(req) == null) { 602 DynamicError err = new DynamicError("No value supplied for required parameter " + 603 config.getNamePool().getDisplayName(req)); 604 err.setErrorCode("XTDE0050"); 605 throw err; 606 } 607 } 608 } 609 610 613 614 public void setReasonUnableToCompile(String reason) { 615 reasonUnableToCompile = reason; 616 } 617 618 622 623 public String getReasonUnableToCompile() { 624 return reasonUnableToCompile; 625 } 626 627 } 628 629 | Popular Tags |