diff --git a/src/main/java/com/sun/syndication/feed/impl/BeanIntrospector.java b/src/main/java/com/sun/syndication/feed/impl/BeanIntrospector.java index 972ac86..ba22272 100644 --- a/src/main/java/com/sun/syndication/feed/impl/BeanIntrospector.java +++ b/src/main/java/com/sun/syndication/feed/impl/BeanIntrospector.java @@ -24,7 +24,6 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -32,8 +31,7 @@ import java.util.Set; /** * Obtains all property descriptors from a bean (interface or implementation). *
- * The java.beans.Introspector does not process the interfaces hierarchy chain, - * this one does. + * The java.beans.Introspector does not process the interfaces hierarchy chain, this one does. *
*
* @author Alejandro Abdelnur
@@ -42,29 +40,98 @@ import java.util.Set;
public class BeanIntrospector {
private static final Map
- * It works on all read/write properties, recursively. It support all primitive
- * types, Strings, Collections, bean-like objects and multi-dimensional arrays
- * of any of them.
+ * It works on all read/write properties, recursively. It support all primitive types, Strings, Collections, bean-like objects and multi-dimensional arrays of
+ * any of them.
*
- * The hashcode is calculated by getting the hashcode of the Bean String
- * representation.
+ * The hashcode is calculated by getting the hashcode of the Bean String representation.
*
*
* @author Alejandro Abdelnur
*
*/
public class EqualsBean implements Serializable {
+
private static final long serialVersionUID = 9120107899175152601L;
private static final Object[] NO_PARAMS = new Object[0];
@@ -96,12 +95,10 @@ public class EqualsBean implements Serializable {
}
/**
- * Indicates whether some other object is "equal to" this object as defined
- * by the Object equals() method.
+ * Indicates whether some other object is "equal to" this object as defined by the Object equals() method.
*
- * To be used by classes extending EqualsBean. Although it works also for
- * classes using EqualsBean in a delegation pattern, for correctness those
- * classes should use the
+ * To be used by classes extending EqualsBean. Although it works also for classes using EqualsBean in a delegation pattern, for correctness those classes
+ * should use the
*
* @see #beanEquals(Object) beanEquals method.
*
@@ -115,58 +112,53 @@ public class EqualsBean implements Serializable {
}
/**
- * Indicates whether some other object is "equal to" the object passed in
- * the constructor, as defined by the Object equals() method.
+ * Indicates whether some other object is "equal to" the object passed in the constructor, as defined by the Object equals() method.
*
* To be used by classes using EqualsBean in a delegation pattern,
*
* @see #EqualsBean(Class,Object) constructor.
*
* @param obj he reference object with which to compare.
- * @return true if the object passed in the constructor is equal to
- * the 'obj' object.
+ * @return true if the object passed in the constructor is equal to the 'obj' object.
*
*/
public boolean beanEquals(final Object obj) {
+
final Object bean1 = this.obj;
final Object bean2 = obj;
+
boolean eq;
- if (bean1 == null && bean2 == null) {
+
+ if (bean1 == null && bean2 == null) { // both are null
eq = true;
- } else if (bean1 == null || bean2 == null) {
+ } else if (bean1 == null || bean2 == null) { // one of the objects is null
+ eq = false;
+ } else if (!beanClass.isInstance(bean2)) { // not of the same type
eq = false;
} else {
- if (!beanClass.isInstance(bean2)) {
- eq = false;
- } else {
- eq = true;
- try {
- final PropertyDescriptor[] pds = BeanIntrospector.getPropertyDescriptors(beanClass);
- if (pds != null) {
- for (int i = 0; eq && i < pds.length; i++) {
- final Method pReadMethod = pds[i].getReadMethod();
- if (pReadMethod != null && // ensure it has a getter
- // method
- pReadMethod.getDeclaringClass() != Object.class && // filter
- // Object.class
- // getter
- // methods
- pReadMethod.getParameterTypes().length == 0) { // filter
- // getter
- // methods
- // that
- // take
- // parameters
- final Object value1 = pReadMethod.invoke(bean1, NO_PARAMS);
- final Object value2 = pReadMethod.invoke(bean2, NO_PARAMS);
- eq = doEquals(value1, value2);
- }
- }
+ eq = true;
+ try {
+
+ final List
* It follows the contract defined by the Object hashCode() method.
*
- * The hashcode is calculated by getting the hashcode of the Bean String
- * representation.
+ * The hashcode is calculated by getting the hashcode of the Bean String representation.
*
- * To be used by classes extending EqualsBean. Although it works also for
- * classes using EqualsBean in a delegation pattern, for correctness those
- * classes should use the
+ * To be used by classes extending EqualsBean. Although it works also for classes using EqualsBean in a delegation pattern, for correctness those classes
+ * should use the
*
* @see #beanHashCode() beanHashCode method.
*
@@ -198,8 +188,7 @@ public class EqualsBean implements Serializable {
*
* It follows the contract defined by the Object hashCode() method.
*
- * The hashcode is calculated by getting the hashcode of the Bean String
- * representation.
+ * The hashcode is calculated by getting the hashcode of the Bean String representation.
*
* To be used by classes using EqualsBean in a delegation pattern,
*
diff --git a/src/main/java/com/sun/syndication/feed/impl/ObjectBean.java b/src/main/java/com/sun/syndication/feed/impl/ObjectBean.java
index ff5bc29..bfb4c43 100644
--- a/src/main/java/com/sun/syndication/feed/impl/ObjectBean.java
+++ b/src/main/java/com/sun/syndication/feed/impl/ObjectBean.java
@@ -20,21 +20,17 @@ import java.io.Serializable;
import java.util.Set;
/**
- * Convenience class providing clone(), toString(), equals() and hashCode()
- * functionality for Java Beans.
+ * Convenience class providing clone(), toString(), equals() and hashCode() functionality for Java Beans.
*
* It works on all read/write properties, recursively.
*
- * It uses the CloneableBean, EqualsBean and ToStringBean classes in a
- * delegation pattern.
+ * It uses the CloneableBean, EqualsBean and ToStringBean classes in a delegation pattern.
*
*
- * All ObjectBean subclasses having properties that return collections they
- * should never return null if the property has been set to null or if a
- * collection has not been set. They should create and return an empty
- * collection, this empty collection instance should also be set to the
- * corresponding property.
+ * All ObjectBean subclasses having properties that return collections they should never return null if the property has been set to null or if a
+ * collection has not been set. They should create and return an empty collection, this empty collection instance should also be set to the corresponding
+ * property.
*
* All ObjectBean subclasses properties should be live references.
*
@@ -43,7 +39,9 @@ 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;
@@ -62,13 +60,9 @@ public class ObjectBean implements Serializable, Cloneable {
/**
* Constructor.
*
- * The property names in the ignoreProperties Set will not be copied into
- * the cloned instance. This is useful for cases where the Bean has
- * convenience properties (properties that are actually references to other
- * properties or properties of properties). For example SyndFeed and
- * SyndEntry beans have convenience properties, publishedDate, author,
- * copyright and categories all of them mapped to properties in the DC
- * Module.
+ * The property names in the ignoreProperties Set will not be copied into the cloned instance. This is useful for cases where the Bean has convenience
+ * properties (properties that are actually references to other properties or properties of properties). For example SyndFeed and SyndEntry beans have
+ * convenience properties, publishedDate, author, copyright and categories all of them mapped to properties in the DC Module.
*
*
* @param beanClass the class/interface to be used for property scanning.
@@ -86,8 +80,7 @@ public class ObjectBean implements Serializable, Cloneable {
*
*
* @return a clone of the object.
- * @throws CloneNotSupportedException thrown if an element of the object
- * cannot be cloned.
+ * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*/
@Override
@@ -96,8 +89,7 @@ public class ObjectBean implements Serializable, Cloneable {
}
/**
- * Indicates whether some other object is "equal to" this one as defined by
- * the Object equals() method.
+ * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
*
*
* @param other he reference object with which to compare.
diff --git a/src/main/java/com/sun/syndication/feed/impl/ToStringBean.java b/src/main/java/com/sun/syndication/feed/impl/ToStringBean.java
index 3dad8e8..2d99cb1 100644
--- a/src/main/java/com/sun/syndication/feed/impl/ToStringBean.java
+++ b/src/main/java/com/sun/syndication/feed/impl/ToStringBean.java
@@ -22,15 +22,18 @@ import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Stack;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Provides deep Bean toString support.
*
- * It works on all read/write properties, recursively. It support all primitive
- * types, Strings, Collections, ToString objects and multi-dimensional arrays of
+ * It works on all read/write properties, recursively. It support all primitive types, Strings, Collections, ToString objects and multi-dimensional arrays of
* any of them.
*
*
@@ -38,7 +41,9 @@ import java.util.Stack;
*
*/
public class ToStringBean implements Serializable {
+
private static final long serialVersionUID = -5850496718959612854L;
+ private static final Logger LOG = LoggerFactory.getLogger(ToStringBean.class);
private static final ThreadLocal
*
- * @param beanClass indicates the class to scan for properties, normally an
- * interface class.
+ * @param beanClass indicates the class to scan for properties, normally an interface class.
*
*/
protected ToStringBean(final Class> beanClass) {
@@ -93,8 +97,7 @@ public class ToStringBean implements Serializable {
*
*
*
- * @param beanClass indicates the class to scan for properties, normally an
- * interface class.
+ * @param beanClass indicates the class to scan for properties, normally an interface class.
* @param obj object bean to create String representation.
*
*/
@@ -141,32 +144,29 @@ public class ToStringBean implements Serializable {
*
*/
private String toString(final String prefix) {
+
final StringBuffer sb = new StringBuffer(128);
+
try {
- final PropertyDescriptor[] pds = BeanIntrospector.getPropertyDescriptors(beanClass);
- if (pds != null) {
- for (final PropertyDescriptor pd : pds) {
- final String pName = pd.getName();
- final Method pReadMethod = pd.getReadMethod();
- if (pReadMethod != null && // ensure it has a getter method
- pReadMethod.getDeclaringClass() != Object.class && // filter
- // Object.class
- // getter
- // methods
- pReadMethod.getParameterTypes().length == 0) { // filter
- // getter
- // methods
- // that
- // take
- // parameters
- final Object value = pReadMethod.invoke(obj, NO_PARAMS);
- printProperty(sb, prefix + "." + pName, value);
- }
- }
+
+ final ListObjectBean programming conventions
*