cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgen...@apache.org
Subject svn commit: r687826 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java
Date Thu, 21 Aug 2008 18:39:00 GMT
Author: mgentry
Date: Thu Aug 21 11:39:00 2008
New Revision: 687826

URL: http://svn.apache.org/viewvc?rev=687826&view=rev
Log:
Updated getPasswordEncoder() to swallow (instead of throw) exceptions and log an error when
it fails to instantiate the specified encoder in the model.  This allows the modeler to continue
loading the model, even with an invalid encoder specified.  In an application, it will fail
to connect to the database and when the user looks at the logs they'll see the missing/invalid
password enocder as an error.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java?rev=687826&r1=687825&r2=687826&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java
Thu Aug 21 11:39:00 2008
@@ -21,7 +21,6 @@
 
 import java.io.Serializable;
 
-import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.conf.PasswordEncoding;
 import org.apache.cayenne.conf.PlainTextPasswordEncoder;
 import org.apache.cayenne.util.Util;
@@ -202,19 +201,26 @@
     }
 
     public PasswordEncoding getPasswordEncoder() {
-        String encoderClassName = getPasswordEncoderClass();
-        if (encoderClassName == null) {
-            encoderClassName = PasswordEncoding.standardEncoders[0];
-        }
-
         try {
-            return (PasswordEncoding) Util
-                    .getJavaClass(getPasswordEncoderClass())
-                    .newInstance();
+            return (PasswordEncoding) Thread.currentThread()
+                                            .getContextClassLoader()
+                                            .loadClass(getPasswordEncoderClass())
+                                            .newInstance();
+        }
+        catch (InstantiationException e) {
+            ; // Swallow it -- no need to throw/etc.
         }
-        catch (Exception e) {
-            throw new CayenneRuntimeException("Error loading encoder", e);
+        catch (IllegalAccessException e) {
+            ; // Swallow it -- no need to throw/etc.
         }
+        catch (ClassNotFoundException e) {
+            ; // Swallow it -- no need to throw/etc.
+        }
+
+        logger.error("Failed to obtain specified Password Encoder '" +
+                     getPasswordEncoderClass() + "' -- please check CLASSPATH");
+
+        return null;
     }
 
     /**



Mime
View raw message