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
|
@ -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 org.xml.sax.XMLReader;
|
||||||
|
|
||||||
import com.sun.syndication.feed.WireFeed;
|
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.FeedParsers;
|
||||||
import com.sun.syndication.io.impl.XmlFixerReader;
|
import com.sun.syndication.io.impl.XmlFixerReader;
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ public class WireFeedInput {
|
||||||
|
|
||||||
private static FeedParsers getFeedParsers() {
|
private static FeedParsers getFeedParsers() {
|
||||||
synchronized (WireFeedInput.class) {
|
synchronized (WireFeedInput.class) {
|
||||||
final ClassLoader classLoader = WireFeedInput.class.getClassLoader();
|
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||||
FeedParsers parsers = clMap.get(classLoader);
|
FeedParsers parsers = clMap.get(classLoader);
|
||||||
if (parsers == null) {
|
if (parsers == null) {
|
||||||
parsers = new FeedParsers();
|
parsers = new FeedParsers();
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.jdom2.output.Format;
|
||||||
import org.jdom2.output.XMLOutputter;
|
import org.jdom2.output.XMLOutputter;
|
||||||
|
|
||||||
import com.sun.syndication.feed.WireFeed;
|
import com.sun.syndication.feed.WireFeed;
|
||||||
|
import com.sun.syndication.feed.impl.ConfigurableClassLoader;
|
||||||
import com.sun.syndication.io.impl.FeedGenerators;
|
import com.sun.syndication.io.impl.FeedGenerators;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +49,7 @@ public class WireFeedOutput {
|
||||||
|
|
||||||
private static FeedGenerators getFeedGenerators() {
|
private static FeedGenerators getFeedGenerators() {
|
||||||
synchronized (WireFeedOutput.class) {
|
synchronized (WireFeedOutput.class) {
|
||||||
final ClassLoader classLoader = WireFeedOutput.class.getClassLoader();
|
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||||
FeedGenerators generators = clMap.get(classLoader);
|
FeedGenerators generators = clMap.get(classLoader);
|
||||||
if (generators == null) {
|
if (generators == null) {
|
||||||
generators = new FeedGenerators();
|
generators = new FeedGenerators();
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.sun.syndication.feed.impl.ConfigurableClassLoader;
|
||||||
import com.sun.syndication.io.DelegatingModuleGenerator;
|
import com.sun.syndication.io.DelegatingModuleGenerator;
|
||||||
import com.sun.syndication.io.DelegatingModuleParser;
|
import com.sun.syndication.io.DelegatingModuleParser;
|
||||||
import com.sun.syndication.io.WireFeedGenerator;
|
import com.sun.syndication.io.WireFeedGenerator;
|
||||||
|
@ -137,7 +138,7 @@ public abstract class PluginManager<T> {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Class<T>[] getClasses() throws ClassNotFoundException {
|
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 List<Class<T>> classes = new ArrayList<Class<T>>();
|
||||||
final boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.pluginmanager.useloadclass", "false")).booleanValue();
|
final boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.pluginmanager.useloadclass", "false")).booleanValue();
|
||||||
for (final String propertyValue : propertyValues) {
|
for (final String propertyValue : propertyValues) {
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.util.Properties;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.WeakHashMap;
|
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.
|
* Properties loader that aggregates a master properties file and several extra properties files, all from the current classpath.
|
||||||
* <P>
|
* <P>
|
||||||
|
@ -39,7 +41,7 @@ public class PropertiesLoader {
|
||||||
*/
|
*/
|
||||||
public static PropertiesLoader getPropertiesLoader() {
|
public static PropertiesLoader getPropertiesLoader() {
|
||||||
synchronized (PropertiesLoader.class) {
|
synchronized (PropertiesLoader.class) {
|
||||||
final ClassLoader classLoader = PropertiesLoader.class.getClassLoader();
|
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||||
PropertiesLoader loader = clMap.get(classLoader);
|
PropertiesLoader loader = clMap.get(classLoader);
|
||||||
if (loader == null) {
|
if (loader == null) {
|
||||||
try {
|
try {
|
||||||
|
@ -66,7 +68,7 @@ public class PropertiesLoader {
|
||||||
*/
|
*/
|
||||||
private PropertiesLoader(final String masterFileLocation, final String extraFileLocation) throws IOException {
|
private PropertiesLoader(final String masterFileLocation, final String extraFileLocation) throws IOException {
|
||||||
final List<Properties> propertiesList = new ArrayList<Properties>();
|
final List<Properties> propertiesList = new ArrayList<Properties>();
|
||||||
final ClassLoader classLoader = PropertiesLoader.class.getClassLoader();
|
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final InputStream is = classLoader.getResourceAsStream(masterFileLocation);
|
final InputStream is = classLoader.getResourceAsStream(masterFileLocation);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.jdom2.input.SAXBuilder;
|
||||||
import org.jdom2.input.sax.XMLReaders;
|
import org.jdom2.input.sax.XMLReaders;
|
||||||
|
|
||||||
import com.sun.syndication.feed.WireFeed;
|
import com.sun.syndication.feed.WireFeed;
|
||||||
|
import com.sun.syndication.feed.impl.ConfigurableClassLoader;
|
||||||
import com.sun.syndication.feed.synd.SyndFeed;
|
import com.sun.syndication.feed.synd.SyndFeed;
|
||||||
import com.sun.syndication.io.SyndFeedInput;
|
import com.sun.syndication.io.SyndFeedInput;
|
||||||
import com.sun.syndication.io.WireFeedInput;
|
import com.sun.syndication.io.WireFeedInput;
|
||||||
|
@ -36,7 +37,8 @@ public abstract class FeedTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Reader getFeedReader() throws Exception {
|
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);
|
assertNotNull("Could not find resource " + getFeedFileName(), resource);
|
||||||
return new InputStreamReader(resource);
|
return new InputStreamReader(resource);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue