KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > reg > Contact


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.reg;
22
23 import com.methodhead.aikp.AutoIntKeyPersistable;
24
25 import org.apache.commons.beanutils.DynaClass;
26 import org.apache.commons.beanutils.DynaProperty;
27 import org.apache.commons.beanutils.BasicDynaClass;
28 import org.apache.commons.lang.StringUtils;
29
30 /**
31  * A Contact. The following fields are defined:
32  * <ul>
33  * <li><tt>int id = 0</tt></li>
34  * <li><tt>String firstname = ""</tt></li>
35  * <li><tt>String middlename = ""</tt></li>
36  * <li><tt>String lastname = ""</tt></li>
37  * <li><tt>String company = ""</tt></li>
38  * <li><tt>String address1 = ""</tt></li>
39  * <li><tt>String address2 = ""</tt></li>
40  * <li><tt>String city = ""</tt></li>
41  * <li><tt>String state = ""</tt></li>
42  * <li><tt>String zip = ""</tt></li>
43  * <li><tt>String country = ""</tt></li>
44  * <li><tt>String phone = ""</tt></li>
45  * <li><tt>String fax = ""</tt></li>
46  * <li><tt>String email = ""</tt></li>
47  * <li><tt>String url = ""</tt></li>
48  * </ul>
49  */

50 public class Contact
51 extends
52   AutoIntKeyPersistable {
53
54   private static DynaClass dynaClass_ = null;
55
56   static {
57     DynaProperty[] dynaProperties =
58       new DynaProperty[] {
59         new DynaProperty( "id", Integer JavaDoc.class ),
60         new DynaProperty( "firstname", String JavaDoc.class ),
61         new DynaProperty( "middlename", String JavaDoc.class ),
62         new DynaProperty( "lastname", String JavaDoc.class ),
63         new DynaProperty( "company", String JavaDoc.class ),
64         new DynaProperty( "address1", String JavaDoc.class ),
65         new DynaProperty( "address2", String JavaDoc.class ),
66         new DynaProperty( "city", String JavaDoc.class ),
67         new DynaProperty( "state", String JavaDoc.class ),
68         new DynaProperty( "zip", String JavaDoc.class ),
69         new DynaProperty( "country", String JavaDoc.class ),
70         new DynaProperty( "phone", String JavaDoc.class ),
71         new DynaProperty( "fax", String JavaDoc.class ),
72         new DynaProperty( "email", String JavaDoc.class ),
73         new DynaProperty( "url", String JavaDoc.class )
74       };
75
76     dynaClass_ =
77       new BasicDynaClass(
78         "reg_contact", Contact.class, dynaProperties );
79   }
80
81   // constructors /////////////////////////////////////////////////////////////
82

83   public Contact() {
84     super( dynaClass_ );
85     init();
86   }
87
88   public Contact( DynaClass dynaClass ) {
89     super( dynaClass );
90     init();
91   }
92
93   // constants ////////////////////////////////////////////////////////////////
94

95   // classes //////////////////////////////////////////////////////////////////
96

97   // methods //////////////////////////////////////////////////////////////////
98

99   protected void init() {
100     setInt( "id", 0 );
101     setString( "firstname", "" );
102     setString( "middlename", "" );
103     setString( "lastname", "" );
104     setString( "company", "" );
105     setString( "address1", "" );
106     setString( "address2", "" );
107     setString( "city", "" );
108     setString( "state", "" );
109     setString( "zip", "" );
110     setString( "country", "" );
111     setString( "phone", "" );
112     setString( "fax", "" );
113     setString( "email", "" );
114     setString( "url", "" );
115   }
116
117   /**
118    * Returns the contacts last and first name separated by a comma. If only
119    * the first or last name is set, it will be returned. If neither is set,
120    * "[Missing Name]" will be returned.
121    */

122   public String JavaDoc getFullName() {
123     if ( StringUtils.isBlank( getString( "firstname" ) ) && StringUtils.isBlank( getString( "lastname" ) ) ) {
124       return "[Missing Name]";
125     }
126
127     if ( StringUtils.isBlank( getString( "firstname" ) ) ) {
128       return getString( "lastname" );
129     }
130
131     if ( StringUtils.isBlank( getString( "lastname" ) ) ) {
132       return getString( "firstname" );
133     }
134
135     return getString( "lastname" ) + ", " + getString( "firstname" );
136   }
137
138   // properties ///////////////////////////////////////////////////////////////
139

140   // attributes ///////////////////////////////////////////////////////////////
141
}
142
Popular Tags