Java tutorial
package com.softech.tbb.bean; import java.sql.Timestamp; import java.util.Map; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.scaffold.lang.ChainedException; import org.apache.commons.scaffold.text.ConvertUtils; import org.apache.commons.scaffold.util.ProcessBeanBase; /** * ValueO * * @version $Revision: 1.1 */ public class Bean extends ProcessBeanBase { // ---------------------------------------------------- Base Properties /** * A generic name field, */ private String keyName = null; /** * A generic value field, */ private String keyValue = null; /** * The marked status of the record. * <p> * Records to be deleted are marked and may be restored before they are * removed from the database. The default value is "0" - not marked. */ private Short marked = ConvertUtils.SHORT_ZERO; // -------------------------------------------------- Search Properties /** * The number of hours * <p> */ private Integer hours = null; /** * The number of articles * <p> */ private Integer articles = null; // ------------------------------------------- Article Table Properties /** * The public key for an article. */ protected Integer article = null; /** * The contributed date of the article, initialized to current system time. */ private Timestamp contributed = ConvertUtils.getTimestamp(); /** * The contributor of the article. */ protected String contributor = null; /** * The creator of the article. * <p> * May also be the contributor. */ protected String creator = null; /** * The cost of the article. * <p> * This is displayed as a headline. */ protected Double cost = null; /** * The title of the article. * <p> * This is displayed as a headline. */ protected String title = null; /** * The content of the article in HTML. */ protected String content = null; /** * Return the keyName. */ public String getKeyName() { return this.keyName; } /** * Set the keyName. * * @param key * The new keyName */ public void setKeyName(String keyName) { this.keyName = keyName; } /** * Return the value. */ public String getKeyValue() { return this.keyValue; } /** * Set the value. * * @param value * The new value */ public void setKeyValue(String keyValue) { this.keyValue = keyValue; } /** * Return the marked status. * <p> * * @return the marked status */ public Short getMarked() { return (this.marked); } /** * Set the marked status. * * @param marked * The new marked status */ public void setMarked(Short marked) { this.marked = marked; } /** * Return the hours * <p> * * @return the hours */ public Integer getHours() { return (this.hours); } /** * Set the hours * * @param hours * The hours */ public void setHours(Integer hours) { this.hours = hours; } /** * Return the number of articles * <p> * * @return the articles */ public Integer getArticles() { return (this.articles); } /** * Set the number of articles * * @param articles * The number of articles */ public void setArticles(Integer articles) { this.articles = articles; } /** * Return the public key for an article. * * @return The public key for an article. */ public Integer getArticle() { return (this.article); } /** * Set the public key for an article. */ public void setArticle(Integer article) { this.article = article; } /** * Return the contributed date of the article. * <p> * * @return the contributed */ public Timestamp getContributed() { return (this.contributed); } /** * Set the contributed date of the article. * <p> * * @param contributed * The new contributed date */ public void setContributed(Timestamp contributed) { this.contributed = contributed; } /** * Return the contributor of the article. * * @return the contributor */ public String getContributor() { return (this.contributor); } /** * Set the contributor of the article. * * @param contributor * The new contributor */ public void setContributor(String contributor) { this.contributor = contributor; } /** * Return the creator of the article. * <p> * * @return the creator */ public String getCreator() { return (this.creator); } /** * Set the creator of the article. * <p> * * @param creator * The new creator */ public void setCreator(String creator) { this.creator = creator; } /** * Return the cost of the article. * * @return the cost */ public Double getCost() { return (this.cost); } /** * Set the cost of the article. * * @param cost * The new cost */ public void setCost(Double cost) { this.cost = cost; } /** * Return the title of the article. * * @return the title */ public String getTitle() { return (this.title); } /** * Set the title of the article. * * @param title * The new title */ public void setTitle(String title) { this.title = title; } /** * Return the content of the article. * * @return the content */ public String getContent() { return (this.content); } /** * Set the content of the article. * * @param content * The new content */ public void setContent(String content) { this.content = content; } // ------------------------------------------------------- Public Methods /** * Set the contributed date of the article formatted for display * <p> * * @param contributed * The new contributed date formatted for display */ public void setContributedDisplay(String contributedDisplay) { if (ConvertUtils.isBlank(contributedDisplay)) { this.contributed = ConvertUtils.getTimestamp(); } else { this.contributed = Timestamp.valueOf(contributedDisplay); } } // end setContributedDisplay /** * Set the contributed of the article. * <p> * * @param contributed * The new contributed */ public String getContributedDisplay() { Timestamp contributed = getContributed(); if (contributed == null) { return null; } else { return contributed.toString(); } } // end getContributedDisplay /** * Set the article content from HTML input. * <p> * This method just passes the content through. A later release could * convert HTML to XHTML or some other format for internal storage. * <p> * * @param content * The new HTML content to display */ public void setContentDisplayHtml(String contentDisplayHtml) { this.content = contentDisplayHtml; } // end setContentDisplayHtml /** * Get the article content as HTML. * <p> * This method just passes the content through. A later release could * convert data from an internal format to HTML or XHTML. * <p> * * @param content * The new content */ public String getContentDisplayHtml() { return this.content; } // end getContentDisplayHtml /** * Populate matching properties on given object. Base method uses * <code>BeanUtils.copyProperties</code> and <code>describe()</code>. * * @param o * The object to populate from this object. * @exception Exception * on any error. */ public void populate(Object o) throws Exception { try { BeanUtils.copyProperties(o, describe()); } catch (Throwable t) { throw new ChainedException(t); } } // end populate /** * Return map of properties for this bean. Base method uses * <code>PropertyUtils.describe</code>. Override if some properties * should not be transfered this way, or a property name should be altered. * This will return the actual public properties. * * @exception Exception * on any error. */ public Map describe() throws Exception { try { return PropertyUtils.describe(this); } catch (Throwable t) { throw new ChainedException(t); } } // end describe } // end Bean /* * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowlegement: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, if and * wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived from this * software without prior written permission. For written permission, please * contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" nor may * "Apache" appear in their names without prior written permission of the Apache * Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE * SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many individuals on * behalf of the Apache Software Foundation. For more information on the Apache * Software Foundation, please see <http://www.apache.org/>. * */