예제 #1
0
 /**
  * Declare a namespace whose prefix can be used in expressions. Namespaces may either be
  * pre-declared (the traditional Saxon interface), or they may be resolved on demand using a
  * supplied NamespaceContext. When a prefix has to be resolved, the parser looks first in the
  * pre-declared namespaces, then in the supplied NamespaceContext object.
  *
  * @param prefix The namespace prefix. Must not be null. Must not be the empty string ("") -
  *     unqualified names in an XPath expression always refer to the null namespace.
  * @param uri The namespace URI. Must not be null.
  */
 public void declareNamespace(String prefix, String uri) {
   if (prefix == null) {
     throw new NullPointerException("Null prefix supplied to declareNamespace()");
   }
   if (uri == null) {
     throw new NullPointerException("Null namespace URI supplied to declareNamespace()");
   }
   namespaces.put(prefix, uri);
   namePool.allocateNamespaceCode(prefix, uri);
 }
예제 #2
0
 /**
  * Declare a variable. A variable may be declared before an expression referring to it is
  * compiled. Alternatively, a JAXP XPathVariableResolver may be supplied to perform the
  * resolution. A variable that has been explicitly declared is used in preference.
  *
  * @param qname Lexical QName identifying the variable. The namespace prefix, if any, must have
  *     been declared before this method is called, or must be resolvable using the namespace
  *     context.
  * @param initialValue The initial value of the variable. A Java object that can be converted to
  *     an XPath value.
  */
 public Variable declareVariable(String qname, Object initialValue) throws XPathException {
   String prefix;
   String localName;
   try {
     String[] parts = Name.getQNameParts(qname);
     prefix = parts[0];
     localName = parts[1];
   } catch (QNameException err) {
     throw new StaticError("Invalid QName for variable: " + qname);
   }
   String uri = "";
   if (!("".equals(prefix))) {
     uri = getURIForPrefix(prefix);
   }
   Variable var = Variable.make(qname, getConfiguration());
   var.setValue(initialValue);
   int fingerprint = namePool.allocate(prefix, uri, localName) & 0xfffff;
   variables.put(new Integer(fingerprint), var);
   stackFrameMap.allocateSlotNumber(fingerprint);
   return var;
 }
예제 #3
0
 /** Set the default namespace for element and type names */
 public void setDefaultElementNamespace(String uri) {
   defaultElementNamespace = namePool.allocateCodeForURI(uri);
 }