Skip to content

Commit 87a4452

Browse files
author
Jeremy Bauer
committed
Disable logging during brokerfactory de-serialization. Added type checking of plugin values.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.2.x@1462488 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5595b96 commit 87a4452

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,13 @@ protected Object readResolve()
467467
_transactional = new ConcurrentHashMap();
468468
_brokers = newBrokerSet();
469469

470+
// turn off logging while de-serializing BrokerFactory
471+
String saveLogConfig = _conf.getLog();
472+
_conf.setLog("none");
470473
makeReadOnly();
474+
// re-enable any logging which was in effect
475+
_conf.setLog(saveLogConfig);
476+
471477
return this;
472478
}
473479

openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
package org.apache.openjpa.lib.conf;
2020

2121
import org.apache.commons.lang.StringUtils;
22+
import org.apache.openjpa.lib.log.Log;
2223
import org.apache.openjpa.lib.util.Localizer;
24+
import org.apache.openjpa.lib.util.ParseException;
2325

2426
/**
2527
* A plugin {@link Value} consisting of plugin name and properties.
@@ -100,13 +102,35 @@ public void setProperties(String props) {
100102
*/
101103
public Object instantiate(Class type, Configuration conf, boolean fatal) {
102104
Object obj = newInstance(_name, type, conf, fatal);
105+
106+
// ensure plugin value is compatible with plugin type
107+
if (obj != null && !type.isAssignableFrom(obj.getClass())) {
108+
Log log = (conf == null) ? null : conf.getConfigurationLog();
109+
String msg = getIncompatiblePluginMessage(obj, type);
110+
if (log != null && log.isErrorEnabled()) {
111+
log.error(msg);
112+
}
113+
if (fatal) {
114+
throw new ParseException(msg);
115+
}
116+
return null;
117+
}
118+
103119
Configurations.configureInstance(obj, conf, _props,
104120
(fatal) ? getProperty() : null);
105121
if (_singleton)
106122
set(obj, true);
107123
return obj;
108124
}
109125

126+
private String getIncompatiblePluginMessage(Object obj, Class<?> type) {
127+
return _loc.get("incompatible-plugin",
128+
new Object[]{ _name,
129+
obj == null ? null : obj.getClass().getName(),
130+
type == null ? null : type.getName()
131+
}).toString();
132+
}
133+
110134
public void set(Object obj, boolean derived) {
111135
if (!_singleton)
112136
throw new IllegalStateException(_loc.get("not-singleton",

openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,7 @@ Id-expert: true
114114

115115
veto-change: Can not modify "{0}" because the property is not dynamic and the \
116116
current configuration is read-only.
117-
jndi-lookup-failed: JNDI lookup for "{0}" with key "{1}" returned null.
117+
jndi-lookup-failed: JNDI lookup for "{0}" with key "{1}" returned null.
118+
incompatible-plugin: The plugin "{0}" of value type "{1}" is not compatible with \
119+
the expected plugin type "{2}". Update the configuration property with a value that \
120+
is compatible with the plugin.

0 commit comments

Comments
 (0)