You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by th...@apache.org on 2012/02/14 12:39:23 UTC

svn commit: r1243883 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: Constants.java util/ExceptionFactory.java wrapper/SecurityWrapper.java

Author: thomasm
Date: Tue Feb 14 11:39:22 2012
New Revision: 1243883

URL: http://svn.apache.org/viewvc?rev=1243883&view=rev
Log:
Include the jar file version in the exception message; remove unused code.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java?rev=1243883&r1=1243882&r2=1243883&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java Tue Feb 14 11:39:22 2012
@@ -20,35 +20,8 @@ package org.apache.jackrabbit.mk;
  * Constants used in this project.
  */
 public class Constants {
-    public static final boolean TYPE_AS_COMMENT = false;
+
     public static final boolean NODE_NAME_AS_PROPERTY = false;
     public static final boolean JSON_NEWLINES = false;
 
-    public static final int VERSION_MAJOR = 3;
-    public static final int VERSION_MINOR = 0;
-    public static final int BUILD = 1000;
-
-    public static final String FULL_VERSION = VERSION_MAJOR + "." + VERSION_MINOR + "." + BUILD;
-
-    public static final int MAX_STORE_RETRY = 3;
-
-    public static final int MAX_CHILD_COUNT = 200;
-
-    public static final int MEM_CACHE_PER_REPOSITORY = 16 * 1024 * 1024;
-    public static final int MEM_CACHE_PER_SESSION = 1024 * 1024;
-    public static final int MEM_MAP_ENTRY = 32;
-    public static final int MEM_EVENT = 64;
-    public static final int MEM_NODE_DATA = 48;
-    public static final int MEM_VAL_LONG = 32;
-    public static final int MEM_VAL_BINARY = 32;
-    public static final int MEM_VAL_STRING = 64;
-    public static final int MEM_VAL_OBJ = 16;
-    public static final int SIZE_EVENT_BUNDLE = 20 * 1024;
-
-    public static final int BUNDLE_MIN_COMPRESS = 3;
-    public static final int JOURNAL_LOAD_SIZE = 16;
-
-    public static final String LOG_UNCLOSED_SESSIONS = "logUnclosedSessions";
-    public static final boolean LOG_UNCLOSED_SESSIONS_DEFAULT = true;
-
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java?rev=1243883&r1=1243882&r2=1243883&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java Tue Feb 14 11:39:22 2012
@@ -16,109 +16,52 @@
  */
 package org.apache.jackrabbit.mk.util;
 
-import org.apache.jackrabbit.mk.Constants;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 
-import java.text.MessageFormat;
-import java.util.ConcurrentModificationException;
-import java.util.HashMap;
-import java.util.NoSuchElementException;
-
 /**
  * An exception factory.
  */
 public class ExceptionFactory {
 
-    public static final int REPOSITORY_ALREADY_OPEN = 1002;
-    static final int CLOSED_0 = 1000;
-    static final int CONCURRENT_UPDATE_1 = 1001;
+    private static final String POM = "META-INF/maven/org.apache.jackrabbit/microkernel/pom.properties";
 
-    static final HashMap<Integer, String> MESSAGE_MAP = new HashMap<Integer, String>();
+    private static String version;
 
     public static MicroKernelException convert(Exception e) {
         if (e instanceof MicroKernelException) {
             return (MicroKernelException) e;
         }
-        return new MicroKernelException(e.getMessage(), e);
+        return new MicroKernelException(e.getMessage() + " " + getVersion(), e);
     }
 
     public static MicroKernelException get(String s) {
-        return new MicroKernelException(s);
-    }
-
-    static {
-        MESSAGE_MAP.put(CLOSED_0, "The repository is closed");
-        MESSAGE_MAP.put(REPOSITORY_ALREADY_OPEN, "The repository is already open");
-    }
-
-    public static int getErrorCode(Exception e) {
-        String message = e.getMessage();
-        int open = message.lastIndexOf('[');
-        int dash = message.lastIndexOf('-');
-        if (dash < 0 || open < 0 || dash < open) {
-            return 0;
-        }
-        return Integer.parseInt(message.substring(open + 1, dash));
-    }
-
-    public static String getMessage(int errorCode, String... params) {
-        String message = MESSAGE_MAP.get(errorCode);
-        message = MessageFormat.format(message, (Object[]) params);
-        return message + " [" + errorCode + "-" + Constants.FULL_VERSION + "]";
-    }
-
-    static String format(String message, Object... params) {
-        if (params != null) {
-            message = MessageFormat.format(message, params);
-        }
-        return message + " [" + Constants.FULL_VERSION + "]";
+        return new MicroKernelException(s + " " + getVersion());
     }
 
-    public static <E extends Exception> E exception(Class<E> e, Throwable cause, String msg, Object... params) throws E {
-        String message;
-        if (params != null && params.length > 0) {
-            message = format(msg, params);
-        } else {
-            message = msg == null ? cause.getMessage() : msg;
+    public static String getVersion() {
+        if (version == null) {
+            try {
+                InputStream in = ExceptionFactory.class.getClassLoader().getResourceAsStream(POM);
+                if (in == null) {
+                    in = new FileInputStream("target/maven-archiver/pom.properties");
+                }
+                if (in == null) {
+                    version = "";
+                } else {
+                    Properties prop = new Properties();
+                    prop.load(in);
+                    in.close();
+                    version = "[" + prop.getProperty("artifactId") + "-" + prop.getProperty("version") + "]";
+                }
+            } catch (IOException e) {
+                version = "";
+            }
         }
-        E i;
-        try {
-            i = e.getConstructor(String.class).newInstance(message);
-        } catch (Exception e1) {
-            throw new RuntimeException("Error building " + e + ": " + message, cause);
-        }
-        if (cause != null) {
-            i.initCause(cause);
-        }
-        throw i;
-    }
-
-    public static UnsupportedOperationException unsupportedOperation() {
-        throw exception(UnsupportedOperationException.class, null, "");
-    }
-
-    public static RuntimeException runtime(Exception e) {
-        throw exception(RuntimeException.class, e, e.getMessage());
-    }
-
-    public static IllegalArgumentException illegalArgument(String message, Object... params) {
-        throw exception(IllegalArgumentException.class, null, message, params);
-    }
-
-    public static IllegalStateException illegalState(String message, Object... params) {
-        throw exception(IllegalStateException.class, null, message, params);
-    }
-
-    public static NullPointerException nullPointer() {
-        throw exception(NullPointerException.class, null, "");
-    }
-
-    public static ConcurrentModificationException concurrentModification() {
-        throw exception(ConcurrentModificationException.class, null, "");
-    }
-
-    public static NoSuchElementException noSuchElement() {
-        throw exception(NoSuchElementException.class, null, "");
+        return version;
     }
 
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java?rev=1243883&r1=1243882&r2=1243883&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java Tue Feb 14 11:39:22 2012
@@ -70,13 +70,13 @@ public class SecurityWrapper extends Wra
         String userPassUrl = url.substring("sec:".length());
         int index = userPassUrl.indexOf(':');
         if (index < 0) {
-            throw new MicroKernelException("Expected url format: sec:user@pass:<url>");
+            throw ExceptionFactory.get("Expected url format: sec:user@pass:<url>");
         }
         String u = userPassUrl.substring(index + 1);
         String userPass = userPassUrl.substring(0, index);
         index = userPass.indexOf('@');
         if (index < 0) {
-            throw new MicroKernelException("Expected url format: sec:user@pass:<url>");
+            throw ExceptionFactory.get("Expected url format: sec:user@pass:<url>");
         }
         String user = userPass.substring(0, index);
         String pass = userPass.substring(index + 1);
@@ -89,7 +89,7 @@ public class SecurityWrapper extends Wra
             NodeImpl n = NodeImpl.parse(map, t, 0);
             String password = JsopTokenizer.decodeQuoted(n.getProperty("password"));
             if (!pass.equals(password)) {
-                throw new MicroKernelException("Wrong password");
+                throw ExceptionFactory.get("Wrong password");
             }
             String rights = JsopTokenizer.decodeQuoted(n.getProperty("rights"));
             return new SecurityWrapper(mk, rights.split(","));