/**
   * Creates a <code>DOMReference</code> from an element.
   *
   * @param refElem a Reference element
   */
  public DOMReference(Element refElem, XMLCryptoContext context) throws MarshalException {
    // unmarshal Transforms, if specified
    Element nextSibling = DOMUtils.getFirstChildElement(refElem);
    List transforms = new ArrayList(5);
    if (nextSibling.getLocalName().equals("Transforms")) {
      Element transformElem = DOMUtils.getFirstChildElement(nextSibling);
      while (transformElem != null) {
        transforms.add(new DOMTransform(transformElem, context));
        transformElem = DOMUtils.getNextSiblingElement(transformElem);
      }
      nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
    }

    // unmarshal DigestMethod
    Element dmElem = nextSibling;
    this.digestMethod = DOMDigestMethod.unmarshal(dmElem);

    // unmarshal DigestValue
    try {
      Element dvElem = DOMUtils.getNextSiblingElement(dmElem);
      this.digestValue = Base64.decode(dvElem);
    } catch (Base64DecodingException bde) {
      throw new MarshalException(bde);
    }

    // unmarshal attributes
    this.uri = DOMUtils.getAttributeValue(refElem, "URI");
    this.id = DOMUtils.getAttributeValue(refElem, "Id");

    this.type = DOMUtils.getAttributeValue(refElem, "Type");
    this.here = refElem.getAttributeNodeNS(null, "URI");
    this.refElem = refElem;

    if (transforms.isEmpty()) {
      this.transforms = Collections.EMPTY_LIST;
    } else {
      this.transforms = Collections.unmodifiableList(transforms);
    }
    this.appliedTransforms = Collections.EMPTY_LIST;
    this.allTransforms = transforms;
    this.appliedTransformData = null;
  }
  private void unmarshalParams(Element curXPathElem) throws MarshalException {
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
      String xPath = curXPathElem.getFirstChild().getNodeValue();
      String filterVal = DOMUtils.getAttributeValue(curXPathElem, "Filter");
      if (filterVal == null) {
        throw new MarshalException("filter cannot be null");
      }
      XPathType.Filter filter = null;
      if (filterVal.equals("intersect")) {
        filter = XPathType.Filter.INTERSECT;
      } else if (filterVal.equals("subtract")) {
        filter = XPathType.Filter.SUBTRACT;
      } else if (filterVal.equals("union")) {
        filter = XPathType.Filter.UNION;
      } else {
        throw new MarshalException("Unknown XPathType filter type" + filterVal);
      }
      NamedNodeMap attributes = curXPathElem.getAttributes();
      if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap = new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
          Attr attr = (Attr) attributes.item(i);
          String prefix = attr.getPrefix();
          if (prefix != null && prefix.equals("xmlns")) {
            namespaceMap.put(attr.getLocalName(), attr.getValue());
          }
        }
        list.add(new XPathType(xPath, filter, namespaceMap));
      } else {
        list.add(new XPathType(xPath, filter));
      }

      curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
  }