< prev index next >

src/java.xml/share/classes/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java

Print this page

        

@@ -33,22 +33,20 @@
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;
 import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Random;
 import java.util.Vector;
 import java.util.Set;
 import java.util.Iterator;
 
 import javax.xml.XMLConstants;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.stream.StreamResult;
 
 import com.sun.org.apache.xerces.internal.impl.Constants;
 import com.sun.org.apache.xerces.internal.impl.PropertyManager;
 import com.sun.org.apache.xerces.internal.util.NamespaceSupport;

@@ -69,11 +67,12 @@
  * @author Neeraj Bajaj
  * @author K.Venugopal
  * @author Santiago.Pericas-Geertsen@sun.com
  * @author Sunitha.Reddy@sun.com
  */
-public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamWriterBase {
+public final class XMLStreamWriterImpl extends AbstractMap<Object, Object>
+        implements XMLStreamWriterBase {
 
     public static final String START_COMMENT = "<!--";
     public static final String END_COMMENT = "-->";
     public static final String DEFAULT_ENCODING = " encoding=\"utf-8\"";
     public static final String DEFAULT_XMLDECL = "<?xml version=\"1.0\" ?>";

@@ -113,16 +112,16 @@
     private OutputStream fOutputStream = null;
 
     /**
      * Collects attributes when the writer is in reparing mode.
      */
-    private ArrayList fAttributeCache;
+    private ArrayList<Attribute> fAttributeCache;
 
     /**
      * Collects namespace declarations when the writer is in reparing mode.
      */
-    private ArrayList fNamespaceDecls;
+    private ArrayList<QName> fNamespaceDecls;
 
     /**
      * Namespace context encapsulating user specified context
      * and context built by the writer
      */

@@ -151,11 +150,11 @@
 
     private ElementStack fElementStack = new ElementStack(); //Change this .-Venu
 
     final private String DEFAULT_PREFIX = fSymbolTable.addSymbol("");
 
-    private final ReadOnlyIterator fReadOnlyIterator = new ReadOnlyIterator();
+    private final ReadOnlyIterator<String> fReadOnlyIterator = new ReadOnlyIterator<>();
 
     /**
      * In some cases, this charset encoder is used to determine if a char is
      * encodable by underlying writer. For example, an 8-bit char from the
      * extended ASCII set is not encodable by 7-bit ASCII encoder. Unencodable

@@ -166,11 +165,11 @@
      /**
      * This is used to hold the namespace for attributes which happen to have
      * the same uri as the default namespace; It's added to avoid changing the
      * current impl. which has many redundant code for the repair mode
      */
-    HashMap fAttrNamespace = null;
+    HashMap<String, String> fAttrNamespace = null;
 
     /**
      * Creates a new instance of XMLStreamWriterImpl. Uses platform's default
      * encoding.
      *

@@ -228,23 +227,23 @@
      * Initialize an instance of this XMLStreamWriter. Allocate new instances
      * for all the data structures. Set internal flags based on property values.
      */
     private void init() {
         fReuse = false;
-        fNamespaceDecls = new ArrayList();
+        fNamespaceDecls = new ArrayList<>();
         fPrefixGen = new Random();
-        fAttributeCache = new ArrayList();
+        fAttributeCache = new ArrayList<>();
         fInternalNamespaceContext = new NamespaceSupport();
         fInternalNamespaceContext.reset();
         fNamespaceContext = new NamespaceContextImpl();
         fNamespaceContext.internalContext = fInternalNamespaceContext;
 
         // Set internal state based on property values
         Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
-        fIsRepairingNamespace = ob.booleanValue();
+        fIsRepairingNamespace = ob;
         ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS);
-        setEscapeCharacters(ob.booleanValue());
+        setEscapeCharacters(ob);
     }
 
     /**
      * Reset this instance so that it can be re-used. Do not read properties
      * again. The method <code>setOutput(StreamResult, encoding)</code> must

@@ -277,13 +276,13 @@
         fStartTagOpened = false;
         fNamespaceContext.userContext = null;
 
         if (resetProperties) {
             Boolean ob = (Boolean) fPropertyManager.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
-            fIsRepairingNamespace = ob.booleanValue();
+            fIsRepairingNamespace = ob;
             ob = (Boolean) fPropertyManager.getProperty(Constants.ESCAPE_CHARACTERS);
-            setEscapeCharacters(ob.booleanValue());
+            setEscapeCharacters(ob);
         }
     }
 
     /**
      * Use a StreamResult to initialize the output for this XMLStreamWriter. Check

@@ -367,10 +366,11 @@
     }
 
     /**
      * Close this XMLStreamWriter by closing underlying writer.
      */
+    @Override
     public void close() throws XMLStreamException {
         if (fWriter != null) {
             try {
                 //fWriter.close();
                 fWriter.flush();

@@ -390,10 +390,11 @@
     }
 
     /**
      * Flush this XMLStreamWriter by flushin underlying writer.
      */
+    @Override
     public void flush() throws XMLStreamException {
         try {
             fWriter.flush();
         } catch (IOException e) {
             throw new XMLStreamException(e);

@@ -403,10 +404,11 @@
     /**
      * Return <code>NamespaceContext</code> being used by the writer.
      *
      * @return NamespaceContext
      */
+    @Override
     public NamespaceContext getNamespaceContext() {
         return fNamespaceContext;
     }
 
     /**

@@ -414,10 +416,11 @@
      * uri is unknown.
      *
      * @param  uri The namespace uri
      * @throws XMLStreamException if uri specified is "" or null
      */
+    @Override
     public String getPrefix(String uri) throws XMLStreamException {
         return fNamespaceContext.getPrefix(uri);
     }
 
     /**

@@ -425,10 +428,11 @@
      *
      * @param  str Property name
      * @throws IllegalArgumentException if the specified property is not supported
      * @return value associated with the specified property.
      */
+    @Override
     public Object getProperty(String str)
         throws IllegalArgumentException {
         if (str == null) {
             throw new NullPointerException();
         }

@@ -444,10 +448,11 @@
     /**
      * Set the specified URI as default namespace in the current namespace context.
      *
      * @param uri Namespace URI
      */
+    @Override
     public void setDefaultNamespace(String uri) throws XMLStreamException {
         if (uri != null) {
             uri = fSymbolTable.addSymbol(uri);
         }
 

@@ -477,10 +482,11 @@
      * <code>XMLStreamWriter</code>.
      *
      * @param namespaceContext the namespace context to use for this writer, may not be null
      * @throws XMLStreamException
      */
+    @Override
     public void setNamespaceContext(NamespaceContext namespaceContext)
         throws XMLStreamException {
         fNamespaceContext.userContext = namespaceContext;
     }
 

@@ -491,10 +497,11 @@
      *
      * @param prefix
      * @param uri
      * @throws XMLStreamException
      */
+    @Override
     public void setPrefix(String prefix, String uri) throws XMLStreamException {
 
         if (prefix == null) {
             throw new XMLStreamException("Prefix cannot be null");
         }

@@ -523,10 +530,11 @@
         }
 
         fInternalNamespaceContext.declarePrefix(prefix, uri);
     }
 
+    @Override
     public void writeAttribute(String localName, String value)
         throws XMLStreamException {
         try {
             if (!fStartTagOpened) {
                 throw new XMLStreamException(

@@ -552,10 +560,11 @@
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
     }
 
+    @Override
     public void writeAttribute(String namespaceURI, String localName,
         String value) throws XMLStreamException {
         try {
             if (!fStartTagOpened) {
                 throw new XMLStreamException(

@@ -588,11 +597,11 @@
 
     private void writeAttributeWithPrefix(String prefix, String localName,
         String value) throws IOException {
         fWriter.write(SPACE);
 
-        if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) {
+        if ((prefix != null) && (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))) {
             fWriter.write(prefix);
             fWriter.write(":");
         }
 
         fWriter.write(localName);

@@ -601,10 +610,11 @@
                 true,   // true = escapeChars
                 true);  // true = escapeDoubleQuotes
         fWriter.write("\"");
     }
 
+    @Override
     public void writeAttribute(String prefix, String namespaceURI,
         String localName, String value) throws XMLStreamException {
         try {
             if (!fStartTagOpened) {
                 throw new XMLStreamException(

@@ -627,11 +637,12 @@
                         writeAttributeWithPrefix(null, localName, value);
                         return;
                     }
                 }
 
-                if (!prefix.equals(XMLConstants.XML_NS_PREFIX) || !namespaceURI.equals(XMLConstants.XML_NS_URI)) {
+                if (!prefix.equals(XMLConstants.XML_NS_PREFIX) ||
+                        !namespaceURI.equals(XMLConstants.XML_NS_URI)) {
 
                     prefix = fSymbolTable.addSymbol(prefix);
                     namespaceURI = fSymbolTable.addSymbol(namespaceURI);
 
                     if (fInternalNamespaceContext.containsPrefixInCurrentContext(prefix)){

@@ -661,10 +672,11 @@
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
     }
 
+    @Override
     public void writeCData(String cdata) throws XMLStreamException {
         try {
             if (cdata == null) {
                 throw new XMLStreamException("cdata cannot be null");
             }

@@ -679,10 +691,11 @@
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
     }
 
+    @Override
     public void writeCharacters(String data) throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();
             }

@@ -691,10 +704,11 @@
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
     }
 
+    @Override
     public void writeCharacters(char[] data, int start, int len)
         throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();

@@ -704,10 +718,11 @@
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
     }
 
+    @Override
     public void writeComment(String comment) throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();
             }

@@ -722,10 +737,11 @@
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
     }
 
+    @Override
     public void writeDTD(String dtd) throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();
             }

@@ -748,15 +764,16 @@
      * @throws XMLStreamException
      *
      * @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting">
      *   Namespaces in XML, 5.2 Namespace Defaulting</a>
      */
+    @Override
     public void writeDefaultNamespace(String namespaceURI)
         throws XMLStreamException {
 
         // normalize namespaceURI
-        String namespaceURINormalized = null;
+        String namespaceURINormalized;
         if (namespaceURI == null) {
             namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI
         } else {
             namespaceURINormalized = namespaceURI;
         }

@@ -780,11 +797,11 @@
 
             if (fInternalNamespaceContext.containsPrefixInCurrentContext("")){
 
                 String tmp = fInternalNamespaceContext.getURI("");
 
-                if (tmp != null && tmp != namespaceURINormalized) {
+                if (tmp != null && !tmp.equals(namespaceURINormalized)) {
                         throw new XMLStreamException(
                                 "xmlns has been already bound to " +tmp +
                                 ". Rebinding it to "+ namespaceURINormalized +
                                 " is an error");
                     }

@@ -796,10 +813,11 @@
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
     }
 
+    @Override
     public void writeEmptyElement(String localName) throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();
             }

@@ -814,10 +832,11 @@
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
     }
 
+    @Override
     public void writeEmptyElement(String namespaceURI, String localName)
         throws XMLStreamException {
         if (namespaceURI == null) {
             throw new XMLStreamException("NamespaceURI cannot be null");
         }

@@ -826,10 +845,11 @@
 
         String prefix = fNamespaceContext.getPrefix(namespaceURI);
         writeEmptyElement(prefix, localName, namespaceURI);
     }
 
+    @Override
     public void writeEmptyElement(String prefix, String localName,
         String namespaceURI) throws XMLStreamException {
         try {
             if (localName == null) {
                 throw new XMLStreamException("Local Name cannot be null");

@@ -861,31 +881,30 @@
                 }
             } else {
                 return;
             }
 
-            if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) {
+            if ((prefix != null) && (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))) {
                 fWriter.write(prefix);
                 fWriter.write(":");
             }
 
             fWriter.write(localName);
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
     }
 
+    @Override
     public void writeEndDocument() throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();
             }
 
-            ElementState elem = null;
-
             while (!fElementStack.empty()) {
-                elem = (ElementState) fElementStack.pop();
+                ElementState elem = fElementStack.pop();
                 fInternalNamespaceContext.popContext();
 
                 if (elem.isEmpty) {
                     //fWriter.write(CLOSE_EMPTY_ELEMENT);
                 } else {

@@ -905,17 +924,18 @@
         } catch (ArrayIndexOutOfBoundsException e) {
             throw new XMLStreamException("No more elements to write");
         }
     }
 
+    @Override
     public void writeEndElement() throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();
             }
 
-            ElementState currentElement = (ElementState) fElementStack.pop();
+            ElementState currentElement = fElementStack.pop();
 
             if (currentElement == null) {
                 throw new XMLStreamException("No element was found to write");
             }
 

@@ -942,10 +962,11 @@
                     "No element was found to write: "
                     + e.toString(), e);
         }
     }
 
+    @Override
     public void writeEntityRef(String refName) throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();
             }

@@ -971,23 +992,24 @@
      * @throws XMLStreamException
      *
      * @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting">
      *   Namespaces in XML, 5.2 Namespace Defaulting</a>
      */
+    @Override
     public void writeNamespace(String prefix, String namespaceURI)
         throws XMLStreamException {
 
         // normalize namespaceURI
-        String namespaceURINormalized = null;
+        String namespaceURINormalized;
         if (namespaceURI == null) {
             namespaceURINormalized = ""; // XMLConstants.NULL_NS_URI
         } else {
             namespaceURINormalized = namespaceURI;
         }
 
         try {
-            QName qname = null;
+            QName qname;
 
             if (!fStartTagOpened) {
                 throw new IllegalStateException(
                         "Invalid state: start tag is not opened at writeNamespace("
                         + prefix

@@ -1011,11 +1033,11 @@
             namespaceURINormalized = fSymbolTable.addSymbol(namespaceURINormalized);
 
             if (fIsRepairingNamespace) {
                 String tmpURI = fInternalNamespaceContext.getURI(prefix);
 
-                if ((tmpURI != null) && (tmpURI == namespaceURINormalized)) {
+                if ((tmpURI != null) && (tmpURI.equals(namespaceURINormalized))) {
                     return;
                 }
 
                 qname = new QName();
                 qname.setValues(prefix, XMLConstants.XMLNS_ATTRIBUTE, null,

@@ -1028,11 +1050,11 @@
 
             if (fInternalNamespaceContext.containsPrefixInCurrentContext(prefix)){
 
                 String tmp = fInternalNamespaceContext.getURI(prefix);
 
-                if (tmp != null && tmp != namespaceURINormalized) {
+                if (tmp != null && !tmp.equals(namespaceURINormalized)) {
 
                        throw new XMLStreamException("prefix "+prefix+
                             " has been already bound to " +tmp +
                             ". Rebinding it to "+ namespaceURINormalized+
                             " is an error");

@@ -1049,11 +1071,11 @@
 
     private void writenamespace(String prefix, String namespaceURI)
         throws IOException {
         fWriter.write(" xmlns");
 
-        if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) {
+        if ((prefix != null) && (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX))) {
             fWriter.write(":");
             fWriter.write(prefix);
         }
 
         fWriter.write("=\"");

@@ -1062,10 +1084,11 @@
                 true,   // true = escapeChars
                 true);  // true = escapeDoubleQuotes
         fWriter.write("\"");
     }
 
+    @Override
     public void writeProcessingInstruction(String target)
         throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();

@@ -1088,10 +1111,11 @@
     /**
      * @param target
      * @param data
      * @throws XMLStreamException
      */
+    @Override
     public void writeProcessingInstruction(String target, String data)
         throws XMLStreamException {
         try {
             if (fStartTagOpened) {
                 closeStartTag();

@@ -1114,20 +1138,22 @@
     /**
      * Writes the XML declaration.
      *
      * @throws XMLStreamException in case of an IOException
      */
+    @Override
     public void writeStartDocument() throws XMLStreamException {
         writeStartDocument(null, null, false, false);
     }
 
     /**
      * Writes the XML declaration.
      *
      * @param version the specified version
      * @throws XMLStreamException in case of an IOException
      */
+    @Override
     public void writeStartDocument(String version) throws XMLStreamException {
         writeStartDocument(null, version, false, false);
     }
 
     /**

@@ -1141,11 +1167,10 @@
     public void writeStartDocument(String encoding, String version)
         throws XMLStreamException {
         writeStartDocument(encoding, version, false, false);
     }
 
-    @Override
     public void writeStartDocument(String encoding, String version,
             boolean standalone, boolean standaloneSet)
         throws XMLStreamException {
 
         try {

@@ -1210,13 +1235,13 @@
         }
 
         if (streamEncoding != null && !streamEncoding.equalsIgnoreCase(encoding)) {
             // If the equality check failed, check for charset encoding aliases
             boolean foundAlias = false;
-            Set aliases = Charset.forName(encoding).aliases();
-            for (Iterator it = aliases.iterator(); !foundAlias && it.hasNext(); ) {
-                if (streamEncoding.equalsIgnoreCase((String) it.next())) {
+            Set<String> aliases = Charset.forName(encoding).aliases();
+            for (Iterator<String> it = aliases.iterator(); !foundAlias && it.hasNext(); ) {
+                if (streamEncoding.equalsIgnoreCase(it.next())) {
                     foundAlias = true;
                 }
             }
             // If no alias matches the encoding name, then report error
             if (!foundAlias) {

@@ -1230,10 +1255,11 @@
 
     /**
      * @param localName
      * @throws XMLStreamException
      */
+    @Override
     public void writeStartElement(String localName) throws XMLStreamException {
         try {
             if (localName == null) {
                 throw new XMLStreamException("Local Name cannot be null");
             }

@@ -1259,10 +1285,11 @@
     /**
      * @param namespaceURI
      * @param localName
      * @throws XMLStreamException
      */
+    @Override
     public void writeStartElement(String namespaceURI, String localName)
         throws XMLStreamException {
         if (localName == null) {
             throw new XMLStreamException("Local Name cannot be null");
         }

@@ -1290,10 +1317,11 @@
      * @param prefix
      * @param localName
      * @param namespaceURI
      * @throws XMLStreamException
      */
+    @Override
     public void writeStartElement(String prefix, String localName,
         String namespaceURI) throws XMLStreamException {
         try {
             if (localName == null) {
                 throw new XMLStreamException("Local Name cannot be null");

@@ -1535,14 +1563,14 @@
                 }
 
                 fWriter.write(currentElement.localpart);
 
                 int len = fNamespaceDecls.size();
-                QName qname = null;
+                QName qname;
 
                 for (int i = 0; i < len; i++) {
-                    qname = (QName) fNamespaceDecls.get(i);
+                    qname = fNamespaceDecls.get(i);
 
                     if (qname != null) {
                         if (fInternalNamespaceContext.declarePrefix(qname.prefix,
                             qname.uri)) {
                             writenamespace(qname.prefix, qname.uri);

@@ -1550,20 +1578,20 @@
                     }
                 }
 
                 fNamespaceDecls.clear();
 
-                Attribute attr = null;
+                Attribute attr;
 
                 for (int j = 0; j < fAttributeCache.size(); j++) {
-                    attr = (Attribute) fAttributeCache.get(j);
+                    attr = fAttributeCache.get(j);
 
                     if ((attr.prefix != null) && (attr.uri != null)) {
                         if (!attr.prefix.equals("") && !attr.uri.equals("") ) {
                             String tmp = fInternalNamespaceContext.getPrefix(attr.uri);
 
-                            if ((tmp == null) || (tmp != attr.prefix)) {
+                            if ((tmp == null) || (!tmp.equals(attr.prefix))) {
                                 tmp = getAttrPrefix(attr.uri);
                                 if (tmp == null) {
                                     if (fInternalNamespaceContext.declarePrefix(attr.prefix,
                                         attr.uri)) {
                                         writenamespace(attr.prefix, attr.uri);

@@ -1609,42 +1637,42 @@
      *
      * @param uri
      * @return
      */
     private void correctPrefix(QName attr, int type) {
-        String tmpPrefix = null;
+        String tmpPrefix;
         String prefix;
         String uri;
         prefix = attr.prefix;
         uri = attr.uri;
         boolean isSpecialCaseURI = false;
 
-        if (prefix == null || prefix.equals("")) {
+        if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
             if (uri == null) {
                 return;
             }
 
-            if (prefix == XMLConstants.DEFAULT_NS_PREFIX && uri == XMLConstants.DEFAULT_NS_PREFIX)
+            if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix) && uri.equals(XMLConstants.DEFAULT_NS_PREFIX))
                 return;
 
             uri = fSymbolTable.addSymbol(uri);
 
-            QName decl = null;
+            QName decl;
 
             for (int i = 0; i < fNamespaceDecls.size(); i++) {
-                decl = (QName) fNamespaceDecls.get(i);
+                decl = fNamespaceDecls.get(i);
 
-                if ((decl != null) && (decl.uri == attr.uri)) {
+                if ((decl != null) && (decl.uri.equals(attr.uri))) {
                     attr.prefix = decl.prefix;
 
                     return;
                 }
             }
 
             tmpPrefix = fNamespaceContext.getPrefix(uri);
 
-            if (tmpPrefix == XMLConstants.DEFAULT_NS_PREFIX) {
+            if (XMLConstants.DEFAULT_NS_PREFIX.equals(tmpPrefix)) {
                 if (type == XMLStreamConstants.START_ELEMENT) {
                     return;
                 }
                 else if (type == XMLStreamConstants.ATTRIBUTE) {
                     //the uri happens to be the same as that of the default namespace

@@ -1652,11 +1680,11 @@
                     isSpecialCaseURI = true;
                 }
             }
 
             if (tmpPrefix == null) {
-                StringBuffer genPrefix = new StringBuffer("zdef");
+                StringBuilder genPrefix = new StringBuilder("zdef");
 
                 for (int i = 0; i < 1; i++) {
                     genPrefix.append(fPrefixGen.nextInt());
                 }
 

@@ -1685,28 +1713,28 @@
     /**
      * return the prefix if the attribute has an uri the same as that of the default namespace
      */
     private String getAttrPrefix(String uri) {
         if (fAttrNamespace != null) {
-            return (String)fAttrNamespace.get(uri);
+            return fAttrNamespace.get(uri);
         }
         return null;
     }
     private void addAttrNamespace(String prefix, String uri) {
         if (fAttrNamespace == null) {
-            fAttrNamespace = new HashMap();
+            fAttrNamespace = new HashMap<>();
         }
         fAttrNamespace.put(prefix, uri);
     }
     /**
      * @param uri
      * @return
      */
     private boolean isDefaultNamespace(String uri) {
         String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX);
 
-        if (uri == defaultNamespace) {
+        if (uri.equals(defaultNamespace)) {
             return true;
         }
 
         return false;
     }

@@ -1730,17 +1758,17 @@
 
     /**
      * Correct's namespaces  as per requirements of isReparisingNamespace property.
      */
     protected void repair() {
-        Attribute attr = null;
-        Attribute attr2 = null;
+        Attribute attr;
+        Attribute attr2;
         ElementState currentElement = fElementStack.peek();
         removeDuplicateDecls();
 
         for(int i=0 ; i< fAttributeCache.size();i++){
-            attr = (Attribute)fAttributeCache.get(i);
+            attr = fAttributeCache.get(i);
             if((attr.prefix != null && !attr.prefix.equals("")) || (attr.uri != null && !attr.uri.equals(""))) {
                 correctPrefix(currentElement,attr);
             }
         }
 

@@ -1752,25 +1780,25 @@
                 }
             }
         }
 
         for(int i=0 ; i< fAttributeCache.size();i++){
-            attr = (Attribute)fAttributeCache.get(i);
+            attr = fAttributeCache.get(i);
             for(int j=i+1;j<fAttributeCache.size();j++){
-                attr2 = (Attribute)fAttributeCache.get(j);
+                attr2 = fAttributeCache.get(j);
                 if(!"".equals(attr.prefix)&& !"".equals(attr2.prefix)){
                     correctPrefix(attr,attr2);
                 }
             }
         }
 
         repairNamespaceDecl(currentElement);
 
-        int i = 0;
+        int i;
 
         for (i = 0; i < fAttributeCache.size(); i++) {
-            attr = (Attribute) fAttributeCache.get(i);
+            attr = fAttributeCache.get(i);
             /* If 'attr' is an attribute and it is in no namespace(which means that prefix="", uri=""), attr's
                namespace should not be redinded. See [http://www.w3.org/TR/REC-xml-names/#defaulting].
              */
             if (attr.prefix != null && attr.prefix.equals("") && attr.uri != null && attr.uri.equals("")){
                 repairNamespaceDecl(attr);

@@ -1778,19 +1806,19 @@
         }
 
         QName qname = null;
 
         for (i = 0; i < fNamespaceDecls.size(); i++) {
-            qname = (QName) fNamespaceDecls.get(i);
+            qname = fNamespaceDecls.get(i);
 
             if (qname != null) {
                 fInternalNamespaceContext.declarePrefix(qname.prefix, qname.uri);
             }
         }
 
         for (i = 0; i < fAttributeCache.size(); i++) {
-            attr = (Attribute) fAttributeCache.get(i);
+            attr = fAttributeCache.get(i);
             correctPrefix(attr, XMLStreamConstants.ATTRIBUTE);
         }
     }
 
     /*

@@ -1799,13 +1827,12 @@
      *the element or the first occurring attribute retains the original prefix
      *and the following attributes have their prefixes replaced with a new prefix
      *that is bound to the namespace URIs of those attributes.
      */
     void correctPrefix(QName attr1, QName attr2) {
-        String tmpPrefix = null;
-        QName decl = null;
-        boolean done = false;
+        String tmpPrefix;
+        QName decl;
 
         checkForNull(attr1);
         checkForNull(attr2);
 
         if(attr1.prefix.equals(attr2.prefix) && !(attr1.uri.equals(attr2.uri))){

@@ -1813,22 +1840,21 @@
             tmpPrefix = fNamespaceContext.getPrefix(attr2.uri);
 
             if (tmpPrefix != null) {
                 attr2.prefix = fSymbolTable.addSymbol(tmpPrefix);
             } else {
-                decl = null;
-                for(int n=0;n<fNamespaceDecls.size();n++){
-                    decl = (QName)fNamespaceDecls.get(n);
-                    if(decl != null && (decl.uri == attr2.uri)){
+                for (int n=0; n<fNamespaceDecls.size(); n++) {
+                    decl = fNamespaceDecls.get(n);
+                    if(decl != null && (decl.uri.equals(attr2.uri))){
                         attr2.prefix = decl.prefix;
 
                         return;
                     }
                 }
 
                 //No namespace mapping found , so declare prefix.
-                StringBuffer genPrefix = new StringBuffer("zdef");
+                StringBuilder genPrefix = new StringBuilder("zdef");
 
                 for (int k = 0; k < 1; k++) {
                     genPrefix.append(fPrefixGen.nextInt());
                 }
 

@@ -1849,15 +1875,15 @@
         if (attr.uri == null) attr.uri = XMLConstants.DEFAULT_NS_PREFIX;
     }
 
     void removeDuplicateDecls(){
         QName decl1,decl2;
-        for(int i =0;i<fNamespaceDecls.size();i++){
-            decl1 = (QName)fNamespaceDecls.get(i);
+        for(int i =0; i<fNamespaceDecls.size(); i++) {
+            decl1 = fNamespaceDecls.get(i);
             if(decl1!=null) {
                 for(int j=i+1;j<fNamespaceDecls.size();j++){
-                    decl2 = (QName)fNamespaceDecls.get(j);
+                    decl2 = fNamespaceDecls.get(j);
                     // QName.equals relies on identity equality, so we can't use it,
                     // because prefixes aren't interned
                     if(decl2!=null && decl1.prefix.equals(decl2.prefix) && decl1.uri.equals(decl2.uri))
                         fNamespaceDecls.remove(j);
                 }

@@ -1871,16 +1897,16 @@
      *is either removed if the correct mapping is inherited from the parent context of that element,
      *or changed to the namespace URI of the element or attribute using that prefix.
      *
      */
     void repairNamespaceDecl(QName attr) {
-        QName decl = null;
+        QName decl;
         String tmpURI;
 
         //check for null prefix.
         for (int j = 0; j < fNamespaceDecls.size(); j++) {
-            decl = (QName) fNamespaceDecls.get(j);
+            decl = fNamespaceDecls.get(j);
 
             if (decl != null) {
                 if ((attr.prefix != null) &&
                         (attr.prefix.equals(decl.prefix) &&
                         !(attr.uri.equals(decl.uri)))) {

@@ -1898,17 +1924,17 @@
             }
         }
     }
 
     boolean isDeclared(QName attr) {
-        QName decl = null;
+        QName decl;
 
         for (int n = 0; n < fNamespaceDecls.size(); n++) {
-            decl = (QName) fNamespaceDecls.get(n);
+            decl = fNamespaceDecls.get(n);
 
             if ((attr.prefix != null) &&
-                    ((attr.prefix == decl.prefix) && (decl.uri == attr.uri))) {
+                    ((attr.prefix.equals(decl.prefix)) && (decl.uri.equals(attr.uri)))) {
                 return true;
             }
         }
 
         if (attr.uri != null) {

@@ -2119,13 +2145,14 @@
             }
 
             return null;
         }
 
-        public java.util.Iterator getPrefixes(String uri) {
+        //Cleanup note: leaving these warnings to a xerces.internal.util cleanup
+        public Iterator<String> getPrefixes(String uri) {
             Vector prefixes = null;
-            Iterator itr = null;
+            Iterator<String> itr = null;
 
             if (uri != null) {
                 uri = fSymbolTable.addSymbol(uri);
             }
 

@@ -2138,82 +2165,90 @@
             }
 
             if ((prefixes == null) && (itr != null)) {
                 return itr;
             } else if ((prefixes != null) && (itr == null)) {
-                return new ReadOnlyIterator(prefixes.iterator());
+                return new ReadOnlyIterator<>(prefixes.iterator());
             } else if ((prefixes != null) && (itr != null)) {
                 String ob = null;
 
                 while (itr.hasNext()) {
-                    ob = (String) itr.next();
+                    ob = itr.next();
 
                     if (ob != null) {
                         ob = fSymbolTable.addSymbol(ob);
                     }
 
                     if (!prefixes.contains(ob)) {
                         prefixes.add(ob);
                     }
                 }
 
-                return new ReadOnlyIterator(prefixes.iterator());
+                return new ReadOnlyIterator<>(prefixes.iterator());
             }
 
             return fReadOnlyIterator;
         }
     }
 
     // -- Map Interface --------------------------------------------------
 
+    @Override
     public int size() {
         return 1;
     }
 
+    @Override
     public boolean isEmpty() {
         return false;
     }
 
+    @Override
     public boolean containsKey(Object key) {
         return key.equals(OUTPUTSTREAM_PROPERTY);
     }
 
     /**
      * Returns the value associated to an implementation-specific
      * property.
      */
+    @Override
     public Object get(Object key) {
         if (key.equals(OUTPUTSTREAM_PROPERTY)) {
             return fOutputStream;
         }
         return null;
     }
 
-    public java.util.Set entrySet() {
+    @Override
+    public Set<Entry<Object,Object>> entrySet() {
         throw new UnsupportedOperationException();
     }
 
     /**
      * Overrides the method defined in AbstractMap which is
      * not completely implemented. Calling toString() in
      * AbstractMap would cause an unsupported exection to
      * be thrown.
      */
+    @Override
     public String toString() {
         return getClass().getName() + "@" + Integer.toHexString(hashCode());
     }
 
     /**
      * Overrides the method defined in AbstractMap
      * This is required by the toString() method
      */
+    @Override
     public int hashCode() {
         return fElementStack.hashCode();
     }
     /**
      * Overrides the method defined in AbstractMap
      * This is required to satisfy the contract for hashCode.
      */
+    @Override
     public boolean equals(Object obj) {
         return (this == obj);
     }
 }
< prev index next >