Refactoring code
This commit is contained in:
parent
b50771724f
commit
3d42211970
2 changed files with 19 additions and 15 deletions
|
@ -38,22 +38,25 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractFeedFetcher.class);
|
||||
|
||||
private final Set<FetcherListener> fetcherEventListeners;
|
||||
private final Set<FetcherListener> listeners;
|
||||
private String userAgent;
|
||||
private boolean usingDeltaEncoding;
|
||||
private boolean preserveWireFeed;
|
||||
|
||||
public AbstractFeedFetcher() {
|
||||
fetcherEventListeners = Collections.synchronizedSet(new HashSet<FetcherListener>());
|
||||
|
||||
listeners = Collections.synchronizedSet(new HashSet<FetcherListener>());
|
||||
|
||||
final Properties props = new Properties(System.getProperties());
|
||||
final String resourceName = "fetcher.properties";
|
||||
|
||||
try {
|
||||
|
||||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(resourceName);
|
||||
if (inputStream == null) {
|
||||
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
|
||||
}
|
||||
|
||||
if (inputStream != null) {
|
||||
props.load(inputStream);
|
||||
System.getProperties().putAll(props);
|
||||
|
@ -61,6 +64,7 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
|||
} else {
|
||||
LOG.warn("Could not find {} on classpath", resourceName);
|
||||
}
|
||||
|
||||
} catch (final IOException e) {
|
||||
// do nothing - we don't want to fail just because we could not find the version
|
||||
LOG.error("Error reading {} from classpath: {}", resourceName, e.getMessage());
|
||||
|
@ -117,8 +121,8 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
|||
*/
|
||||
protected void fireEvent(final String eventType, final String urlStr, final SyndFeed feed) {
|
||||
final FetcherEvent fetcherEvent = new FetcherEvent(this, urlStr, eventType, feed);
|
||||
synchronized (fetcherEventListeners) {
|
||||
for (final FetcherListener fetcherEventListener : fetcherEventListeners) {
|
||||
synchronized (listeners) {
|
||||
for (final FetcherListener fetcherEventListener : listeners) {
|
||||
fetcherEventListener.fetcherEvent(fetcherEvent);
|
||||
}
|
||||
}
|
||||
|
@ -127,14 +131,14 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
|||
@Override
|
||||
public void addFetcherEventListener(final FetcherListener listener) {
|
||||
if (listener != null) {
|
||||
fetcherEventListeners.add(listener);
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFetcherEventListener(final FetcherListener listener) {
|
||||
if (listener != null) {
|
||||
fetcherEventListeners.remove(listener);
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,9 +202,8 @@ public abstract class AbstractFeedFetcher implements FeedFetcher {
|
|||
* @return
|
||||
*/
|
||||
public static SyndFeed combineFeeds(final SyndFeed originalFeed, final SyndFeed newFeed) {
|
||||
SyndFeed result;
|
||||
try {
|
||||
result = (SyndFeed) newFeed.clone();
|
||||
final SyndFeed result = (SyndFeed) newFeed.clone();
|
||||
result.getEntries().addAll(result.getEntries().size(), originalFeed.getEntries());
|
||||
return result;
|
||||
} catch (final CloneNotSupportedException e) {
|
||||
|
|
|
@ -11,22 +11,23 @@ public class AbstractFeedFetcherBeanInfo extends SimpleBeanInfo {
|
|||
|
||||
@Override
|
||||
public EventSetDescriptor[] getEventSetDescriptors() {
|
||||
|
||||
try {
|
||||
final Class<AbstractFeedFetcher> clz = AbstractFeedFetcher.class; // get the class
|
||||
// object which we'll
|
||||
// describe
|
||||
|
||||
// get the class object which we'll describe
|
||||
final Class<AbstractFeedFetcher> clz = AbstractFeedFetcher.class;
|
||||
final Method addMethod = clz.getMethod("addFetcherEventListener", new Class[] { FetcherListener.class });
|
||||
final Method removeMethod = clz.getMethod("removeFetcherEventListener", new Class[] { FetcherListener.class });
|
||||
final Method listenerMethod = FetcherListener.class.getMethod("fetcherEvent", new Class[] { FetcherEvent.class });
|
||||
final EventSetDescriptor est = new EventSetDescriptor("fetcherEvent", clz, new Method[] { listenerMethod }, addMethod, removeMethod);
|
||||
final EventSetDescriptor[] results = new EventSetDescriptor[] { est };
|
||||
return results;
|
||||
return new EventSetDescriptor[] { est };
|
||||
|
||||
} catch (final Exception e) {
|
||||
// IntrospectionException, SecurityException and/or NoSuchMethodException can be thrown
|
||||
// here
|
||||
// the best we can do is to convert them to runtime exceptions
|
||||
// here. The best we can do is to convert them to runtime exceptions
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue