AddressDO.java :  » Groupware » ivatagroupware » com » ivata » groupware » business » addressbook » address » Java Open Source

Java Open Source » Groupware » ivatagroupware 
ivatagroupware » com » ivata » groupware » business » addressbook » address » AddressDO.java
/*
 * Copyright (c) 2001 - 2005 ivata limited.
 * All rights reserved.
 * -----------------------------------------------------------------------------
 * ivata groupware may be redistributed under the GNU General Public
 * License as published by the Free Software Foundation;
 * version 2 of the License.
 *
 * These programs are free software; you can redistribute them and/or
 * modify them under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2 of the License.
 *
 * These programs are distributed in the hope that they will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License in the file LICENSE.txt for more
 * details.
 *
 * If you would like a copy of the GNU General Public License write to
 *
 * Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330
 * Boston, MA 02111-1307, USA.
 *
 *
 * To arrange commercial support and licensing, contact ivata at
 *                  http://www.ivata.com/contact.jsp
 * -----------------------------------------------------------------------------
 * $Log: AddressDO.java,v $
 * Revision 1.8  2005/10/11 18:53:06  colinmacleod
 * Fixed some checkstyle and javadoc issues.
 *
 * Revision 1.7  2005/10/02 14:08:55  colinmacleod
 * Added/improved log4j logging.
 *
 * Revision 1.6  2005/09/29 13:22:44  colinmacleod
 * Added read-only functionality to data object classes (with a check on each
 * setter).
 *
 * Revision 1.5  2005/09/14 14:38:48  colinmacleod
 * Re-ordered methods alphabetically.
 * Added serialVersionUID.
 *
 * Revision 1.4  2005/04/30 13:00:25  colinmacleod
 * Added getId override for one-to-one relationship.
 *
 * Revision 1.3  2005/04/10 20:09:34  colinmacleod
 * Added new themes.
 * Changed id type to String.
 * Changed i tag to em and b tag to strong.
 * Improved PicoContainerFactory with NanoContainer scripts.
 *
 * Revision 1.2  2005/04/09 17:19:06  colinmacleod
 * Changed copyright text to GPL v2 explicitly.
 *
 * Revision 1.1.1.1  2005/03/10 17:50:22  colinmacleod
 * Restructured ivata op around Hibernate/PicoContainer.
 * Renamed ivata groupware.
 *
 * Revision 1.3  2004/11/12 15:57:04  colinmacleod
 * Removed dependencies on SSLEXT.
 * Moved Persistence classes to ivata masks.
 *
 * Revision 1.2  2004/11/03 15:34:05  colinmacleod
 * Changed relationship between person and address:
 * each person for now has exactly one address.
 *
 * Revision 1.1  2004/07/13 19:41:13  colinmacleod
 * Moved project to POJOs from EJBs.
 * Applied PicoContainer to services layer (replacing session EJBs).
 * Applied Hibernate to persistence layer (replacing entity EJBs).
 * -----------------------------------------------------------------------------
 */
package com.ivata.groupware.business.addressbook.address;

import org.apache.log4j.Logger;

import com.ivata.groupware.business.addressbook.address.country.CountryDO;
import com.ivata.groupware.business.addressbook.person.PersonDO;
import com.ivata.groupware.container.persistence.BaseDO;

/**
 * <p>
 * Represents a street address within the system. The current model will allow
 * each person to have multiple street addresses, though the JSP front-end is
 * currently restricted to just one.
 * </p>
 *
 * @author Colin MacLeod
 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
 * @since   2002-05-15
 * @version $Revision: 1.8 $
 *
 * @hibernate.class
 *      table="address"
 * @hibernate.cache
 *      usage="read-write"
 */
public class AddressDO extends BaseDO {
    /**
     * Logger for this class.
     */
    private static final Logger logger = Logger.getLogger(AddressDO.class);

    /**
     * <p>
     * Used to separate all the values in the display value.
     * </p>
     */
    private static final String DISPLAY_VALUE_SEPERATOR = ", ";
    /**
     * Serialization version (for <code>Serializable</code> interface).
     */
    private static final long serialVersionUID = 1L;
    /**
     * Country this address is in.
     */
    private CountryDO country;
    /**
     * <copyDoc>Refer to {@link #getPerson}.</copyDoc>
     */
    private PersonDO person;
    /**
     * Zipcode or postcode. Can be aphanumeric in some countries (UK/CA).
     */
    private String postCode;
    /**
     * <p>
     * State or county/region within country.
     * </p>
     */
    private String region;
    /**
     * <p>
     * House name/house number, street and district.
     * </p>
     */
    private String streetAddress;
    /**
     * <p>
     * Town or city.
     * </p>
     */
    private String town;

    /**
     * <p>
     * Get the country of an address.
     * </p>
     *
     * @return country for this address bean.
     * @hibernate.many-to-one
     *      column="address_country"
     */
    public final  CountryDO getCountry() {
        if (logger.isDebugEnabled()) {
            logger.debug("getCountry() - start");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("getCountry() - end - return value = " + country);
        }
        return country;
    }

    /**
     * <p>
     * For this class, shows the whole address.
     * </p>
     *
     * @see com.ivata.mask.valueobject.ValueObject#getDisplayValue()
     */
    public final String getDisplayValue() {
        if (logger.isDebugEnabled()) {
            logger.debug("getDisplayValue() - start");
        }

        StringBuffer displayValue = new StringBuffer();
        if (streetAddress != null) {
            displayValue.append(streetAddress);
        }
        if (town != null) {
            if (displayValue.length() > 0) {
                displayValue.append(DISPLAY_VALUE_SEPERATOR);
            }
            displayValue.append(town);
        }
        if (postCode != null) {
            if (displayValue.length() > 0) {
                displayValue.append(DISPLAY_VALUE_SEPERATOR);
            }
            displayValue.append(postCode);
        }
        if (region != null) {
            if (displayValue.length() > 0) {
                displayValue.append(DISPLAY_VALUE_SEPERATOR);
            }
            displayValue.append(region);
        }
        if (country != null) {
            if (displayValue.length() > 0) {
                displayValue.append(DISPLAY_VALUE_SEPERATOR);
            }
            displayValue.append(country.getDisplayValue());
        }
        String returnString = displayValue.toString();
        if (logger.isDebugEnabled()) {
            logger.debug("getDisplayValue() - end - return value = "
                    + returnString);
        }
        return returnString;
    }
    /**
     * Overridden to set the id type.
     * @see com.ivata.groupware.container.persistence.BaseDO#getId()
     * @return current identifier.
     * @hibernate.id
     *      generator-class="foreign"
     * @hibernate.generator-param
     *      name="property"
     *      value="person"
     */
    public Integer getId() {
        if (logger.isDebugEnabled()) {
            logger.debug("getId() - start");
        }

        Integer returnInteger = super.getId();
        if (logger.isDebugEnabled()) {
            logger.debug("getId() - end - return value = " + returnInteger);
        }
        return returnInteger;
    }

    /**
     * <p>
     * In this version of ivata groupware, each address is associated with a
     * single person.
     * </p>
     *
     * @return Returns the person this address is associated with.
     * @hibernate.one-to-one
     */
    public PersonDO getPerson() {
        if (logger.isDebugEnabled()) {
            logger.debug("getPerson() - start");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("getPerson() - end - return value = " + person);
        }
        return person;
    }

    /**
     * <p>
     * Get the zipcode or postcode. Can be aphanumeric in some countries
     * (UK/CA).
     * </p>
     *
     * @return zipcode or postcode. Can be aphanumeric in some countries
     *     (UK/CA).
     * @hibernate.property
     *      column="post_code"
     */
    public final  String getPostCode() {
        if (logger.isDebugEnabled()) {
            logger.debug("getPostCode() - start");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("getPostCode() - end - return value = " + postCode);
        }
        return postCode;
    }
    /**
     * <p>
     * Get the state or county/region within country.
     * </p>
     *
     * @return state or county/region within country.
     * @hibernate.property
     */
    public final  String getRegion() {
        if (logger.isDebugEnabled()) {
            logger.debug("getRegion() - start");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("getRegion() - end - return value = " + region);
        }
        return region;
    }
    /**
     * <p>Get the house name/house number, street and district.</p>
     *
     * @return the house name/house number, street and district.
     * @hibernate.property
     *      column="street_address"
     */
    public final  String getStreetAddress() {
        if (logger.isDebugEnabled()) {
            logger.debug("getStreetAddress() - start");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("getStreetAddress() - end - return value = "
                    + streetAddress);
        }
        return streetAddress;
    }

    /**
     * <p>Get the town or city.</p>
     *
     * @return the town or city.
     * @hibernate.property
     */
    public final  String getTown() {
        if (logger.isDebugEnabled()) {
            logger.debug("getTown() - start");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("getTown() - end - return value = " + town);
        }
        return town;
    }
    /**
     * <p>Set the country of an address.</p>
     *
     * @param countryParam the new country for this address bean.
     */
    public final  void setCountry(final CountryDO countryParam) {
        if (logger.isDebugEnabled()) {
            logger.debug("setCountry(CountryDO country = " + countryParam
                    + ") - start");
        }

        checkSetter();
        this.country = countryParam;

        if (logger.isDebugEnabled()) {
            logger.debug("setCountry(CountryDO) - end");
        }
    }

    /**
     * <copyDoc>Refer to {@link #getPerson}.</copyDoc>
     * @param personParam The person to set.
     */
    public final void setPerson(final PersonDO personParam) {
        if (logger.isDebugEnabled()) {
            logger.debug("setPerson(PersonDO person = "
                    + personParam + ") - start");
        }

        checkSetter();
        this.person = personParam;

        if (logger.isDebugEnabled()) {
            logger.debug("setPerson(PersonDO) - end");
        }
    }

    /**
     * <p>Set the zipcode or postcode. Can be aphanumeric in some countries
     * (UK/CA).</p>
     *
     * @param postCodeParam zipcode or postcode. Can be aphanumeric in some
     * countries (UK/CA).
     */
    public final  void setPostCode(final String postCodeParam) {
        if (logger.isDebugEnabled()) {
            logger.debug("setPostCode(String postCode = " + postCodeParam
                    + ") - start");
        }

        checkSetter();
        this.postCode = postCodeParam;

        if (logger.isDebugEnabled()) {
            logger.debug("setPostCode(String) - end");
        }
    }

    /**
     * <p>Set the state or county/region within country.</p>
     *
     * @param regionParam state or county/region within country.
     */
    public final  void setRegion(final String regionParam) {
        if (logger.isDebugEnabled()) {
            logger.debug("setRegion(String region = "
                    + regionParam + ") - start");
        }

        checkSetter();
        this.region = regionParam;

        if (logger.isDebugEnabled()) {
            logger.debug("setRegion(String) - end");
        }
    }
    /**
     * <p>Set the house name/house number, street and district.</p>
     *
     * @param streetAddressParam house name/house number, street and district.
     */
    public final  void setStreetAddress(final String streetAddressParam) {
        if (logger.isDebugEnabled()) {
            logger.debug("setStreetAddress(String streetAddress = "
                    + streetAddressParam + ") - start");
        }

        checkSetter();
        this.streetAddress = streetAddressParam;

        if (logger.isDebugEnabled()) {
            logger.debug("setStreetAddress(String) - end");
        }
    }
    /**
     * <p>Set the town or city.</p>
     *
     * @param townParam or city.
     */
    public final  void setTown(final String townParam) {
        if (logger.isDebugEnabled()) {
            logger.debug("setTown(String town = " + townParam + ") - start");
        }

        checkSetter();
        this.town = townParam;

        if (logger.isDebugEnabled()) {
            logger.debug("setTown(String) - end");
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.