예제 #1
0
 /**
  * Defines an XPath variable and sets its value.
  *
  * @param name the variable name.
  * @param value the variable value.
  * @throws IllegalArgumentException if <code>name</code> is not a valid XPath variable name or if
  *     the value type is not supported by the underlying implementation
  */
 @Override
 public void setVariable(String name, Object value) throws IllegalArgumentException {
   Object o = xPath.getVariableContext();
   if (o instanceof SimpleVariableContext) {
     ((SimpleVariableContext) o).setVariableValue(null, name, value);
   }
 }
예제 #2
0
  private BaseXPath createXPath(String xpathQueryString, Navigator navigator)
      throws JaxenException {

    BaseXPath xpath = new BaseXPath(xpathQueryString, navigator);
    if (properties.size() > 1) {
      SimpleVariableContext vc = new SimpleVariableContext();
      for (Entry<PropertyDescriptor<?>, Object> e : properties.entrySet()) {
        String propName = e.getKey().name();
        if (!"xpath".equals(propName)) {
          Object value = e.getValue();
          vc.setVariableValue(propName, value != null ? value.toString() : null);
        }
      }
      xpath.setVariableContext(vc);
    }
    return xpath;
  }