⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertyexception.java

📁 一个很好的开源项目管理系统源代码
💻 JAVA
字号:
package net.java.workeffort.infrastructure.exception;import java.util.ArrayList;import java.util.List;import org.apache.commons.lang.StringUtils;import org.apache.commons.lang.Validate;import org.apache.commons.lang.builder.ToStringBuilder;/** * Helps in identifying exactly which property created the exception. * @author Antony Joseph */public class PropertyException extends RuntimeException implements        IPropertyException {    private String propertyName;    private Object guiltyObj;    private String collectionName;    private Integer index;    private String errorCode = "property.exception";    public PropertyException() {        super();    }    /**     * @param propertyName Seperate multiple properties using commas.     */    public PropertyException(String propertyName) {        super();        this.propertyName = propertyName;    }    /**     * @return Returns the errorCode.     */    public String getErrorCode() {        return errorCode;    }    /**     * @param errorCode The errorCode to set.     */    public void setErrorCode(String errorCode) {        Validate.notEmpty(errorCode, "errorCode cannot be empty");        this.errorCode = errorCode;    }    /**     * @return Returns the index.     */    public Integer getIndex() {        return index;    }    /**     * @param index The index to set.     */    public void setIndex(Integer index) {        this.index = index;    }    /**     * For indexed items the property will be     * collectionName[index].propertyName. For all others it will be     * propertyName.     * @return the full property name     */    public String getPropertyName() {        if (isMultiProperty())            return "This object has multiple properties. Use getPropertyList()";        if (isIndexed())            return prepareIndexedProperty(collectionName, index, propertyName);        else            return propertyName;    }    public void setPropertyName(String propertyName) {        this.propertyName = propertyName;    }    /**     * @return Returns the collectionName.     */    public String getCollectionName() {        return collectionName;    }    /**     * @param collectionName The collectionName to set.     */    public void setCollectionName(String collectionName) {        this.collectionName = collectionName;    }    /**     * @return Returns the value.     */    public Object getGuiltyObj() {        return guiltyObj;    }    public void setGuiltyObj(Object guiltyObj) {        this.guiltyObj = guiltyObj;    }    public List getPropertyNameList() {        List list = new ArrayList();        if (isMultiProperty()) {            String[] props = StringUtils.split(propertyName, ',');            for (int i = 0; i < props.length; i++) {                String prop = StringUtils.deleteWhitespace(props[i]);                if (isIndexed()) {                    prop = prepareIndexedProperty(collectionName, index, prop);                }                list.add(prop);            }            return list;        }        else            return list; //empty list    }    public boolean isIndexed() {        if (index != null)            return true;        else            return false;    }    public boolean isMultiProperty() {        if (StringUtils.contains(propertyName, ','))            return true;        else            return false;    }    private String prepareIndexedProperty(String collectionName, Integer index,            String name) {        if (collectionName != null && name != null && index != null) {            StringBuffer buf = new StringBuffer(100);            buf.append(collectionName);            buf.append("[");            buf.append(index);            buf.append("].");            buf.append(name);            return buf.toString();        }        else            return null;    }    /** @return string representation */    public String toString() {        return ToStringBuilder.reflectionToString(this);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -