OSDN Git Service

git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@3575 ae02f08e...
authorleo <leo@ae02f08e-27ec-0310-ae8c-8ba02fe2eafd>
Thu, 10 Sep 2009 06:55:08 +0000 (06:55 +0000)
committerleo <leo@ae02f08e-27ec-0310-ae8c-8ba02fe2eafd>
Thu, 10 Sep 2009 06:55:08 +0000 (06:55 +0000)
src/main/java/org/xerial/core/XerialException.java
src/main/java/org/xerial/json/JSONException.java
src/main/java/org/xerial/util/opt/OptionParser.java
src/test/java/org/xerial/core/XerialExceptionTest.java
src/test/java/org/xerial/util/bean/TypeReferenceTest.java

index 1d32a1d..da654d6 100644 (file)
@@ -38,11 +38,12 @@ import org.xerial.json.JSONErrorCode;
  * @author leo
  * 
  */
-public class XerialException extends Exception {
+public class XerialException extends Exception
+{
 
     private static final long serialVersionUID = 1L;
 
-    private final ErrorCode errorCode;
+    protected final ErrorCode errorCode;
 
     public XerialException(XerialException e) {
         super(e.getErrorMessage());
@@ -69,23 +70,9 @@ public class XerialException extends Exception {
         this.errorCode = errorCode;
     }
 
-    public ErrorCode getErrorCode() {
-        return errorCode;
-    }
-
-    private boolean hasXerialErrorCode() {
-        return XerialErrorCode.class.isInstance(errorCode);
-    }
-
-    public XerialErrorCode getXerialErrorCode() {
-        if (hasXerialErrorCode())
-            return XerialErrorCode.class.cast(errorCode);
-        else
-            return XerialErrorCode.HAS_AN_EXTENDED_ERROR_CODE;
-    }
-
-    public <T extends Enum<T>> T getErrorCodeOfTheType(Class<T> errorCodeType) {
-        return errorCodeType.cast(errorCode);
+    @SuppressWarnings("unchecked")
+    public <T> T getErrorCode() {
+        return (T) errorCode;
     }
 
     @Override
index d821f19..f7f4675 100644 (file)
@@ -32,7 +32,8 @@ import org.xerial.core.XerialException;
  * @author leo\r
  * \r
  */\r
-public class JSONException extends XerialException {\r
+public class JSONException extends XerialException\r
+{\r
     private static final long serialVersionUID = 1L;\r
 \r
     /**\r
@@ -68,7 +69,8 @@ public class JSONException extends XerialException {
      * \r
      * @return the error code\r
      */\r
+    @SuppressWarnings("unchecked")\r
     public JSONErrorCode getErrorCode() {\r
-        return (JSONErrorCode) super.getErrorCode();\r
+        return JSONErrorCode.class.cast(errorCode);\r
     }\r
 }\r
index 06133e6..548094e 100644 (file)
@@ -277,13 +277,13 @@ public class OptionParser
             item.setOption(optionHolder, value);
         }
         catch (XerialException e) {
-            XerialErrorCode be = e.getXerialErrorCode();
+            XerialErrorCode be = e.getErrorCode();
             switch (be) {
             case InvalidFormat:
                 throw new OptionParserException(XerialErrorCode.INVALID_ARGUMENT, String.format("cannot set %s to %s",
                         value, item.toString()));
             default:
-                throw new OptionParserException(e.getErrorCode(), e.getMessage());
+                throw new OptionParserException(e.<XerialErrorCode> getErrorCode(), e.getMessage());
             }
         }
     }
index 7046c76..2bdf21e 100644 (file)
@@ -24,8 +24,7 @@
 //--------------------------------------
 package org.xerial.core;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 import org.junit.Test;
 
@@ -37,10 +36,9 @@ public class XerialExceptionTest
 {
 
     @Test
-    public void testVarArgConstructor()
-    {
+    public void testVarArgConstructor() {
         XerialException e = new XerialException(XerialErrorCode.INVALID_STATE, "exception message");
-        assertEquals(XerialErrorCode.INVALID_STATE.name(), e.getErrorCode().getCodeName());
+        assertEquals(XerialErrorCode.INVALID_STATE.name(), e.<XerialErrorCode> getErrorCode().getCodeName());
 
         assertTrue(e.getMessage().contains("exception message"));
     }
index 00d0666..8905120 100644 (file)
@@ -35,8 +35,8 @@ import org.xerial.core.XerialException;
 \r
 public class TypeReferenceTest\r
 {\r
-    @Test\r
-    void reference() {\r
+\r
+    public void reference() {\r
         Type c = new TypeReference<List<String>>() {}.getElementType()[0];\r
         assertEquals(String.class, c);\r
 \r