svn commit: r564998 - in /xml/xindice/trunk/java/src/org/apache/xindice: client/xmldb/embed/ core/ core/query/ server/ util/

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: vgritsenko
Date: Sat Aug 11 19:51:49 2007
New Revision: 564998

URL: http://svn.apache.org/viewvc?view=rev&rev=564998
Log:
remove ConfigurationException.
cleanup XindiceException, XindiceRuntimeException.
servlet should use ServletException.
DBException.faultCode should be final (since it's public)

Removed:
    xml/xindice/trunk/java/src/org/apache/xindice/util/ConfigurationException.java
Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/DBException.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/query/TextQueryResolver.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
    xml/xindice/trunk/java/src/org/apache/xindice/server/ManagedServer.java
    xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java
    xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceException.java
    xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceRuntimeException.java

Modified: xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java?view=diff&rev=564998&r1=564997&r2=564998
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java Sat Aug 11 19:51:49 2007
@@ -22,12 +22,14 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.xindice.client.xmldb.CommonConfigurable;
+import org.apache.xindice.core.DBException;
 import org.apache.xindice.core.Database;
+import org.apache.xindice.core.FaultCodes;
 import org.apache.xindice.server.Xindice;
 import org.apache.xindice.util.Configuration;
+import org.apache.xindice.util.ReadOnlyException;
 import org.apache.xindice.util.XindiceException;
 import org.apache.xindice.util.XindiceRuntimeException;
-import org.apache.xindice.util.ReadOnlyException;
 import org.apache.xindice.xml.dom.DOMParser;
 
 import org.xmldb.api.base.Collection;
@@ -36,8 +38,8 @@
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.IOException;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 
 /**
  * Implements XML:DB's <code>Database</code> interface providing embedded access to
@@ -175,7 +177,11 @@
                                          "Database '" + dbName + "' not found: " + uri);
             }
 
-            database = Database.getDatabase(dbConfig);
+            try {
+                database = Database.getDatabase(dbConfig);
+            } catch (DBException e) {
+                throw FaultCodes.createXMLDBException(e);
+            }
             if (log.isDebugEnabled()) {
                 log.info("Mounted database: '" + database.getName() + "'");
             }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/DBException.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/DBException.java?view=diff&rev=564998&r1=564997&r2=564998
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/DBException.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/DBException.java Sat Aug 11 19:51:49 2007
@@ -29,7 +29,7 @@
  * @version $Revision$, $Date$
  */
 public class DBException extends XindiceException {
-    public int faultCode;
+    public final int faultCode;
 
     public DBException() {
         this(FaultCodes.GEN_UNKNOWN, "", null);

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java?view=diff&rev=564998&r1=564997&r2=564998
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java Sat Aug 11 19:51:49 2007
@@ -24,7 +24,6 @@
 import org.apache.xindice.core.query.QueryEngine;
 import org.apache.xindice.server.Xindice;
 import org.apache.xindice.util.Configuration;
-import org.apache.xindice.util.ConfigurationException;
 import org.apache.xindice.util.Named;
 import org.apache.xindice.util.XindiceException;
 
@@ -78,18 +77,20 @@
     /**
      * This will return an instance of a Database for the given
      * name if one has already been loaded, otherwise it will
-     * create a new instance.
+     * create and load a new database instance.
      *
      * @param config Database configuration
      * @return Database instance
-     * @throws ConfigurationException if database name is missing in the configuration
+     * @throws DBException if database name is missing in the configuration,
+     *                     or unable to load a database.
      */
-    public static Database getDatabase(Configuration config) {
+    public static Database getDatabase(Configuration config) throws DBException {
         String name = config.getAttribute(Database.NAME);
 
         // No name in the config file ... can't get the database
         if (name == null) {
-            throw new ConfigurationException("Database configuration didn't contain a database name");
+            throw new DBException(FaultCodes.DBE_CANNOT_READ,
+                                  "Database configuration didn't contain a database name");
         }
 
         Database database = (Database) databases.get(name);
@@ -103,8 +104,8 @@
                     try {
                         database.setConfig(config);
                     } catch (XindiceException x) {
-                        // TODO: Configurable interface should use ConfigurationException instead of XindiceException... Right?
-                        throw new ConfigurationException("XindiceException: " + x.getMessage(), x);
+                        throw new DBException(FaultCodes.DBE_CANNOT_READ,
+                                              "XindiceException: " + x.getMessage(), x);
                     }
 
                     databases.put(database.getName(), database);

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/query/TextQueryResolver.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/query/TextQueryResolver.java?view=diff&rev=564998&r1=564997&r2=564998
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/query/TextQueryResolver.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/query/TextQueryResolver.java Sat Aug 11 19:51:49 2007
@@ -155,7 +155,7 @@
                 try {
                     prepareNextNode();
                 } catch (Exception e) {
-                    throw new XindiceRuntimeException(e.getMessage());
+                    throw new XindiceRuntimeException(e);
                 }
             }
 

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java?view=diff&rev=564998&r1=564997&r2=564998
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java Sat Aug 11 19:51:49 2007
@@ -1235,7 +1235,7 @@
             try {
                 prepareNextNode();
             } catch (Exception e) {
-                throw new XindiceRuntimeException(e.getMessage());
+                throw new XindiceRuntimeException(e);
             }
         }
 
@@ -1330,7 +1330,7 @@
                 try {
                     prepareNextNode();
                 } catch (Exception e) {
-                    throw new XindiceRuntimeException(e.getMessage());
+                    throw new XindiceRuntimeException(e);
                 }
             }
 

Modified: xml/xindice/trunk/java/src/org/apache/xindice/server/ManagedServer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/server/ManagedServer.java?view=diff&rev=564998&r1=564997&r2=564998
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/server/ManagedServer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/server/ManagedServer.java Sat Aug 11 19:51:49 2007
@@ -77,10 +77,6 @@
      */
     public synchronized void configure() throws IOException, XindiceException {
         db = Database.getDatabase(loadConfiguration());
-        if (null == db) {
-            log.fatal("Unable to configure database");
-            throw new XindiceException("Unable to configure database");
-        }
         if (log.isInfoEnabled()) {
             log.info("Database name: '" + db.getName() + "'");
         }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java?view=diff&rev=564998&r1=564997&r2=564998
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java Sat Aug 11 19:51:49 2007
@@ -26,13 +26,12 @@
 import org.apache.xindice.core.Database;
 import org.apache.xindice.server.rpc.RPCMessageInterface;
 import org.apache.xindice.util.Configuration;
-import org.apache.xindice.util.ConfigurationException;
 import org.apache.xindice.webadmin.Location;
 import org.apache.xindice.webadmin.WebAdminManager;
-import org.apache.xindice.webadmin.viewer.HtmlDatabaseViewer;
+import org.apache.xindice.webadmin.util.MimeTable;
 import org.apache.xindice.webadmin.viewer.HtmlCollectionViewer;
+import org.apache.xindice.webadmin.viewer.HtmlDatabaseViewer;
 import org.apache.xindice.webadmin.viewer.HtmlResourceViewer;
-import org.apache.xindice.webadmin.util.MimeTable;
 import org.apache.xindice.webadmin.webdav.DAVRequest;
 import org.apache.xindice.webadmin.webdav.DAVResponse;
 import org.apache.xindice.webadmin.webdav.WebdavStatus;
@@ -92,7 +91,7 @@
         try {
             Configuration[] rootConfigurations = configuration.getChildren("root-collection");
             if (rootConfigurations.length == 0) {
-                throw new ConfigurationException("The database configuration is missing the <root-collection> element");
+                throw new ServletException("The database configuration is missing the <root-collection> element");
             }
 
             for (int i = 0; i < rootConfigurations.length; i++) {
@@ -132,7 +131,7 @@
                         log.warn("The database '" + name + "' root directory has been set to " + dbRoot +
                                  ". Keep in mind that if a war upgrade will take place the database will be lost.");
                     } else {
-                        throw new ConfigurationException(
+                        throw new ServletException(
                                 "The database '" + name + "' configuration points to a relative path, "
                                 + "but there was no " + Xindice.PROP_XINDICE_DB_HOME + " property set. "
                                 + "Furthermore, the war was not unpacked by the application server "
@@ -176,7 +175,7 @@
             try {
                 XmlRpc.setDriver(xmlrpcDriver);
             } catch (Exception e) {
-                throw new ConfigurationException("Failed to set driver for XmlRpc to: " + xmlrpcDriver, e);
+                throw new ServletException("Failed to set driver for XmlRpc to: " + xmlrpcDriver, e);
             }
 
             // Create the XML-RPC server and add our handler as the default.
@@ -184,7 +183,7 @@
             try {
                 this.xmlrpcServer.addHandler("$default", new RPCMessageInterface());
             } catch (Exception e) {
-                throw new ConfigurationException("Failed to add default handler to XmlRpc server.", e);
+                throw new ServletException("Failed to add default handler to XmlRpc server.", e);
             }
 
             log.info("Xindice server successfully started");
@@ -221,10 +220,11 @@
      * <li>default configuration stored in the <tt>Xindice</tt> class</li>
      * </ul>
      *
+     * @param servletConfig servlet configuration
      * @return Xindice configuration
-     * @throws ConfigurationException if unable to read configuration file or parse it
+     * @throws ServletException if unable to load configuration
      */
-    public Configuration loadConfiguration(ServletConfig servletConfig) {
+    public Configuration loadConfiguration(ServletConfig servletConfig) throws ServletException {
         try {
             InputStream in = null;
             String path = System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
@@ -262,7 +262,7 @@
 
             return new Configuration(doc, false);
         } catch (Exception e) {
-            throw new ConfigurationException("Failed to load configuration.", e);
+            throw new ServletException("Failed to load configuration.", e);
         }
     }
 

Modified: xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceException.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceException.java?view=diff&rev=564998&r1=564997&r2=564998
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceException.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceException.java Sat Aug 11 19:51:49 2007
@@ -19,9 +19,6 @@
 
 package org.apache.xindice.util;
 
-import java.io.PrintStream;
-import java.io.PrintWriter;
-
 /**
  * A XindiceException is the base class for all Xindice related
  * Exceptions.
@@ -29,7 +26,6 @@
  * @version $Revision$, $Date$
  */
 public class XindiceException extends Exception {
-    protected Throwable cause;
 
     public XindiceException() {
     }
@@ -39,36 +35,10 @@
     }
 
     public XindiceException(Throwable cause) {
-        super();
-        this.cause = cause;
+        super(cause);
     }
 
     public XindiceException(String message, Throwable cause) {
-        super(message);
-        this.cause = cause;
-    }
-
-    public void printStackTrace() {
-        printStackTrace(System.err);
-    }
-
-    public void printStackTrace(PrintStream s) {
-        super.printStackTrace(s);
-        if (this.cause != null) {
-            s.print("Caused by: ");
-            this.cause.printStackTrace(s);
-        }
-    }
-
-    public void printStackTrace(PrintWriter s) {
-        super.printStackTrace(s);
-        if (this.cause != null) {
-            s.print("Caused by: ");
-            this.cause.printStackTrace(s);
-        }
-    }
-
-    public Throwable getCause() {
-        return cause;
+        super(message, cause);
     }
 }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceRuntimeException.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceRuntimeException.java?view=diff&rev=564998&r1=564997&r2=564998
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceRuntimeException.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/util/XindiceRuntimeException.java Sat Aug 11 19:51:49 2007
@@ -19,16 +19,13 @@
 
 package org.apache.xindice.util;
 
-import java.io.PrintStream;
-import java.io.PrintWriter;
-
 /**
- * A XindiceRuntimeException is the base class for all Xindice related RuntimeExceptions.
+ * A XindiceRuntimeException is the base class for all Xindice related
+ * RuntimeExceptions.
  *
  * @version $Revision$, $Date$
  */
 public class XindiceRuntimeException extends RuntimeException {
-    protected Throwable cause;
 
     public XindiceRuntimeException() {
     }
@@ -38,36 +35,10 @@
     }
 
     public XindiceRuntimeException(Throwable cause) {
-        super();
-        this.cause = cause;
+        super(cause);
     }
 
     public XindiceRuntimeException(String message, Throwable cause) {
-        super(message);
-        this.cause = cause;
-    }
-
-    public void printStackTrace() {
-        printStackTrace(System.err);
-    }
-
-    public void printStackTrace(PrintStream s) {
-        super.printStackTrace(s);
-        if (this.cause != null) {
-            s.print("Caused by: ");
-            this.cause.printStackTrace(s);
-        }
-    }
-
-    public void printStackTrace(PrintWriter s) {
-        super.printStackTrace(s);
-        if (this.cause != null) {
-            s.print("Caused by: ");
-            this.cause.printStackTrace(s);
-        }
-    }
-
-    public Throwable getCause() {
-        return cause;
+        super(message, cause);
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.