001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.reg;
022:
023: import com.methodhead.aikp.AutoIntKeyPersistable;
024:
025: import org.apache.commons.beanutils.DynaClass;
026: import org.apache.commons.beanutils.DynaProperty;
027: import org.apache.commons.beanutils.BasicDynaClass;
028: import org.apache.commons.lang.StringUtils;
029:
030: /**
031: * A Contact. The following fields are defined:
032: * <ul>
033: * <li><tt>int id = 0</tt></li>
034: * <li><tt>String firstname = ""</tt></li>
035: * <li><tt>String middlename = ""</tt></li>
036: * <li><tt>String lastname = ""</tt></li>
037: * <li><tt>String company = ""</tt></li>
038: * <li><tt>String address1 = ""</tt></li>
039: * <li><tt>String address2 = ""</tt></li>
040: * <li><tt>String city = ""</tt></li>
041: * <li><tt>String state = ""</tt></li>
042: * <li><tt>String zip = ""</tt></li>
043: * <li><tt>String country = ""</tt></li>
044: * <li><tt>String phone = ""</tt></li>
045: * <li><tt>String fax = ""</tt></li>
046: * <li><tt>String email = ""</tt></li>
047: * <li><tt>String url = ""</tt></li>
048: * </ul>
049: */
050: public class Contact extends AutoIntKeyPersistable {
051:
052: private static DynaClass dynaClass_ = null;
053:
054: static {
055: DynaProperty[] dynaProperties = new DynaProperty[] {
056: new DynaProperty("id", Integer.class),
057: new DynaProperty("firstname", String.class),
058: new DynaProperty("middlename", String.class),
059: new DynaProperty("lastname", String.class),
060: new DynaProperty("company", String.class),
061: new DynaProperty("address1", String.class),
062: new DynaProperty("address2", String.class),
063: new DynaProperty("city", String.class),
064: new DynaProperty("state", String.class),
065: new DynaProperty("zip", String.class),
066: new DynaProperty("country", String.class),
067: new DynaProperty("phone", String.class),
068: new DynaProperty("fax", String.class),
069: new DynaProperty("email", String.class),
070: new DynaProperty("url", String.class) };
071:
072: dynaClass_ = new BasicDynaClass("reg_contact", Contact.class,
073: dynaProperties);
074: }
075:
076: // constructors /////////////////////////////////////////////////////////////
077:
078: public Contact() {
079: super (dynaClass_);
080: init();
081: }
082:
083: public Contact(DynaClass dynaClass) {
084: super (dynaClass);
085: init();
086: }
087:
088: // constants ////////////////////////////////////////////////////////////////
089:
090: // classes //////////////////////////////////////////////////////////////////
091:
092: // methods //////////////////////////////////////////////////////////////////
093:
094: protected void init() {
095: setInt("id", 0);
096: setString("firstname", "");
097: setString("middlename", "");
098: setString("lastname", "");
099: setString("company", "");
100: setString("address1", "");
101: setString("address2", "");
102: setString("city", "");
103: setString("state", "");
104: setString("zip", "");
105: setString("country", "");
106: setString("phone", "");
107: setString("fax", "");
108: setString("email", "");
109: setString("url", "");
110: }
111:
112: /**
113: * Returns the contacts last and first name separated by a comma. If only
114: * the first or last name is set, it will be returned. If neither is set,
115: * "[Missing Name]" will be returned.
116: */
117: public String getFullName() {
118: if (StringUtils.isBlank(getString("firstname"))
119: && StringUtils.isBlank(getString("lastname"))) {
120: return "[Missing Name]";
121: }
122:
123: if (StringUtils.isBlank(getString("firstname"))) {
124: return getString("lastname");
125: }
126:
127: if (StringUtils.isBlank(getString("lastname"))) {
128: return getString("firstname");
129: }
130:
131: return getString("lastname") + ", " + getString("firstname");
132: }
133:
134: // properties ///////////////////////////////////////////////////////////////
135:
136: // attributes ///////////////////////////////////////////////////////////////
137: }
|