【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-AbstractValueObject.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
package com.cownew.PIS.framework.common;
import java.beans.PropertyDescriptor;
import java.util.Collection;
import java.util.Map;
import com.cownew.ctk.common.ExceptionUtils;
import com.cownew.ctk.common.PropertyUtils;
abstract public class AbstractValueObject implements IValueObject
{
public String toString()
{
try
{
StringBuffer sb = new StringBuffer();
PropertyDescriptor[] propDescs = org.apache.commons.beanutils.PropertyUtils
.getPropertyDescriptors(this);
for (int i = 0, n = propDescs.length; i < n; i++)
{
String name = propDescs[i].getName();
if (!org.apache.commons.beanutils.PropertyUtils.isReadable(
this, name))
{
continue;
}
Object propValue = PropertyUtils.getProperty(this, name);
// 为防止对象自引用或者循环引用,造成死循环,因此对于关联属性不进行级联描述
if (propValue instanceof Collection || propValue instanceof Map)
{
sb.append(name).append("=[more...]");
} else if (propValue instanceof IValueObject)
{
String className = propValue.getClass().getName();
sb.append(name).append("=[").append(className).append("]");
} else
{
sb.append(name).append("=[").append(propValue).append("]");
}
}
return sb.toString();
} catch (Exception e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
}