Esempio n. 1
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;
 }