jdk/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java
changeset 10694 cf59e2badd14
parent 1337 e8d6cef36199
child 13791 059978b7e438
--- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java	Mon Sep 26 11:48:37 2011 -0700
+++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java	Mon Sep 26 17:20:45 2011 -0700
@@ -33,9 +33,12 @@
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.SortedSet;
+import java.util.Collection;
 
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
 
 import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
 import com.sun.org.apache.xml.internal.security.c14n.CanonicalizerSpi;
@@ -94,10 +97,10 @@
     }
    }
 
-   List nodeFilter;
+   List<NodeFilter> nodeFilter;
 
    boolean _includeComments;
-   Set _xpathNodeSet = null;
+   Set<Node> _xpathNodeSet = null;
    /**
     * The node to be skiped/excluded from the DOM tree
     * in subtree canonicalizations.
@@ -130,7 +133,7 @@
     * @param xpathNodeSet
     * @throws CanonicalizationException
     */
-   public byte[] engineCanonicalizeXPathNodeSet(Set xpathNodeSet)
+   public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet)
            throws CanonicalizationException {
            this._xpathNodeSet = xpathNodeSet;
            return engineCanonicalizeXPathNodeSetInternal(XMLUtils.getOwnerDocument(this._xpathNodeSet));
@@ -251,7 +254,7 @@
         final OutputStream writer=this._writer;
         final Node excludeNode=this._excludeNode;
         final boolean includeComments=this._includeComments;
-        Map cache=new HashMap();
+        Map<String, byte[]> cache=new HashMap<String, byte[]>();
         do {
                 switch (currentNode.getNodeType()) {
 
@@ -298,11 +301,11 @@
                         String name=currentElement.getTagName();
                         UtfHelpper.writeByte(name,writer,cache);
 
-                        Iterator attrs = this.handleAttributesSubtree(currentElement,ns);
+                        Iterator<Attr> attrs = this.handleAttributesSubtree(currentElement,ns);
                         if (attrs!=null) {
                                 //we output all Attrs which are available
                                 while (attrs.hasNext()) {
-                                        Attr attr = (Attr) attrs.next();
+                                        Attr attr = attrs.next();
                                         outputAttrToWriter(attr.getNodeName(),attr.getNodeValue(), writer,cache);
                                 }
                         }
@@ -394,7 +397,7 @@
         Node parentNode=null;
         OutputStream writer=this._writer;
         int documentLevel=NODE_BEFORE_DOCUMENT_ELEMENT;
-        Map cache=new HashMap();
+        Map<String, byte[]> cache=new HashMap<String,byte[]>();
         do {
                 switch (currentNode.getNodeType()) {
 
@@ -464,11 +467,11 @@
                                 ns.push();
                         }
 
-                        Iterator attrs = handleAttributes(currentElement,ns);
+                        Iterator<Attr> attrs = handleAttributes(currentElement,ns);
                         if (attrs!=null) {
                                 //we output all Attrs which are available
                                 while (attrs.hasNext()) {
-                                        Attr attr = (Attr) attrs.next();
+                                        Attr attr = attrs.next();
                                         outputAttrToWriter(attr.getNodeName(),attr.getNodeValue(), writer,cache);
                                 }
                         }
@@ -522,9 +525,9 @@
    }
    int isVisibleDO(Node currentNode,int level) {
            if (nodeFilter!=null) {
-                        Iterator it=nodeFilter.iterator();
+                        Iterator<NodeFilter> it=nodeFilter.iterator();
                         while (it.hasNext()) {
-                                int i=((NodeFilter)it.next()).isNodeIncludeDO(currentNode,level);
+                                int i=(it.next()).isNodeIncludeDO(currentNode,level);
                                 if (i!=1)
                                         return i;
                         }
@@ -535,9 +538,9 @@
    }
    int isVisibleInt(Node currentNode) {
            if (nodeFilter!=null) {
-                Iterator it=nodeFilter.iterator();
+                Iterator<NodeFilter> it=nodeFilter.iterator();
                 while (it.hasNext()) {
-                        int i=((NodeFilter)it.next()).isNodeInclude(currentNode);
+                        int i=(it.next()).isNodeInclude(currentNode);
                         if (i!=1)
                                 return i;
                 }
@@ -549,9 +552,9 @@
 
    boolean isVisible(Node currentNode) {
            if (nodeFilter!=null) {
-                Iterator it=nodeFilter.iterator();
+                Iterator<NodeFilter> it=nodeFilter.iterator();
                 while (it.hasNext()) {
-                        if (((NodeFilter)it.next()).isNodeInclude(currentNode)!=1)
+                        if ((it.next()).isNodeInclude(currentNode)!=1)
                                 return false;
                 }
            }
@@ -589,7 +592,7 @@
          * @param ns
          */
         final void getParentNameSpaces(Element el,NameSpaceSymbTable ns)  {
-                List parents=new ArrayList(10);
+                List<Element> parents=new ArrayList<Element>(10);
                 Node n1=el.getParentNode();
                 if (!(n1 instanceof Element)) {
                         return;
@@ -605,9 +608,9 @@
                         parent=(Element)n;
                 }
                 //Visit them in reverse order.
-                ListIterator it=parents.listIterator(parents.size());
+                ListIterator<Element> it=parents.listIterator(parents.size());
                 while (it.hasPrevious()) {
-                        Element ele=(Element)it.previous();
+                        Element ele=it.previous();
                         handleParent(ele, ns);
         }
         Attr nsprefix;
@@ -624,7 +627,7 @@
         * @return the attributes nodes to output.
     * @throws CanonicalizationException
     */
-   abstract Iterator handleAttributes(Element E, NameSpaceSymbTable ns )
+   abstract Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns )
    throws CanonicalizationException;
 
    /**
@@ -635,7 +638,7 @@
         * @return the attributes nodes to output.
     * @throws CanonicalizationException
     */
-   abstract Iterator handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
+   abstract Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
    throws CanonicalizationException;
 
    abstract void circumventBugIfNeeded(XMLSignatureInput input) throws CanonicalizationException, ParserConfigurationException, IOException, SAXException;
@@ -660,7 +663,7 @@
             * @throws IOException
             */
            static final void outputAttrToWriter(final String name, final String value, final OutputStream writer,
-                                final Map cache) throws IOException {
+                                final Map<String, byte[]> cache) throws IOException {
               writer.write(' ');
               UtfHelpper.writeByte(name,writer,cache);
               writer.write(equalsStr);
@@ -841,4 +844,10 @@
               }
            }
 
+    @SuppressWarnings("unchecked")
+    protected Collection<Attr> getSortedSetAsCollection(SortedSet<Attr> result) {
+        return (Collection<Attr>)(Collection)result;
+    }
+
+
 }