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

📄 valuebean.java

📁 A Java web application, based on Struts and Hibernate, that serves as an online running log. Users m
💻 JAVA
字号:
/* @LICENSE_COPYRIGHT@ */package net.sf.irunninglog.servlet.formbean;import javax.servlet.http.HttpServletRequest;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.struts.action.ActionMapping;import net.sf.irunninglog.servlet.UserContainer;import net.sf.irunninglog.util.ConstantValues;import net.sf.irunninglog.util.Conversions;import net.sf.irunninglog.util.DTO;import net.sf.irunninglog.util.Utilities;/** * Abstract form bean class that acts as a value container. This class * should be used a the parent class for any object that will be used to * represent data in the application's view layer. * * <p/> * * This class provides are the <code>getValues</code> and <code>setValues</code> * methods.  These use the <code>DTO</code> objects to provide a way to * allow <code>ValueBean</code>s to interact with other layers of the * application.  Subclasses should override these as needed to handle any * new fields (values) that they define. * * @author <a href="mailto:allan_e_lewis@yahoo.com">Allan Lewis</a> * @version $Revision: 1.2 $ $Date: 2005/06/23 03:13:54 $ * @since iRunningLog 1.0 * @see DTO */public abstract class ValueBean extends FormBean {    /** <code>Log</code> instance for this class. */    private static final Log LOG = LogFactory.getLog(ValueBean.class);    /**     * Retrieve the value bean's values.  This will return a transfer object     * populated with <code>String</code> representations of any values that     * the value bean wishes to expose.  At this level, this method simply     * instantiates and returns a transfer object.     *     * @return A transfer object representing the for bean's state     */    public DTO getValues() {        DTO valueObject = new DTO();        if (LOG.isDebugEnabled()) {            LOG.debug("getValues: Values contained in this object "                      + valueObject);        }        return valueObject;    }    /**     * Update the value bean's values.  This will pass the supplied transfer     * object to the value bean, which is then responsible for updating any     * internal values based on the contents of the transfer object.  At this     * level, this method does nothing.     *     * @param valueObject Value object containing the new values     *                    to be applied to the value bean     */    public void setValues(DTO valueObject) {        if (LOG.isDebugEnabled()) {            LOG.debug("setValues: Updating the object using these values "                      + valueObject);        }        if (valueObject == null) {            LOG.error("Unable to setValues using a null DTO");            throw new NullPointerException("Unable to setValues using a null"                                           + " DTO");        }    }    /**     * Reset the state of a value bean.  This method can be overridden by     * subclasses to perform any necessary logic.  This     * method is invoked from the 3-argument <code>reset</code> method, which     * is called from the Struts framework during request processing.     *     * @param mapping The mapping used to select this instance     * @param request The servlet request we are processing     * @param container The current user's container object     * @see #reset(ActionMapping, HttpServletRequest)     */    protected void reset(ActionMapping mapping, HttpServletRequest request,                         UserContainer container) {        super.reset(mapping, request, container);        if (LOG.isDebugEnabled()) {            LOG.debug("reset: Does nothing at this level.");        }    }    /**     * Get a representation of a <code>String</code> representing a true/false     * value and convert it into either 'Yes' or 'No'.  This method will never     * throw an exception - any sort of failue will result in a return value     * of 'No'.     *     * @param sBoolean A string containing a true/false value     * @return 'Yes' of the string represents a true value, false otherwise     */    protected String getAsYesNo(String sBoolean) {        boolean bool;        try {            bool = Conversions.stringToBoolean(sBoolean).booleanValue();        } catch (Exception ex) {            bool = false;        }        return bool ? ConstantValues.STRING_YES : ConstantValues.STRING_NO;    }    /**     * Based on an input string, return a non-null representation.  This will     * return ConstantValues.STRING_BLANK if the parameter string is     * <code>null</code> - otherwise the input string will be returned.     *     * @param value The input string     * @return The input value, or  a blank string if the input was     *         <code>null</code>     * @see ConstantValues#STRING_BLANK     */    protected String getValueOrBlank(String value) {        return Utilities.isBlank(value) ? ConstantValues.STRING_BLANK : value;    }    /**     * Custom toString override to provide a meaningful <code>String</code>     * representation of this object.     *     * @return A <code>String</code> representation of this object     */    public String toString() {        StringBuffer buff = new StringBuffer();        buff.append(getClass());        buff.append("[");        buff.append("values=");        buff.append(getValues());        buff.append("]");        return buff.toString();    }}

⌨️ 快捷键说明

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