Added the ConfigurableClassLoader singleton to address some OSGi
problems.
This commit is contained in:
parent
6029420e5f
commit
90fca03a98
6 changed files with 51 additions and 6 deletions
src
main/java/com/sun/syndication
feed/impl
io
test/java/com/sun/syndication/unittest
|
@ -0,0 +1,38 @@
|
|||
package com.sun.syndication.feed.impl;
|
||||
|
||||
/**
|
||||
* This class addresses some ClassLoader problems in OSGi environments. If you have ClassLoader problems, simply override the default ClassLoader by calling the
|
||||
* {@link #setClassLoader(ClassLoader)} method before calling any ROME code. Unfortunately I don't know whether this works because I have absolutely no
|
||||
* experience with OSGi.
|
||||
*
|
||||
* @author Patrick Gotthard
|
||||
*
|
||||
*/
|
||||
public enum ConfigurableClassLoader {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
private ClassLoader classLoader;
|
||||
|
||||
/**
|
||||
* Get the configured ClassLoader. Returns
|
||||
*
|
||||
* @return The configured ClassLoader. Returns the ClassLoader of this enum when the ClassLoader was not overridden.
|
||||
*/
|
||||
public ClassLoader getClassLoader() {
|
||||
if (classLoader == null) {
|
||||
classLoader = ConfigurableClassLoader.class.getClassLoader();
|
||||
}
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default ClassLoader (the ClassLoader of this enum).
|
||||
*
|
||||
* @param classLoader The ClassLoader to set.
|
||||
*/
|
||||
public void setClassLoader(final ClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
}
|
|
@ -39,6 +39,7 @@ import org.xml.sax.SAXNotSupportedException;
|
|||
import org.xml.sax.XMLReader;
|
||||
|
||||
import com.sun.syndication.feed.WireFeed;
|
||||
import com.sun.syndication.feed.impl.ConfigurableClassLoader;
|
||||
import com.sun.syndication.io.impl.FeedParsers;
|
||||
import com.sun.syndication.io.impl.XmlFixerReader;
|
||||
|
||||
|
@ -60,7 +61,7 @@ public class WireFeedInput {
|
|||
|
||||
private static FeedParsers getFeedParsers() {
|
||||
synchronized (WireFeedInput.class) {
|
||||
final ClassLoader classLoader = WireFeedInput.class.getClassLoader();
|
||||
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||
FeedParsers parsers = clMap.get(classLoader);
|
||||
if (parsers == null) {
|
||||
parsers = new FeedParsers();
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.jdom2.output.Format;
|
|||
import org.jdom2.output.XMLOutputter;
|
||||
|
||||
import com.sun.syndication.feed.WireFeed;
|
||||
import com.sun.syndication.feed.impl.ConfigurableClassLoader;
|
||||
import com.sun.syndication.io.impl.FeedGenerators;
|
||||
|
||||
/**
|
||||
|
@ -48,7 +49,7 @@ public class WireFeedOutput {
|
|||
|
||||
private static FeedGenerators getFeedGenerators() {
|
||||
synchronized (WireFeedOutput.class) {
|
||||
final ClassLoader classLoader = WireFeedOutput.class.getClassLoader();
|
||||
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||
FeedGenerators generators = clMap.get(classLoader);
|
||||
if (generators == null) {
|
||||
generators = new FeedGenerators();
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.syndication.feed.impl.ConfigurableClassLoader;
|
||||
import com.sun.syndication.io.DelegatingModuleGenerator;
|
||||
import com.sun.syndication.io.DelegatingModuleParser;
|
||||
import com.sun.syndication.io.WireFeedGenerator;
|
||||
|
@ -137,7 +138,7 @@ public abstract class PluginManager<T> {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<T>[] getClasses() throws ClassNotFoundException {
|
||||
final ClassLoader classLoader = PluginManager.class.getClassLoader();
|
||||
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||
final List<Class<T>> classes = new ArrayList<Class<T>>();
|
||||
final boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.pluginmanager.useloadclass", "false")).booleanValue();
|
||||
for (final String propertyValue : propertyValues) {
|
||||
|
|
|
@ -11,6 +11,8 @@ import java.util.Properties;
|
|||
import java.util.StringTokenizer;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import com.sun.syndication.feed.impl.ConfigurableClassLoader;
|
||||
|
||||
/**
|
||||
* Properties loader that aggregates a master properties file and several extra properties files, all from the current classpath.
|
||||
* <P>
|
||||
|
@ -39,7 +41,7 @@ public class PropertiesLoader {
|
|||
*/
|
||||
public static PropertiesLoader getPropertiesLoader() {
|
||||
synchronized (PropertiesLoader.class) {
|
||||
final ClassLoader classLoader = PropertiesLoader.class.getClassLoader();
|
||||
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||
PropertiesLoader loader = clMap.get(classLoader);
|
||||
if (loader == null) {
|
||||
try {
|
||||
|
@ -66,7 +68,7 @@ public class PropertiesLoader {
|
|||
*/
|
||||
private PropertiesLoader(final String masterFileLocation, final String extraFileLocation) throws IOException {
|
||||
final List<Properties> propertiesList = new ArrayList<Properties>();
|
||||
final ClassLoader classLoader = PropertiesLoader.class.getClassLoader();
|
||||
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||
|
||||
try {
|
||||
final InputStream is = classLoader.getResourceAsStream(masterFileLocation);
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.jdom2.input.SAXBuilder;
|
|||
import org.jdom2.input.sax.XMLReaders;
|
||||
|
||||
import com.sun.syndication.feed.WireFeed;
|
||||
import com.sun.syndication.feed.impl.ConfigurableClassLoader;
|
||||
import com.sun.syndication.feed.synd.SyndFeed;
|
||||
import com.sun.syndication.io.SyndFeedInput;
|
||||
import com.sun.syndication.io.WireFeedInput;
|
||||
|
@ -36,7 +37,8 @@ public abstract class FeedTest extends TestCase {
|
|||
}
|
||||
|
||||
protected Reader getFeedReader() throws Exception {
|
||||
final InputStream resource = FeedTest.class.getClassLoader().getResourceAsStream(getFeedFileName());
|
||||
final ClassLoader ClassLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||
final InputStream resource = ClassLoader.getResourceAsStream(getFeedFileName());
|
||||
assertNotNull("Could not find resource " + getFeedFileName(), resource);
|
||||
return new InputStreamReader(resource);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue