ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1152849 - /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartFactory.java
Date Mon, 01 Aug 2011 16:00:52 GMT
Author: veithen
Date: Mon Aug  1 16:00:51 2011
New Revision: 1152849

URL: http://svn.apache.org/viewvc?rev=1152849&view=rev
Log:
AXIOM-326: Improved error handling.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartFactory.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartFactory.java?rev=1152849&r1=1152848&r2=1152849&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartFactory.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartFactory.java
Mon Aug  1 16:00:51 2011
@@ -61,6 +61,13 @@ public class PartFactory {
     // Dynamic Threshold = availMemory / THRESHOLD_FACTOR
     private static final int THRESHOLD_FACTOR = 5;
     
+    private static void checkParserState(EntityState expected, EntityState actual) throws
IllegalStateException {
+        if (expected != actual) {
+            throw new IllegalStateException("Internal error: expected parser to be in state
"
+                    + expected + ", but got " + actual);
+        }
+    }
+    
     /**
      * Creates a part from the input stream.
      * The remaining parameters are used to determine if the
@@ -157,9 +164,7 @@ public class PartFactory {
                     }
 
                 } 
-                if (parser.next() != EntityState.T_END_BODYPART) {
-                    throw new IllegalStateException();
-                }
+                checkParserState(parser.next(), EntityState.T_END_BODYPART);
             } finally {
                 if (!isSOAPPart) {
                     synchronized(semifore) {
@@ -187,9 +192,7 @@ public class PartFactory {
             log.debug("initHeaders");
         }
         
-        if (parser.next() != EntityState.T_START_HEADER) {
-            throw new IllegalStateException();
-        }
+        checkParserState(parser.next(), EntityState.T_START_HEADER);
         
         while (parser.next() == EntityState.T_FIELD) {
             Field field = parser.getField();
@@ -206,9 +209,7 @@ public class PartFactory {
             headers.put(key, headerObj);
         }
         
-        if (parser.next() != EntityState.T_BODY) {
-            throw new IllegalStateException();
-        }
+        checkParserState(parser.next(), EntityState.T_BODY);
     }
     
     /**



Mime
View raw message