some generics signatures and some serialVersionUIDs added

This commit is contained in:
Martin Kurz 2013-10-04 00:26:33 +02:00
parent cb75d15dd1
commit 8489324695
40 changed files with 234 additions and 211 deletions

View file

@ -31,7 +31,7 @@ public interface CopyFrom<T> {
*
* @return the interface the copyFrom works on.
*/
public Class<? extends CopyFrom> getInterface();
public Class<? extends CopyFrom<?>> getInterface();
/**
* Copies all the properties of the given bean into this one.
@ -46,6 +46,6 @@ public interface CopyFrom<T> {
* @param obj the instance to copy properties from.
*
*/
public void copyFrom(CopyFrom obj);
public void copyFrom(CopyFrom<?> obj);
}

View file

@ -27,6 +27,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.module.Extendable;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.module.impl.ModuleUtils;
import com.sun.syndication.feed.synd.SyndPerson;
/**
* Bean for entry elements of Atom feeds.
@ -36,6 +37,7 @@ import com.sun.syndication.feed.module.impl.ModuleUtils;
* @author Dave Johnson (updated for Atom 1.0)
*/
public class Entry implements Cloneable, Serializable, Extendable {
private static final long serialVersionUID = 4874483180016783939L;
private Content summary;
private Content title;
private Date created; // Atom 0.3 only
@ -43,10 +45,10 @@ public class Entry implements Cloneable, Serializable, Extendable {
private Date updated; // AKA modified
private Feed source;
private List<Link> alternateLinks;
private List<Person> authors;
private List<SyndPerson> authors;
private List<Category> categories;
private List<Content> contents;
private List<Person> contributors;
private List<SyndPerson> contributors;
private List<Element> foreignMarkup;
private List<Module> modules;
private List<Link> otherLinks;
@ -93,7 +95,7 @@ public class Entry implements Cloneable, Serializable, Extendable {
* @param authors the author of the entry, <b>null</b> if none.
*
*/
public void setAuthors(final List<Person> authors) {
public void setAuthors(final List<SyndPerson> authors) {
this.authors = authors;
}
@ -104,8 +106,8 @@ public class Entry implements Cloneable, Serializable, Extendable {
* @return the entry author, <b>null</b> if none.
*
*/
public List<Person> getAuthors() {
return authors == null ? (authors = new ArrayList<Person>()) : authors;
public List<SyndPerson> getAuthors() {
return authors == null ? (authors = new ArrayList<SyndPerson>()) : authors;
}
/**
@ -160,7 +162,7 @@ public class Entry implements Cloneable, Serializable, Extendable {
* contributors to set, an empty list or <b>null</b> if none.
*
*/
public void setContributors(final List<Person> contributors) {
public void setContributors(final List<SyndPerson> contributors) {
this.contributors = contributors;
}
@ -172,8 +174,8 @@ public class Entry implements Cloneable, Serializable, Extendable {
* list if none.
*
*/
public List<Person> getContributors() {
return contributors == null ? (contributors = new ArrayList<Person>()) : contributors;
public List<SyndPerson> getContributors() {
return contributors == null ? (contributors = new ArrayList<SyndPerson>()) : contributors;
}
/**

View file

@ -23,6 +23,7 @@ import java.util.List;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.module.impl.ModuleUtils;
import com.sun.syndication.feed.synd.SyndPerson;
/**
* Bean for Atom feeds.
@ -34,11 +35,11 @@ import com.sun.syndication.feed.module.impl.ModuleUtils;
* @author Dave Johnson (updated for Atom 1.0)
*/
public class Feed extends WireFeed {
private static final long serialVersionUID = -9175445106675422528L;
private String xmlBase;
private List<Category> categories;
private List<Person> authors;
private List<Person> contributors;
private List<SyndPerson> authors;
private List<SyndPerson> contributors;
private Generator generator;
private String icon;
private String id;
@ -199,8 +200,8 @@ public class Feed extends WireFeed {
* @return the feed author, <b>null</b> if none.
*
*/
public List<Person> getAuthors() {
return authors == null ? (authors = new ArrayList<Person>()) : authors;
public List<SyndPerson> getAuthors() {
return authors == null ? (authors = new ArrayList<SyndPerson>()) : authors;
}
/**
@ -210,7 +211,7 @@ public class Feed extends WireFeed {
* @param authors the feed author to set, <b>null</b> if none.
*
*/
public void setAuthors(final List<Person> authors) {
public void setAuthors(final List<SyndPerson> authors) {
this.authors = authors;
}
@ -222,8 +223,8 @@ public class Feed extends WireFeed {
* list if none.
*
*/
public List<Person> getContributors() {
return contributors == null ? (contributors = new ArrayList<Person>()) : contributors;
public List<SyndPerson> getContributors() {
return contributors == null ? (contributors = new ArrayList<SyndPerson>()) : contributors;
}
/**
@ -234,7 +235,7 @@ public class Feed extends WireFeed {
* contributors to set, an empty list or <b>null</b> if none.
*
*/
public void setContributors(final List<Person> contributors) {
public void setContributors(final List<SyndPerson> contributors) {
this.contributors = contributors;
}

View file

@ -24,6 +24,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.module.Extendable;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.module.impl.ModuleUtils;
import com.sun.syndication.feed.synd.SyndPerson;
/**
* Bean for person elements of Atom feeds.
@ -32,7 +33,9 @@ import com.sun.syndication.feed.module.impl.ModuleUtils;
* @author Alejandro Abdelnur
* @author Dave Johnson (updated for Atom 1.0)
*/
public class Person implements Cloneable, Serializable, Extendable {
public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
private static final long serialVersionUID = 8853656713347735541L;
private final ObjectBean objBean;

View file

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
@ -41,12 +42,12 @@ import java.util.Set;
*
*/
public class CloneableBean implements Serializable, Cloneable {
private static final Class[] NO_PARAMS_DEF = new Class[0];
private static final long serialVersionUID = -6520053043831187823L;
private static final Class<?>[] NO_PARAMS_DEF = new Class[0];
private static final Object[] NO_PARAMS = new Object[0];
private final Object obj;
private Set ignoreProperties;
private Set<String> ignoreProperties;
/**
* Default constructor.
@ -103,9 +104,9 @@ public class CloneableBean implements Serializable, Cloneable {
* @param ignoreProperties properties to ignore when cloning.
*
*/
public CloneableBean(final Object obj, final Set ignoreProperties) {
public CloneableBean(final Object obj, final Set<String> ignoreProperties) {
this.obj = obj;
this.ignoreProperties = ignoreProperties != null ? ignoreProperties : Collections.EMPTY_SET;
this.ignoreProperties = ignoreProperties != null ? ignoreProperties : Collections.<String>emptySet();
}
/**
@ -191,21 +192,22 @@ public class CloneableBean implements Serializable, Cloneable {
return clonedBean;
}
private Object doClone(Object value) throws Exception {
@SuppressWarnings("unchecked")
private <T extends Object> T doClone(T value) throws Exception {
if (value != null) {
final Class vClass = value.getClass();
final Class<?> vClass = value.getClass();
if (vClass.isArray()) {
value = cloneArray(value);
value = (T) cloneArray((T[]) value);
} else if (value instanceof Collection) {
value = cloneCollection((Collection) value);
value = (T) cloneCollection((Collection<Object>) value);
} else if (value instanceof Map) {
value = cloneMap((Map) value);
value = (T) cloneMap((Map<Object, Object>) value);
} else if (isBasicType(vClass)) {
// NOTHING SPECIAL TO DO HERE, THEY ARE INMUTABLE
} else if (value instanceof Cloneable) {
final Method cloneMethod = vClass.getMethod("clone", NO_PARAMS_DEF);
if (Modifier.isPublic(cloneMethod.getModifiers())) {
value = cloneMethod.invoke(value, NO_PARAMS);
value = (T) cloneMethod.invoke(value, NO_PARAMS);
} else {
throw new CloneNotSupportedException("Cannot clone a " + value.getClass() + " object, clone() is not public");
}
@ -216,42 +218,41 @@ public class CloneableBean implements Serializable, Cloneable {
return value;
}
private Object cloneArray(final Object array) throws Exception {
final Class elementClass = array.getClass().getComponentType();
private <T> T[] cloneArray(final T[] array) throws Exception {
final Class<?> elementClass = array.getClass().getComponentType();
final int length = Array.getLength(array);
final Object newArray = Array.newInstance(elementClass, length);
@SuppressWarnings("unchecked")
final T[] newArray = (T[]) Array.newInstance(elementClass, length);
for (int i = 0; i < length; i++) {
final Object element = doClone(Array.get(array, i));
Array.set(newArray, i, element);
Array.set(newArray, i, doClone(Array.get(array, i)));
}
return newArray;
}
private Object cloneCollection(final Collection collection) throws Exception {
final Class mClass = collection.getClass();
final Collection newColl = (Collection) mClass.newInstance();
final Iterator i = collection.iterator();
private <T> Collection<T> cloneCollection(final Collection<T> collection) throws Exception {
@SuppressWarnings("unchecked")
final Class<Collection<T>> mClass = (Class<Collection<T>>) collection.getClass();
final Collection<T> newColl = (Collection<T>) mClass.newInstance();
final Iterator<T> i = collection.iterator();
while (i.hasNext()) {
final Object element = doClone(i.next());
newColl.add(element);
newColl.add(doClone(i.next()));
}
return newColl;
}
private Object cloneMap(final Map map) throws Exception {
final Class mClass = map.getClass();
final Map newMap = (Map) mClass.newInstance();
final Iterator entries = map.entrySet().iterator();
private <S, T> Map<S, T> cloneMap(final Map<S, T> map) throws Exception {
@SuppressWarnings("unchecked")
final Class<Map<S, T>> mClass = (Class<Map<S, T>>) map.getClass();
final Map<S, T> newMap = (Map<S, T>) mClass.newInstance();
final Iterator<Entry<S, T>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
final Map.Entry entry = (Map.Entry) entries.next();
final Object key = doClone(entry.getKey());
final Object value = doClone(entry.getValue());
newMap.put(key, value);
final Map.Entry<S, T> entry = (Map.Entry<S, T>) entries.next();
newMap.put(doClone(entry.getKey()), doClone(entry.getValue()));
}
return newMap;
}
private static final Set BASIC_TYPES = new HashSet();
private static final Set<Class<?>> BASIC_TYPES = new HashSet<Class<?>>();
static {
BASIC_TYPES.add(Boolean.class);
@ -265,7 +266,7 @@ public class CloneableBean implements Serializable, Cloneable {
BASIC_TYPES.add(String.class);
}
private static final Map CONSTRUCTOR_BASIC_TYPES = new HashMap();
private static final Map<Class<?>, Class<?>[]> CONSTRUCTOR_BASIC_TYPES = new HashMap<Class<?>, Class<?>[]>();
static {
CONSTRUCTOR_BASIC_TYPES.put(Boolean.class, new Class[] { Boolean.TYPE });
@ -279,7 +280,7 @@ public class CloneableBean implements Serializable, Cloneable {
CONSTRUCTOR_BASIC_TYPES.put(String.class, new Class[] { String.class });
}
private boolean isBasicType(final Class vClass) {
private boolean isBasicType(final Class<?> vClass) {
return BASIC_TYPES.contains(vClass);
}

View file

@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.sun.syndication.feed.CopyFrom;
@ -36,11 +37,11 @@ import com.sun.syndication.feed.CopyFrom;
public class CopyFromHelper {
private static final Object[] NO_PARAMS = new Object[0];
private final Class beanInterfaceClass;
private final Map baseInterfaceMap; // ENTRIES(propertyName,interface.class)
private final Map baseImplMap; // ENTRIES(interface.class,implementation.class)
private final Class<? extends CopyFrom<?>> beanInterfaceClass;
private final Map<String, Class<?>> baseInterfaceMap; // ENTRIES(propertyName,interface.class)
private final Map<Class<? extends CopyFrom<?>>, Class<?>> baseImplMap; // ENTRIES(interface.class,implementation.class)
public CopyFromHelper(final Class beanInterfaceClass, final Map basePropInterfaceMap, final Map basePropClassImplMap) {
public CopyFromHelper(final Class<? extends CopyFrom<?>> beanInterfaceClass, final Map<String, Class<?>> basePropInterfaceMap, final Map<Class<? extends CopyFrom<?>>, Class<?>> basePropClassImplMap) {
this.beanInterfaceClass = beanInterfaceClass;
baseInterfaceMap = basePropInterfaceMap;
baseImplMap = basePropClassImplMap;
@ -78,7 +79,7 @@ public class CopyFromHelper {
// copyFrom-able
Object value = pReadMethod.invoke(source, NO_PARAMS);
if (value != null) {
final Class baseInterface = (Class) baseInterfaceMap.get(propertyName);
final Class<?> baseInterface = baseInterfaceMap.get(propertyName);
value = doCopy(value, baseInterface);
pWriteMethod.invoke(target, new Object[] { value });
}
@ -90,33 +91,34 @@ public class CopyFromHelper {
}
}
private CopyFrom createInstance(final Class interfaceClass) throws Exception {
private CopyFrom<?> createInstance(final Class<? extends CopyFrom<?>> interfaceClass) throws Exception {
if (baseImplMap.get(interfaceClass) == null) {
return null;
} else {
return (CopyFrom) ((Class) baseImplMap.get(interfaceClass)).newInstance();
return (CopyFrom<?>) baseImplMap.get(interfaceClass).newInstance();
}
}
private Object doCopy(Object value, final Class baseInterface) throws Exception {
@SuppressWarnings("unchecked")
private Object doCopy(Object value, final Class<?> baseInterface) throws Exception {
if (value != null) {
final Class vClass = value.getClass();
final Class<?> vClass = value.getClass();
if (vClass.isArray()) {
value = doCopyArray(value, baseInterface);
} else if (value instanceof Collection) {
value = doCopyCollection((Collection) value, baseInterface);
value = doCopyCollection((Collection<?>) value, baseInterface);
} else if (value instanceof Map) {
value = doCopyMap((Map) value, baseInterface);
value = doCopyMap((Map<Object, Object>) value, baseInterface);
} else if (isBasicType(vClass)) {
// value = value; // nothing to do here
if (value instanceof Date) { // because Date it is not inmutable
value = ((Date) value).clone();
}
} else { // it goes CopyFrom
if (value instanceof CopyFrom) {
final CopyFrom source = (CopyFrom) value;
CopyFrom target = createInstance(source.getInterface());
target = target == null ? (CopyFrom) value.getClass().newInstance() : target;
if (value instanceof CopyFrom<?>) {
final CopyFrom<?> source = (CopyFrom<?>) value;
CopyFrom<?> target = createInstance(source.getInterface());
target = target == null ? (CopyFrom<?>) value.getClass().newInstance() : target;
target.copyFrom(source);
value = target;
} else {
@ -127,8 +129,8 @@ public class CopyFromHelper {
return value;
}
private Object doCopyArray(final Object array, final Class baseInterface) throws Exception {
final Class elementClass = array.getClass().getComponentType();
private Object doCopyArray(final Object array, final Class<?> baseInterface) throws Exception {
final Class<?> elementClass = array.getClass().getComponentType();
final int length = Array.getLength(array);
final Object newArray = Array.newInstance(elementClass, length);
for (int i = 0; i < length; i++) {
@ -138,30 +140,27 @@ public class CopyFromHelper {
return newArray;
}
private Object doCopyCollection(final Collection collection, final Class baseInterface) throws Exception {
private Collection<Object> doCopyCollection(final Collection<?> collection, final Class<?> baseInterface) throws Exception {
// expecting SETs or LISTs only, going default implementation of them
final Collection newColl = collection instanceof Set ? (Collection) new HashSet() : (Collection) new ArrayList();
final Iterator i = collection.iterator();
final Collection<Object> newColl = collection instanceof Set ? new HashSet<Object>() : new ArrayList<Object>();
final Iterator<?> i = collection.iterator();
while (i.hasNext()) {
final Object element = doCopy(i.next(), baseInterface);
newColl.add(element);
newColl.add(doCopy(i.next(), baseInterface));
}
return newColl;
}
private Object doCopyMap(final Map map, final Class baseInterface) throws Exception {
final Map newMap = new HashMap();
final Iterator entries = map.entrySet().iterator();
private Map<Object, Object> doCopyMap(final Map<Object, Object> map, final Class<?> baseInterface) throws Exception {
final Map<Object, Object> newMap = new HashMap<Object, Object>();
final Iterator<Entry<Object, Object>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
final Map.Entry entry = (Map.Entry) entries.next();
final Object key = entry.getKey(); // we are assuming string KEYS
final Object element = doCopy(entry.getValue(), baseInterface);
newMap.put(key, element);
final Map.Entry<Object, Object> entry = entries.next();
newMap.put(entry.getKey(), doCopy(entry.getValue(), baseInterface));
}
return newMap;
}
private static final Set BASIC_TYPES = new HashSet();
private static final Set<Class<?>> BASIC_TYPES = new HashSet<Class<?>>();
static {
BASIC_TYPES.add(Boolean.class);
@ -176,7 +175,7 @@ public class CopyFromHelper {
BASIC_TYPES.add(Date.class);
}
private boolean isBasicType(final Class vClass) {
private boolean isBasicType(final Class<?> vClass) {
return BASIC_TYPES.contains(vClass);
}

View file

@ -43,6 +43,7 @@ import java.util.Set;
*
*/
public class ObjectBean implements Serializable, Cloneable {
private static final long serialVersionUID = -8784981605711980095L;
private final EqualsBean equalsBean;
private final ToStringBean toStringBean;
private final CloneableBean cloneableBean;
@ -54,7 +55,7 @@ public class ObjectBean implements Serializable, Cloneable {
* @param beanClass the class/interface to be used for property scanning.
*
*/
public ObjectBean(final Class beanClass, final Object obj) {
public ObjectBean(final Class<?> beanClass, final Object obj) {
this(beanClass, obj, null);
}
@ -74,7 +75,7 @@ public class ObjectBean implements Serializable, Cloneable {
* @param ignoreProperties properties to ignore when cloning.
*
*/
public ObjectBean(final Class beanClass, final Object obj, final Set ignoreProperties) {
public ObjectBean(final Class<?> beanClass, final Object obj, final Set<String> ignoreProperties) {
equalsBean = new EqualsBean(beanClass, obj);
toStringBean = new ToStringBean(beanClass, obj);
cloneableBean = new CloneableBean(obj, ignoreProperties);

View file

@ -19,8 +19,6 @@ package com.sun.syndication.feed.module;
import java.util.Date;
import java.util.List;
import com.sun.syndication.feed.CopyFrom;
/**
* Dublin Core Module.
* <p>
@ -30,7 +28,7 @@ import com.sun.syndication.feed.CopyFrom;
* @author Alejandro Abdelnur
*
*/
public interface DCModule extends Module, CopyFrom {
public interface DCModule extends Module {
/**
* URI of the Dublin Core Module (http://purl.org/dc/elements/1.1/).

View file

@ -39,6 +39,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
*
*/
public class DCModuleImpl extends ModuleImpl implements DCModule {
private static final long serialVersionUID = -6502372914221178645L;
private final ObjectBean objBean;
private List<String> title;
private List<String> creator;
@ -940,19 +941,19 @@ public class DCModuleImpl extends ModuleImpl implements DCModule {
}
@Override
public final Class<? extends CopyFrom> getInterface() {
public final Class<DCModule> getInterface() {
return DCModule.class;
}
@Override
public final void copyFrom(final CopyFrom obj) {
public final void copyFrom(final CopyFrom<?> obj) {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map basePropInterfaceMap = new HashMap();
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("titles", String.class);
basePropInterfaceMap.put("creators", String.class);
basePropInterfaceMap.put("subjects", DCSubject.class);
@ -969,7 +970,7 @@ public class DCModuleImpl extends ModuleImpl implements DCModule {
basePropInterfaceMap.put("coverages", String.class);
basePropInterfaceMap.put("rightsList", String.class);
final Map basePropClassImplMap = new HashMap();
final Map<Class<? extends CopyFrom<?>>, Class<?>> basePropClassImplMap = new HashMap<Class<? extends CopyFrom<?>>, Class<?>>();
basePropClassImplMap.put(DCSubject.class, DCSubjectImpl.class);
COPY_FROM_HELPER = new CopyFromHelper(DCModule.class, basePropInterfaceMap, basePropClassImplMap);

View file

@ -27,7 +27,7 @@ import com.sun.syndication.feed.CopyFrom;
* @author Alejandro Abdelnur
*
*/
public interface DCSubject extends Cloneable, CopyFrom {
public interface DCSubject extends Cloneable, CopyFrom<DCSubject> {
/**
* Returns the DublinCore subject taxonomy URI.
* <p>

View file

@ -35,6 +35,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
*
*/
public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
private static final long serialVersionUID = 6276396184267118968L;
private final ObjectBean objBean;
private String taxonomyUri;
private String value;
@ -155,23 +156,23 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
}
@Override
public Class getInterface() {
public Class<DCSubject> getInterface() {
return DCSubject.class;
}
@Override
public void copyFrom(final CopyFrom obj) {
public void copyFrom(final CopyFrom<?> obj) {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map basePropInterfaceMap = new HashMap();
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("taxonomyUri", String.class);
basePropInterfaceMap.put("value", String.class);
final Map basePropClassImplMap = Collections.EMPTY_MAP;
final Map<Class<? extends CopyFrom<?>>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom<?>>, Class<?>>emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(DCSubject.class, basePropInterfaceMap, basePropClassImplMap);
}

View file

@ -28,7 +28,7 @@ import com.sun.syndication.feed.CopyFrom;
* @author Alejandro Abdelnur
*
*/
public interface Module extends Cloneable, CopyFrom, Serializable {
public interface Module extends Cloneable, CopyFrom<Module>, Serializable {
/**
* Returns the URI of the module.

View file

@ -13,6 +13,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
* @author Alejandro Abdelnur
*/
public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
private static final long serialVersionUID = -5813049622142257411L;
private final ObjectBean objBean;
private String url;
private String type;
@ -148,24 +149,24 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
}
@Override
public Class<? extends CopyFrom> getInterface() {
public Class<SyndEnclosure> getInterface() {
return SyndEnclosure.class;
}
@Override
public void copyFrom(final CopyFrom obj) {
public void copyFrom(final CopyFrom<?> obj) {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map basePropInterfaceMap = new HashMap();
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("url", String.class);
basePropInterfaceMap.put("type", String.class);
basePropInterfaceMap.put("length", Long.TYPE);
final Map basePropClassImplMap = Collections.EMPTY_MAP;
final Map<Class<? extends CopyFrom<?>>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom<?>>, Class<?>>emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndEnclosure.class, basePropInterfaceMap, basePropClassImplMap);
}

View file

@ -32,7 +32,7 @@ import com.sun.syndication.feed.module.Module;
* @author Alejandro Abdelnur
*
*/
public interface SyndEntry extends Cloneable, CopyFrom, Extendable {
public interface SyndEntry extends Cloneable, CopyFrom<SyndEntry>, Extendable {
/**
* Returns the entry URI.

View file

@ -47,6 +47,7 @@ import com.sun.syndication.feed.synd.impl.URINormalizer;
*
*/
public class SyndEntryImpl implements Serializable, SyndEntry {
private static final long serialVersionUID = 1944144041409866698L;
private final ObjectBean objBean;
private String uri;
private String link;
@ -94,7 +95,7 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* CloneableBean for details).
*
*/
protected SyndEntryImpl(final Class beanClass, final Set convenienceProperties) {
protected SyndEntryImpl(final Class<?> beanClass, final Set<String> convenienceProperties) {
objBean = new ObjectBean(beanClass, this, convenienceProperties);
}
@ -483,19 +484,19 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
}
@Override
public Class getInterface() {
public Class<SyndEntry> getInterface() {
return SyndEntry.class;
}
@Override
public void copyFrom(final CopyFrom obj) {
public void copyFrom(final CopyFrom<?> obj) {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map basePropInterfaceMap = new HashMap();
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("uri", String.class);
basePropInterfaceMap.put("title", String.class);
basePropInterfaceMap.put("link", String.class);
@ -505,7 +506,7 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
basePropInterfaceMap.put("enclosures", SyndEnclosure.class);
basePropInterfaceMap.put("modules", Module.class);
final Map basePropClassImplMap = new HashMap();
final Map<Class<? extends CopyFrom<?>>, Class<?>> basePropClassImplMap = new HashMap<Class<? extends CopyFrom<?>>, Class<?>>();
basePropClassImplMap.put(SyndContent.class, SyndContentImpl.class);
basePropClassImplMap.put(SyndEnclosure.class, SyndEnclosureImpl.class);
basePropClassImplMap.put(DCModule.class, DCModuleImpl.class);

View file

@ -36,7 +36,7 @@ import com.sun.syndication.feed.module.Module;
* @author Alejandro Abdelnur
*
*/
public interface SyndFeed extends Cloneable, CopyFrom, Extendable {
public interface SyndFeed extends Cloneable, CopyFrom<SyndFeed>, Extendable {
/**
* Returns the real feed types the SyndFeedImpl supports when converting

View file

@ -26,7 +26,7 @@ import com.sun.syndication.feed.CopyFrom;
* @author Alejandro Abdelnur
*
*/
public interface SyndImage extends Cloneable, CopyFrom {
public interface SyndImage extends Cloneable, CopyFrom<SyndImage> {
/**
* Returns the image title.
* <p>

View file

@ -33,6 +33,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
*
*/
public class SyndImageImpl implements Serializable, SyndImage {
private static final long serialVersionUID = 5078981553559513247L;
private final ObjectBean objBean;
private String title;
private String url;
@ -199,25 +200,25 @@ public class SyndImageImpl implements Serializable, SyndImage {
}
@Override
public Class getInterface() {
public Class<SyndImage> getInterface() {
return SyndImage.class;
}
@Override
public void copyFrom(final CopyFrom syndImage) {
public void copyFrom(final CopyFrom<?> syndImage) {
COPY_FROM_HELPER.copy(this, syndImage);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map basePropInterfaceMap = new HashMap();
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("title", String.class);
basePropInterfaceMap.put("url", String.class);
basePropInterfaceMap.put("link", String.class);
basePropInterfaceMap.put("description", String.class);
final Map basePropClassImplMap = Collections.EMPTY_MAP;
final Map<Class<? extends CopyFrom<?>>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom<?>>, Class<?>>emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndImage.class, basePropInterfaceMap, basePropClassImplMap);
}

View file

@ -29,6 +29,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
* @author Dave Johnson (updated for Atom 1.0)
*/
public class SyndLinkImpl implements Cloneable, Serializable, SyndLink {
private static final long serialVersionUID = -3620141754437170078L;
private final ObjectBean objBean;

View file

@ -33,6 +33,7 @@ import com.sun.syndication.feed.module.impl.ModuleUtils;
*
*/
public class SyndPersonImpl implements Serializable, SyndPerson {
private static final long serialVersionUID = 8523373264589239335L;
private final ObjectBean objBean;
private String name;
private String uri;

View file

@ -108,7 +108,7 @@ public class ConverterForAtom03 implements Converter {
syndFeed.setLanguage(language);
}
final List<Person> authors = aFeed.getAuthors();
final List<SyndPerson> authors = aFeed.getAuthors();
if (authors != null && authors.size() > 0) {
syndFeed.setAuthors(createSyndPersons(authors));
}
@ -232,7 +232,7 @@ public class ConverterForAtom03 implements Converter {
syndEntry.setContents(sContents);
}
final List<Person> authors = entry.getAuthors();
final List<SyndPerson> authors = entry.getAuthors();
if (authors != null && authors.size() > 0) {
syndEntry.setAuthors(createSyndPersons(authors));
final SyndPerson person0 = syndEntry.getAuthors().get(0);
@ -341,8 +341,8 @@ public class ConverterForAtom03 implements Converter {
return aFeed;
}
protected static List<Person> createAtomPersons(final List<SyndPerson> sPersons) {
final List<Person> persons = new ArrayList<Person>();
protected static List<SyndPerson> createAtomPersons(final List<SyndPerson> sPersons) {
final List<SyndPerson> persons = new ArrayList<SyndPerson>();
for (final SyndPerson syndPerson : sPersons) {
final SyndPerson sPerson = syndPerson;
final Person person = new Person();
@ -355,15 +355,14 @@ public class ConverterForAtom03 implements Converter {
return persons;
}
protected static List<SyndPerson> createSyndPersons(final List<Person> aPersons) {
protected static List<SyndPerson> createSyndPersons(final List<SyndPerson> aPersons) {
final List<SyndPerson> persons = new ArrayList<SyndPerson>();
for (final Person person2 : aPersons) {
final Person aPerson = person2;
for (final SyndPerson person2 : aPersons) {
final SyndPerson person = new SyndPersonImpl();
person.setName(aPerson.getName());
person.setUri(aPerson.getUri());
person.setEmail(aPerson.getEmail());
person.setModules(aPerson.getModules());
person.setName(person2.getName());
person.setUri(person2.getUri());
person.setEmail(person2.getEmail());
person.setModules(person2.getModules());
persons.add(person);
}
return persons;
@ -467,7 +466,7 @@ public class ConverterForAtom03 implements Converter {
} else if (sEntry.getAuthor() != null) {
final Person person = new Person();
person.setName(sEntry.getAuthor());
final List<Person> authors = new ArrayList<Person>();
final List<SyndPerson> authors = new ArrayList<SyndPerson>();
authors.add(person);
aEntry.setAuthors(authors);
}

View file

@ -114,12 +114,12 @@ public class ConverterForAtom10 implements Converter {
// Core Atom language/author/copyright/modified elements have precedence
// over DC equivalent info.
final List<Person> authors = aFeed.getAuthors();
final List<SyndPerson> authors = aFeed.getAuthors();
if (authors != null && authors.size() > 0) {
syndFeed.setAuthors(ConverterForAtom03.createSyndPersons(authors));
}
final List<Person> contributors = aFeed.getContributors();
final List<SyndPerson> contributors = aFeed.getContributors();
if (contributors != null && contributors.size() > 0) {
syndFeed.setContributors(ConverterForAtom03.createSyndPersons(contributors));
}
@ -185,14 +185,14 @@ public class ConverterForAtom10 implements Converter {
syndEntry.setContents(sContents);
}
final List<Person> authors = entry.getAuthors();
final List<SyndPerson> authors = entry.getAuthors();
if (authors != null && authors.size() > 0) {
syndEntry.setAuthors(ConverterForAtom03.createSyndPersons(authors));
final SyndPerson person0 = syndEntry.getAuthors().get(0);
syndEntry.setAuthor(person0.getName());
}
final List<Person> contributors = entry.getContributors();
final List<SyndPerson> contributors = entry.getContributors();
if (contributors != null && contributors.size() > 0) {
syndEntry.setContributors(ConverterForAtom03.createSyndPersons(contributors));
}
@ -520,13 +520,13 @@ public class ConverterForAtom10 implements Converter {
final List<SyndContent> syndContents = sEntry.getContents();
aEntry.setContents(createAtomContents(syndContents));
List authors = sEntry.getAuthors();
List<SyndPerson> authors = sEntry.getAuthors();
if (authors != null && authors.size() > 0) {
aEntry.setAuthors(ConverterForAtom03.createAtomPersons(authors));
} else if (sEntry.getAuthor() != null) {
final Person person = new Person();
person.setName(sEntry.getAuthor());
authors = new ArrayList();
authors = new ArrayList<SyndPerson>();
authors.add(person);
aEntry.setAuthors(authors);
}

View file

@ -26,6 +26,8 @@ package com.sun.syndication.io;
*/
public class FeedException extends Exception {
private static final long serialVersionUID = -8761681574235401334L;
/**
* Creates a FeedException with a message.
* <p>

View file

@ -19,6 +19,7 @@ package com.sun.syndication.io;
import java.util.Set;
import org.jdom2.Element;
import org.jdom2.Namespace;
import com.sun.syndication.feed.module.Module;
@ -56,7 +57,7 @@ public interface ModuleGenerator {
* @return a set with all the URIs (JDOM Namespace elements) this module
* generator uses.
*/
public Set getNamespaces();
public Set<Namespace> getNamespaces();
/**
* Generates and injects module metadata into an XML node (JDOM element).

View file

@ -27,6 +27,8 @@ import org.jdom2.input.JDOMParseException;
*/
public class ParsingFeedException extends FeedException {
private static final long serialVersionUID = -4791878470117677698L;
/**
* Creates a FeedException with a message.
* <p>

View file

@ -57,11 +57,11 @@ import com.sun.syndication.io.impl.XmlFixerReader;
*/
public class WireFeedInput {
private static Map clMap = new WeakHashMap();
private static Map<ClassLoader, FeedParsers> clMap = new WeakHashMap<ClassLoader, FeedParsers>();
private static FeedParsers getFeedParsers() {
synchronized (WireFeedInput.class) {
FeedParsers parsers = (FeedParsers) clMap.get(Thread.currentThread().getContextClassLoader());
FeedParsers parsers = clMap.get(Thread.currentThread().getContextClassLoader());
if (parsers == null) {
parsers = new FeedParsers();
clMap.put(Thread.currentThread().getContextClassLoader(), parsers);
@ -96,7 +96,7 @@ public class WireFeedInput {
* @return a list of String elements with the supported input feed types.
*
*/
public static List getSupportedFeedTypes() {
public static List<String> getSupportedFeedTypes() {
return getFeedParsers().getSupportedFeedTypes();
}

View file

@ -46,7 +46,7 @@ import com.sun.syndication.io.impl.FeedGenerators;
*
*/
public class WireFeedOutput {
private static Map clMap = new WeakHashMap();
private static Map<ClassLoader, FeedGenerators> clMap = new WeakHashMap<ClassLoader, FeedGenerators>();
private static FeedGenerators getFeedGenerators() {
synchronized (WireFeedOutput.class) {
@ -68,7 +68,7 @@ public class WireFeedOutput {
* @return a list of String elements with the supported output feed types.
*
*/
public static List getSupportedFeedTypes() {
public static List<String> getSupportedFeedTypes() {
return getFeedGenerators().getSupportedFeedTypes();
}

View file

@ -18,6 +18,7 @@ import java.io.InputStream;
*
*/
public class XmlReaderException extends IOException {
private static final long serialVersionUID = 622706428081721579L;
private final String bomEncoding;
private final String xmlGuessEncoding;
private final String xmlEncoding;

View file

@ -31,7 +31,7 @@ import com.sun.syndication.feed.atom.Entry;
import com.sun.syndication.feed.atom.Feed;
import com.sun.syndication.feed.atom.Generator;
import com.sun.syndication.feed.atom.Link;
import com.sun.syndication.feed.atom.Person;
import com.sun.syndication.feed.synd.SyndPerson;
import com.sun.syndication.io.FeedException;
/**
@ -138,7 +138,7 @@ public class Atom03Generator extends BaseWireFeedGenerator {
eFeed.addContent(authorElement);
}
final List<Person> contributors = feed.getContributors();
final List<SyndPerson> contributors = feed.getContributors();
for (int i = 0; i < contributors.size(); i++) {
final Element contributorElement = new Element("contributor", getFeedNamespace());
fillPersonElement(contributorElement, contributors.get(i));
@ -198,7 +198,7 @@ public class Atom03Generator extends BaseWireFeedGenerator {
eEntry.addContent(authorElement);
}
final List<Person> contributors = entry.getContributors();
final List<SyndPerson> contributors = entry.getContributors();
for (int i = 0; i < contributors.size(); i++) {
final Element contributorElement = new Element("contributor", getFeedNamespace());
fillPersonElement(contributorElement, contributors.get(i));
@ -271,12 +271,12 @@ public class Atom03Generator extends BaseWireFeedGenerator {
return linkElement;
}
protected void fillPersonElement(final Element element, final Person person) {
protected void fillPersonElement(final Element element, final SyndPerson person) {
if (person.getName() != null) {
element.addContent(generateSimpleElement("name", person.getName()));
}
if (person.getUrl() != null) {
element.addContent(generateSimpleElement("url", person.getUrl()));
if (person.getUri() != null) {
element.addContent(generateSimpleElement("url", person.getUri()));
}
if (person.getEmail() != null) {

View file

@ -31,6 +31,7 @@ import com.sun.syndication.feed.atom.Entry;
import com.sun.syndication.feed.atom.Generator;
import com.sun.syndication.feed.atom.Link;
import com.sun.syndication.feed.atom.Person;
import com.sun.syndication.feed.synd.SyndPerson;
import com.sun.syndication.io.FeedException;
/**
@ -92,7 +93,7 @@ public class Atom03Parser extends BaseWireFeedParser {
e = eFeed.getChild("author", getAtomNamespace());
if (e != null) {
final List<Person> authors = new ArrayList<Person>();
final List<SyndPerson> authors = new ArrayList<SyndPerson>();
authors.add(parsePerson(e));
feed.setAuthors(authors);
}
@ -220,8 +221,8 @@ public class Atom03Parser extends BaseWireFeedParser {
}
// List(Elements) -> List(Persons)
private List<Person> parsePersons(final List<Element> ePersons) {
final List<Person> persons = new ArrayList<Person>();
private List<SyndPerson> parsePersons(final List<Element> ePersons) {
final List<SyndPerson> persons = new ArrayList<SyndPerson>();
for (int i = 0; i < ePersons.size(); i++) {
persons.add(parsePerson(ePersons.get(i)));
}
@ -287,7 +288,7 @@ public class Atom03Parser extends BaseWireFeedParser {
e = eEntry.getChild("author", getAtomNamespace());
if (e != null) {
final List<Person> authors = new ArrayList<Person>();
final List<SyndPerson> authors = new ArrayList<SyndPerson>();
authors.add(parsePerson(e));
entry.setAuthors(authors);
}

View file

@ -36,7 +36,7 @@ import com.sun.syndication.feed.atom.Entry;
import com.sun.syndication.feed.atom.Feed;
import com.sun.syndication.feed.atom.Generator;
import com.sun.syndication.feed.atom.Link;
import com.sun.syndication.feed.atom.Person;
import com.sun.syndication.feed.synd.SyndPerson;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.WireFeedOutput;
@ -157,7 +157,7 @@ public class Atom10Generator extends BaseWireFeedGenerator {
}
}
final List<Person> authors = feed.getAuthors();
final List<SyndPerson> authors = feed.getAuthors();
if (authors != null && authors.size() > 0) {
for (int i = 0; i < authors.size(); i++) {
final Element authorElement = new Element("author", getFeedNamespace());
@ -166,7 +166,7 @@ public class Atom10Generator extends BaseWireFeedGenerator {
}
}
final List<Person> contributors = feed.getContributors();
final List<SyndPerson> contributors = feed.getContributors();
if (contributors != null && contributors.size() > 0) {
for (int i = 0; i < contributors.size(); i++) {
final Element contributorElement = new Element("contributor", getFeedNamespace());
@ -234,7 +234,7 @@ public class Atom10Generator extends BaseWireFeedGenerator {
}
}
final List<Person> authors = entry.getAuthors();
final List<SyndPerson> authors = entry.getAuthors();
if (authors != null && authors.size() > 0) {
for (int i = 0; i < authors.size(); i++) {
final Element authorElement = new Element("author", getFeedNamespace());
@ -243,7 +243,7 @@ public class Atom10Generator extends BaseWireFeedGenerator {
}
}
final List<Person> contributors = entry.getContributors();
final List<SyndPerson> contributors = entry.getContributors();
if (contributors != null && contributors.size() > 0) {
for (int i = 0; i < contributors.size(); i++) {
final Element contributorElement = new Element("contributor", getFeedNamespace());
@ -349,7 +349,7 @@ public class Atom10Generator extends BaseWireFeedGenerator {
return linkElement;
}
protected void fillPersonElement(final Element element, final Person person) {
protected void fillPersonElement(final Element element, final SyndPerson person) {
if (person.getName() != null) {
element.addContent(generateSimpleElement("name", person.getName()));
}

View file

@ -41,6 +41,7 @@ import com.sun.syndication.feed.atom.Feed;
import com.sun.syndication.feed.atom.Generator;
import com.sun.syndication.feed.atom.Link;
import com.sun.syndication.feed.atom.Person;
import com.sun.syndication.feed.synd.SyndPerson;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.WireFeedInput;
import com.sun.syndication.io.WireFeedOutput;
@ -293,8 +294,8 @@ public class Atom10Parser extends BaseWireFeedParser {
}
// List(Elements) -> List(Persons)
private List<Person> parsePersons(final String baseURI, final List<Element> ePersons) {
final List<Person> persons = new ArrayList<Person>();
private List<SyndPerson> parsePersons(final String baseURI, final List<Element> ePersons) {
final List<SyndPerson> persons = new ArrayList<SyndPerson>();
for (int i = 0; i < ePersons.size(); i++) {
persons.add(parsePerson(baseURI, ePersons.get(i)));
}
@ -594,7 +595,6 @@ public class Atom10Parser extends BaseWireFeedParser {
base = stripTrailingSlash(base);
append = stripStartingSlash(append);
if (append.startsWith("..")) {
final String ret = null;
final String[] parts = append.split("/");
for (final String part : parts) {
if ("..".equals(part)) {

View file

@ -1,5 +1,6 @@
package com.sun.syndication.io.impl;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -9,6 +10,7 @@ import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.Parent;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.io.WireFeedGenerator;
/**
@ -42,8 +44,8 @@ public abstract class BaseWireFeedGenerator implements WireFeedGenerator {
feedModuleGenerators = new ModuleGenerators(type + FEED_MODULE_GENERATORS_POSFIX_KEY, this);
itemModuleGenerators = new ModuleGenerators(type + ITEM_MODULE_GENERATORS_POSFIX_KEY, this);
personModuleGenerators = new ModuleGenerators(type + PERSON_MODULE_GENERATORS_POSFIX_KEY, this);
final Set allModuleNamespaces = new HashSet();
Iterator i = feedModuleGenerators.getAllNamespaces().iterator();
final Set<Namespace> allModuleNamespaces = new HashSet<Namespace>();
Iterator<Namespace> i = feedModuleGenerators.getAllNamespaces().iterator();
while (i.hasNext()) {
allModuleNamespaces.add(i.next());
}
@ -70,21 +72,21 @@ public abstract class BaseWireFeedGenerator implements WireFeedGenerator {
}
}
protected void generateFeedModules(final List modules, final Element feed) {
protected void generateFeedModules(final List<Module> modules, final Element feed) {
feedModuleGenerators.generateModules(modules, feed);
}
public void generateItemModules(final List modules, final Element item) {
public void generateItemModules(final List<Module> modules, final Element item) {
itemModuleGenerators.generateModules(modules, item);
}
public void generatePersonModules(final List modules, final Element person) {
public void generatePersonModules(final List<Module> modules, final Element person) {
personModuleGenerators.generateModules(modules, person);
}
protected void generateForeignMarkup(final Element e, final List foreignMarkup) {
protected void generateForeignMarkup(final Element e, final List<Element> foreignMarkup) {
if (foreignMarkup != null) {
final Iterator elems = foreignMarkup.iterator();
final Iterator<Element> elems = foreignMarkup.iterator();
while (elems.hasNext()) {
final Element elem = (Element) elems.next();
final Parent parent = elem.getParent();
@ -109,17 +111,17 @@ public abstract class BaseWireFeedGenerator implements WireFeedGenerator {
* make sure their namespace declarations are present.
*/
protected static void purgeUnusedNamespaceDeclarations(final Element root) {
final java.util.Set usedPrefixes = new java.util.HashSet();
final Set<String> usedPrefixes = new HashSet<String>();
collectUsedPrefixes(root, usedPrefixes);
final List list = root.getAdditionalNamespaces();
final List additionalNamespaces = new java.util.ArrayList();
final List<Namespace> list = root.getAdditionalNamespaces();
final List<Namespace> additionalNamespaces = new ArrayList<Namespace>();
additionalNamespaces.addAll(list); // the duplication will prevent a
// ConcurrentModificationException
// below
for (int i = 0; i < additionalNamespaces.size(); i++) {
final Namespace ns = (Namespace) additionalNamespaces.get(i);
final Namespace ns = additionalNamespaces.get(i);
final String prefix = ns.getPrefix();
if (prefix != null && prefix.length() > 0 && !usedPrefixes.contains(prefix)) {
root.removeNamespaceDeclaration(ns);
@ -127,12 +129,12 @@ public abstract class BaseWireFeedGenerator implements WireFeedGenerator {
}
}
private static void collectUsedPrefixes(final Element el, final java.util.Set collector) {
private static void collectUsedPrefixes(final Element el, final Set<String> collector) {
final String prefix = el.getNamespacePrefix();
if (prefix != null && prefix.length() > 0 && !collector.contains(prefix)) {
collector.add(prefix);
}
final List kids = el.getChildren();
final List<Element> kids = el.getChildren();
for (int i = 0; i < kids.size(); i++) {
collectUsedPrefixes((Element) kids.get(i), collector); // recursion
// - worth it

View file

@ -75,6 +75,7 @@ public class DateParser {
* are a lot more forgiving than what the Atom spec allows. The forms that
* are invalid according to the spec are indicated.
*/
@SuppressWarnings("unused")
private static final String[] masks = { "yyyy-MM-dd'T'HH:mm:ss.SSSz", "yyyy-MM-dd't'HH:mm:ss.SSSz", // invalid
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd't'HH:mm:ss.SSS'z'", // invalid
"yyyy-MM-dd'T'HH:mm:ssz", "yyyy-MM-dd't'HH:mm:ssz", // invalid

View file

@ -36,7 +36,7 @@ import com.sun.syndication.io.WireFeedGenerator;
* @author Alejandro Abdelnur
*
*/
public class FeedGenerators extends PluginManager {
public class FeedGenerators extends PluginManager<WireFeedGenerator> {
/**
* WireFeedGenerator.classes= [className] ...
@ -49,7 +49,7 @@ public class FeedGenerators extends PluginManager {
}
public WireFeedGenerator getGenerator(final String feedType) {
return (WireFeedGenerator) getPlugin(feedType);
return getPlugin(feedType);
}
@Override
@ -57,7 +57,7 @@ public class FeedGenerators extends PluginManager {
return ((WireFeedGenerator) obj).getType();
}
public List getSupportedFeedTypes() {
public List<String> getSupportedFeedTypes() {
return getKeys();
}

View file

@ -40,7 +40,7 @@ import com.sun.syndication.io.WireFeedParser;
* @author Alejandro Abdelnur
*
*/
public class FeedParsers extends PluginManager {
public class FeedParsers extends PluginManager<WireFeedParser> {
/**
* WireFeedParser.classes= [className] ...
@ -57,7 +57,7 @@ public class FeedParsers extends PluginManager {
super(FEED_PARSERS_KEY);
}
public List getSupportedFeedTypes() {
public List<String> getSupportedFeedTypes() {
return getKeys();
}
@ -71,7 +71,7 @@ public class FeedParsers extends PluginManager {
*
*/
public WireFeedParser getParserFor(final Document document) {
final List parsers = getPlugins();
final List<WireFeedParser> parsers = getPlugins();
WireFeedParser parser = null;
for (int i = 0; parser == null && i < parsers.size(); i++) {
parser = (WireFeedParser) parsers.get(i);

View file

@ -22,14 +22,15 @@ import java.util.Map;
import java.util.Set;
import org.jdom2.Element;
import org.jdom2.Namespace;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.io.ModuleGenerator;
/**
*/
public class ModuleGenerators extends PluginManager {
private Set allNamespaces;
public class ModuleGenerators extends PluginManager<ModuleGenerator> {
private Set<Namespace> allNamespaces;
public ModuleGenerators(final String propertyKey, final BaseWireFeedGenerator parentGenerator) {
super(propertyKey, null, parentGenerator);
@ -44,28 +45,28 @@ public class ModuleGenerators extends PluginManager {
return ((ModuleGenerator) obj).getNamespaceUri();
}
public List getModuleNamespaces() {
public List<String> getModuleNamespaces() {
return getKeys();
}
public void generateModules(final List modules, final Element element) {
final Map generators = getPluginMap();
public void generateModules(final List<Module> modules, final Element element) {
final Map<String, ModuleGenerator> generators = getPluginMap();
for (int i = 0; i < modules.size(); i++) {
final Module module = (Module) modules.get(i);
final Module module = modules.get(i);
final String namespaceUri = module.getUri();
final ModuleGenerator generator = (ModuleGenerator) generators.get(namespaceUri);
final ModuleGenerator generator = generators.get(namespaceUri);
if (generator != null) {
generator.generate(module, element);
}
}
}
public Set getAllNamespaces() {
public Set<Namespace> getAllNamespaces() {
if (allNamespaces == null) {
allNamespaces = new HashSet();
final List mUris = getModuleNamespaces();
allNamespaces = new HashSet<Namespace>();
final List<String> mUris = getModuleNamespaces();
for (int i = 0; i < mUris.size(); i++) {
final ModuleGenerator mGen = getGenerator((String) mUris.get(i));
final ModuleGenerator mGen = getGenerator(mUris.get(i));
allNamespaces.addAll(mGen.getNamespaces());
}
}

View file

@ -28,7 +28,7 @@ import com.sun.syndication.io.WireFeedParser;
/**
*/
public class ModuleParsers extends PluginManager {
public class ModuleParsers extends PluginManager<ModuleParser> {
public ModuleParsers(final String propertyKey, final WireFeedParser parentParser) {
super(propertyKey, parentParser, null);
}
@ -38,7 +38,7 @@ public class ModuleParsers extends PluginManager {
return ((ModuleParser) obj).getNamespaceUri();
}
public List getModuleNamespaces() {
public List<String> getModuleNamespaces() {
return getKeys();
}

View file

@ -34,11 +34,11 @@ import com.sun.syndication.io.WireFeedParser;
* @author Alejandro Abdelnur
*
*/
public abstract class PluginManager {
public abstract class PluginManager<T> {
private final String[] propertyValues;
private Map pluginsMap;
private List pluginsList;
private final List keys;
private Map<String, T> pluginsMap;
private List<T> pluginsList;
private final List<String> keys;
private final WireFeedParser parentParser;
private final WireFeedGenerator parentGenerator;
@ -60,39 +60,39 @@ public abstract class PluginManager {
loadPlugins();
pluginsMap = Collections.unmodifiableMap(pluginsMap);
pluginsList = Collections.unmodifiableList(pluginsList);
keys = Collections.unmodifiableList(new ArrayList(pluginsMap.keySet()));
keys = Collections.unmodifiableList(new ArrayList<String>(pluginsMap.keySet()));
}
protected abstract String getKey(Object obj);
protected List getKeys() {
protected List<String> getKeys() {
return keys;
}
protected List getPlugins() {
protected List<T> getPlugins() {
return pluginsList;
}
protected Map getPluginMap() {
protected Map<String, T> getPluginMap() {
return pluginsMap;
}
protected Object getPlugin(final String key) {
protected T getPlugin(final String key) {
return pluginsMap.get(key);
}
// PRIVATE - LOADER PART
private void loadPlugins() {
final List finalPluginsList = new ArrayList();
pluginsList = new ArrayList();
pluginsMap = new HashMap();
final List<T> finalPluginsList = new ArrayList<T>();
pluginsList = new ArrayList<T>();
pluginsMap = new HashMap<String, T>();
String className = null;
try {
final Class[] classes = getClasses();
for (final Class classe : classes) {
final Class<T>[] classes = getClasses();
for (final Class<T> classe : classes) {
className = classe.getName();
final Object plugin = classe.newInstance();
final T plugin = classe.newInstance();
if (plugin instanceof DelegatingModuleParser) {
((DelegatingModuleParser) plugin).setFeedParser(parentParser);
}
@ -105,7 +105,7 @@ public abstract class PluginManager {
// definition
// in the rome.properties files
}
Iterator i = pluginsMap.values().iterator();
Iterator<T> i = pluginsMap.values().iterator();
while (i.hasNext()) {
finalPluginsList.add(i.next()); // to remove overridden plugin
// impls
@ -140,15 +140,17 @@ public abstract class PluginManager {
* failure is ON.
*
*/
private Class[] getClasses() throws ClassNotFoundException {
private Class<T>[] getClasses() throws ClassNotFoundException {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final List classes = new ArrayList();
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) {
final Class mClass = useLoadClass ? classLoader.loadClass(_propertyValue) : Class.forName(_propertyValue, true, classLoader);
@SuppressWarnings("unchecked")
final Class<T> mClass = (Class<T>) (useLoadClass ? classLoader.loadClass(_propertyValue) : Class.forName(_propertyValue, true, classLoader));
classes.add(mClass);
}
final Class[] array = new Class[classes.size()];
@SuppressWarnings("unchecked")
final Class<T>[] array = (Class<T>[]) new Class[classes.size()];
classes.toArray(array);
return array;
}

View file

@ -28,7 +28,6 @@ import org.jdom2.Element;
*
*/
public class RSS091NetscapeGenerator extends RSS091UserlandGenerator {
private String version;
public RSS091NetscapeGenerator() {
this("rss_0.91N", "0.91");