You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by we...@apache.org on 2003/08/14 18:00:17 UTC
cvs commit: jakarta-jetspeed-2/plugin/src/java/org/apache/jetspeed/services/plugin AbstractPluginFactory.java
weaver 2003/08/14 09:00:17
Modified: plugin/src/java/org/apache/jetspeed/persistence/impl
AbstractOJBPersistencePlugin.java
plugin/src/java/org/apache/jetspeed/services/plugin
AbstractPluginFactory.java
Added: plugin/src/java/org/apache/jetspeed/services/plugin/util
CauseExtractor.java
Log:
Added a CauseExtractor class to be abel to produce more meaningful error/log messages.
It is pre-1.4 compliant as it looks for the "getCause" method using introspection
Revision Changes Path
1.1 jakarta-jetspeed-2/plugin/src/java/org/apache/jetspeed/services/plugin/util/CauseExtractor.java
Index: CauseExtractor.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.services.plugin.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* <p>
* CauseExtractor
* </p>
*
* Strings together all the messages within the exception
* stack. Checks for the "getCause" method so as to be pre-1.4
* compatible.
*
* @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
* @version $Id: CauseExtractor.java,v 1.1 2003/08/14 16:00:17 weaver Exp $
*
*/
public class CauseExtractor
{
/**
* Combines all the exception classes names and there
* messages from <code>e</code>'s exception stack into a single string.
* @param e base exception to extract all exceptions from.
* @return String containing all exception names and messages in
* <code>e</code>'s exception hierarchy.
*/
public static String getCompositeMessage(Exception e)
{
if (e == null)
{
throw new IllegalArgumentException("The exception cannot be null");
}
StringBuffer buf = new StringBuffer();
walkExceptions(e, buf);
return buf.toString();
}
public static void walkExceptions(Exception e, StringBuffer message)
{
try
{
Method method = e.getClass().getMethod("getCause", null);
message.append(e.getClass().getName()).append(": ").append((String) method.invoke(e, null));
message.append(". Cause: ");
}
catch (SecurityException e1)
{
e1.printStackTrace();
}
catch (NoSuchMethodException e1)
{
// we are done
return;
}
catch (IllegalArgumentException e2)
{
e2.printStackTrace();
}
catch (IllegalAccessException e3)
{
e3.printStackTrace();
}
catch (InvocationTargetException e4)
{
e4.printStackTrace();
}
}
}
1.2 +4 -2 jakarta-jetspeed-2/plugin/src/java/org/apache/jetspeed/persistence/impl/AbstractOJBPersistencePlugin.java
Index: AbstractOJBPersistencePlugin.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/plugin/src/java/org/apache/jetspeed/persistence/impl/AbstractOJBPersistencePlugin.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractOJBPersistencePlugin.java 13 Aug 2003 21:21:29 -0000 1.1
+++ AbstractOJBPersistencePlugin.java 14 Aug 2003 16:00:17 -0000 1.2
@@ -71,6 +71,7 @@
import org.apache.jetspeed.persistence.PersistencePlugin;
import org.apache.jetspeed.services.plugin.PluginConfiguration;
import org.apache.jetspeed.services.plugin.PluginInitializationException;
+import org.apache.jetspeed.services.plugin.util.CauseExtractor;
import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.PBKey;
import org.apache.ojb.broker.PersistenceBroker;
@@ -395,9 +396,10 @@
log.info(this.getClass().getName() + " initalized!");
}
- catch (Throwable e)
+ catch (Exception e)
{
- String message = "Unable create a ojb persistence plugin: " + e.getMessage();
+ String cause = CauseExtractor.getCompositeMessage(e);
+ String message = "Unable create a ojb persistence plugin. Cause: " + cause;
log.fatal(message, e);
throw new PluginInitializationException(message, e);
}
1.3 +4 -2 jakarta-jetspeed-2/plugin/src/java/org/apache/jetspeed/services/plugin/AbstractPluginFactory.java
Index: AbstractPluginFactory.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/plugin/src/java/org/apache/jetspeed/services/plugin/AbstractPluginFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractPluginFactory.java 13 Aug 2003 21:21:28 -0000 1.2
+++ AbstractPluginFactory.java 14 Aug 2003 16:00:17 -0000 1.3
@@ -63,6 +63,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.BaseService;
import org.apache.fulcrum.InitializationException;
+import org.apache.jetspeed.services.plugin.util.CauseExtractor;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
@@ -196,8 +197,9 @@
}
catch (Exception e)
{
- String message = "Unable to create Plugin.";
+ String message = "Unable to create Plugin.Cause: " + e.getMessage();
log.fatal(message, e);
+ log.fatal(CauseExtractor.getCompositeMessage(e));
if (!(e instanceof PluginInitializationException))
{
throw new PluginInitializationException(message, e);
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org