You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2008/09/29 05:53:20 UTC

svn commit: r699978 - in /xerces/java/trunk/src/org/apache/xerces: dom/DOMConfigurationImpl.java parsers/DOMParserImpl.java

Author: mrglavas
Date: Sun Sep 28 20:53:20 2008
New Revision: 699978

URL: http://svn.apache.org/viewvc?rev=699978&view=rev
Log:
Factored out DOMException handling to eliminate a lot of duplicate code.

Modified:
    xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java
    xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java

Modified: xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java?rev=699978&r1=699977&r2=699978&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java Sun Sep 28 20:53:20 2008
@@ -1181,7 +1181,7 @@
                 DOMMessageFormatter.DOM_DOMAIN,
                 "FEATURE_NOT_SUPPORTED",
                 new Object[] { name });
-        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
+        return new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
     }
     
     private static DOMException newFeatureNotFoundError(String name) {
@@ -1190,7 +1190,7 @@
                 DOMMessageFormatter.DOM_DOMAIN,
                 "FEATURE_NOT_FOUND",
                 new Object[] { name });
-        throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+        return new DOMException(DOMException.NOT_FOUND_ERR, msg);
     }
     
     private static DOMException newTypeMismatchError(String name) {

Modified: xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java?rev=699978&r1=699977&r2=699978&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java Sun Sep 28 20:53:20 2008
@@ -140,11 +140,11 @@
 
     protected final static boolean DEBUG = false;
 
-    private Vector fSchemaLocations = new Vector ();
+    private final Vector fSchemaLocations = new Vector();
     private String fSchemaLocation = null;
 	private DOMStringList fRecognizedParameters;
     
-    private AbortHandler abortHandler = new AbortHandler();
+    private final AbortHandler abortHandler = new AbortHandler();
 
     //
     // Constructors
@@ -364,12 +364,7 @@
                 || name.equalsIgnoreCase (Constants.DOM_CHECK_CHAR_NORMALIZATION)
                 || name.equalsIgnoreCase (Constants.DOM_CANONICAL_FORM)) {
                     if (state) { // true is not supported
-                        String msg =
-                        DOMMessageFormatter.formatMessage (
-                        DOMMessageFormatter.DOM_DOMAIN,
-                        "FEATURE_NOT_SUPPORTED",
-                        new Object[] { name });
-                        throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg);
+                        throw newFeatureNotSupportedError(name);
                     }
                     // setting those features to false is no-op
                 }
@@ -403,12 +398,7 @@
                 else if (name.equalsIgnoreCase (Constants.DOM_WELLFORMED)
                 || name.equalsIgnoreCase (Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
                     if (!state) { // false is not supported
-                        String msg =
-                        DOMMessageFormatter.formatMessage (
-                        DOMMessageFormatter.DOM_DOMAIN,
-                        "FEATURE_NOT_SUPPORTED",
-                        new Object[] { name });
-                        throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg);
+                        throw newFeatureNotSupportedError(name);
                     }
                     // setting these features to true is no-op
                     // REVISIT: implement "namespace-declaration" feature
@@ -457,12 +447,7 @@
 
             }
             catch (XMLConfigurationException e) {
-                String msg =
-                DOMMessageFormatter.formatMessage (
-                DOMMessageFormatter.DOM_DOMAIN,
-                "FEATURE_NOT_FOUND",
-                new Object[] { name });
-                throw new DOMException (DOMException.NOT_FOUND_ERR, msg);
+                throw newFeatureNotFoundError(name);
             }
         }
         else { // set properties
@@ -475,13 +460,7 @@
                     catch (XMLConfigurationException e) {}
                 }
                 else {
-                    // REVISIT: type mismatch
-                    String msg =
-                    DOMMessageFormatter.formatMessage (
-                    DOMMessageFormatter.DOM_DOMAIN,
-                    "TYPE_MISMATCH_ERR",
-                    new Object[] { name });
-                    throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
+                    throw newTypeMismatchError(name);
                 }
 
             }
@@ -493,13 +472,7 @@
                     catch (XMLConfigurationException e) {}
                 }
                 else {
-                    // REVISIT: type mismatch
-                    String msg =
-                    DOMMessageFormatter.formatMessage (
-                    DOMMessageFormatter.DOM_DOMAIN,
-                    "TYPE_MISMATCH_ERR",
-                    new Object[] { name });
-                    throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
+                    throw newTypeMismatchError(name);
                 }
 
             }
@@ -537,13 +510,7 @@
                     catch (XMLConfigurationException e) {}
                 }
                 else {
-                    // REVISIT: type mismatch
-                    String msg =
-                    DOMMessageFormatter.formatMessage (
-                    DOMMessageFormatter.DOM_DOMAIN,
-                    "TYPE_MISMATCH_ERR",
-                    new Object[] { name });
-                    throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
+                    throw newTypeMismatchError(name);
                 }
 
             }
@@ -584,12 +551,7 @@
                     catch (XMLConfigurationException e) {}
                 }
                 else {
-                    String msg =
-                    DOMMessageFormatter.formatMessage (
-                    DOMMessageFormatter.DOM_DOMAIN,
-                    "TYPE_MISMATCH_ERR",
-                    new Object[] { name });
-                    throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
+                    throw newTypeMismatchError(name);
                 }
 
             }
@@ -613,23 +575,13 @@
                         normalizedName = HONOUR_ALL_SCHEMALOCATIONS;
                     }
                     fConfiguration.getFeature(normalizedName);
-                    String msg =
-                        DOMMessageFormatter.formatMessage (
-                                DOMMessageFormatter.DOM_DOMAIN,
-                                "TYPE_MISMATCH_ERR",
-                                new Object[] { name });
-                    throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
+                    throw newTypeMismatchError(name);
                     
                 }
                 catch (XMLConfigurationException e) {}
                 
                 // Parameter is not recognized
-                String msg =
-                    DOMMessageFormatter.formatMessage (
-                            DOMMessageFormatter.DOM_DOMAIN,
-                            "FEATURE_NOT_FOUND",
-                            new Object[] { name });
-                throw new DOMException (DOMException.NOT_FOUND_ERR, msg);
+                throw newFeatureNotFoundError(name);
             }
         }
     }
@@ -767,12 +719,7 @@
             }
             catch (XMLConfigurationException e) {}
             
-            String msg =
-                DOMMessageFormatter.formatMessage (
-                        DOMMessageFormatter.DOM_DOMAIN,
-                        "FEATURE_NOT_FOUND",
-                        new Object[] { name });
-            throw new DOMException (DOMException.NOT_FOUND_ERR, msg);
+            throw newFeatureNotFoundError(name);
         }
     }
 
@@ -929,10 +876,7 @@
         //If DOMParser insstance is already busy parsing another document when this
         // method is called, then raise INVALID_STATE_ERR according to DOM L3 LS spec
         if ( fBusy ) {
-            String msg = DOMMessageFormatter.formatMessage (
-            DOMMessageFormatter.DOM_DOMAIN,
-            "INVALID_STATE_ERR",null);
-            throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
+            throw newInvalidStateError();
         }
 
         XMLInputSource source = new XMLInputSource (null, uri, null);
@@ -987,10 +931,7 @@
         // need to wrap the LSInput with an XMLInputSource
         XMLInputSource xmlInputSource = dom2xmlInputSource (is);
         if ( fBusy ) {
-            String msg = DOMMessageFormatter.formatMessage (
-            DOMMessageFormatter.DOM_DOMAIN,
-            "INVALID_STATE_ERR",null);
-            throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
+            throw newInvalidStateError();
         }
 
         try {
@@ -1377,8 +1318,42 @@
 
         public XMLDTDContentModelSource getDTDContentModelSource() {
             return dtdContentSource;
-        }
-        
+        }  
+    }
+    
+    private static DOMException newInvalidStateError() {
+        String msg = 
+            DOMMessageFormatter.formatMessage (
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "INVALID_STATE_ERR", null);
+        throw new DOMException ( DOMException.INVALID_STATE_ERR, msg);
+    }
+    
+    private static DOMException newFeatureNotSupportedError(String name) {
+        String msg =
+            DOMMessageFormatter.formatMessage (
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "FEATURE_NOT_SUPPORTED",
+                    new Object[] { name });
+        return new DOMException (DOMException.NOT_SUPPORTED_ERR, msg);
+    }
+    
+    private static DOMException newFeatureNotFoundError(String name) {
+        String msg =
+            DOMMessageFormatter.formatMessage (
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "FEATURE_NOT_FOUND",
+                    new Object[] { name });
+        return new DOMException (DOMException.NOT_FOUND_ERR, msg);
+    }
+    
+    private static DOMException newTypeMismatchError(String name) {
+        String msg =
+            DOMMessageFormatter.formatMessage (
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "TYPE_MISMATCH_ERR",
+                    new Object[] { name });
+        return new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
     }
 	
 } // class DOMParserImpl



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org