You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by jr...@apache.org on 2013/03/28 23:25:45 UTC

svn commit: r1462328 - in /openjpa/branches/1.3.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/

Author: jrbauer
Date: Thu Mar 28 22:25:45 2013
New Revision: 1462328

URL: http://svn.apache.org/r1462328
Log:
Disable logging during brokerfactory de-serialization.  Added type checking of plugin values.

Modified:
    openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/branches/1.3.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java
    openjpa/branches/1.3.x/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties

Modified: openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=1462328&r1=1462327&r2=1462328&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java (original)
+++ openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java Thu Mar 28 22:25:45 2013
@@ -474,7 +474,13 @@ public abstract class AbstractBrokerFact
         _transactional = new ConcurrentHashMap();
         _brokers = newBrokerSet();
 
+        // turn off logging while de-serializing BrokerFactory
+        String saveLogConfig = _conf.getLog();
+        _conf.setLog("none");
         makeReadOnly();
+        // re-enable any logging which was in effect
+        _conf.setLog(saveLogConfig);
+        
         return this;
     }
 

Modified: openjpa/branches/1.3.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java?rev=1462328&r1=1462327&r2=1462328&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java (original)
+++ openjpa/branches/1.3.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java Thu Mar 28 22:25:45 2013
@@ -19,7 +19,9 @@
 package org.apache.openjpa.lib.conf;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.ParseException;
 
 /**
  * A plugin {@link Value} consisting of plugin name and properties.
@@ -100,6 +102,20 @@ public class PluginValue extends ObjectV
      */
     public Object instantiate(Class type, Configuration conf, boolean fatal) {
         Object obj = newInstance(_name, type, conf, fatal);
+        
+        // ensure plugin value is compatible with plugin type
+        if (obj != null && !type.isAssignableFrom(obj.getClass())) {
+            Log log = (conf == null) ? null : conf.getConfigurationLog();
+            String msg = getIncompatiblePluginMessage(obj, type);
+            if (log != null && log.isErrorEnabled()) {
+            	log.error(msg);
+            }
+            if (fatal) {
+            	throw new ParseException(msg);
+            }
+            return null;
+        }
+        
         Configurations.configureInstance(obj, conf, _props,
             (fatal) ? getProperty() : null);
         if (_singleton)
@@ -107,6 +123,14 @@ public class PluginValue extends ObjectV
         return obj;
     }
 
+    private String getIncompatiblePluginMessage(Object obj, Class<?> type) {
+		return _loc.get("incompatible-plugin", 
+            new Object[]{ _name, 
+                          obj == null ? null : obj.getClass().getName(),
+                          type == null ? null : type.getName()
+                          }).toString();
+	}
+
     public void set(Object obj, boolean derived) {
         if (!_singleton)
             throw new IllegalStateException(_loc.get("not-singleton",

Modified: openjpa/branches/1.3.x/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties?rev=1462328&r1=1462327&r2=1462328&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties (original)
+++ openjpa/branches/1.3.x/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties Thu Mar 28 22:25:45 2013
@@ -114,4 +114,7 @@ Id-expert: true
 
 veto-change: Can not modify "{0}" because the property is not dynamic and the \
 	current configuration is read-only.
-jndi-lookup-failed: JNDI lookup for "{0}" with key "{1}" returned null.
\ No newline at end of file
+jndi-lookup-failed: JNDI lookup for "{0}" with key "{1}" returned null.
+incompatible-plugin: The plugin "{0}" of value type "{1}" is not compatible with \
+	the expected plugin type "{2}". Update the configuration property with a value that \
+	is compatible with the plugin.