001    package org.rakeshv.xml.addressbook;
002    
003    import java.util.List;
004    import java.util.ArrayList;
005    
006    /**
007     * A <code>bean</code> that represents a person in the address book.
008     * This bean contains fields that directly map to the child elements
009     * under the <code>person</code> element in the address book XML file.
010     *
011     * <p>Copyright 2003 Rakesh Vidyadharan</p>
012     *
013     * @author Rakesh Vidyadharan 2003 February 12
014     * @version $Id: Person.java,v 1.3 2004/05/26 11:42:40 rakesh Exp $
015     */
016    public class Person extends Object
017    {
018      /**
019       * The nickname of the person.  This is used to uniquely identify an
020       * entry in the addressbook, as well as the alias to use to look up
021       * the mail address.  This field maps to the <code>nickname</code>
022       * element.
023       */
024      private String nickname = null;
025    
026      /**
027       * The givenname of the person.  The naming convention used in the
028       * XML file maps to the LDAP schema.  This field maps to the
029       * <code>givenname</code> element.
030       */
031      private String givenname = null;
032    
033      /**
034       * The surname of the person.  This field maps to the <code>sn</code>
035       * element.
036       */
037      private String surname = null;
038    
039      /**
040       * The commonname of the person.  This field maps to the 
041       * <code>cn</code> element.
042       */
043      private String commonname = null;
044    
045      /**
046       * The email address of the person.  This field maps to the
047       * <code>mail</code> element.
048       */
049      private String mail = null;
050    
051      /**
052       * The list of address(s) of the person.  This field maps to the 
053       * <code>addresses</code> element.
054       */
055      private List addresses = null;
056    
057      /**
058       * The home telepohone number of the person.  This field maps to the
059       * <code>homePhone</code> element.
060       */
061      private String homePhone = null;
062    
063      /**
064       * The mobile telephone number of the person.  This field maps to the
065       * <code>mobilePhone</code> element.
066       */
067      private String mobilePhone = null;
068    
069      /**
070       * The office telephone number of the person.  This field maps to the
071       * <code>officePhone</code> element.
072       */
073      private String officePhone = null;
074    
075      /**
076       * The pager number of the person.  This field maps to the 
077       * <code>pagerNumber</code> element.
078       */
079      private String pagerNumber = null;
080    
081      /**
082       * The fax number of the person.  This field maps to the
083       * <code>faxNumber</code> element.
084       */
085      private String faxNumber = null;
086    
087      /**
088       * Default constructor.  Just serves to create a new instance of the
089       * bean, whose fields may then be populated using the appropriate
090       * mutator methods.
091       */
092      public Person()
093      {
094        super();
095      }
096    
097      /**
098       * Constructor that populates all the class fields.
099       *
100       * @param nick - The {@link #nickname} value to set.
101       * @param name - The {@link #givenname} value to set.
102       * @param sn - The {@link #surname} value to set.
103       * @param cn - The {@link #commonname} value to set.
104       * @param email - The {@link #mail} value to set.
105       * @param addresses - The {@link #addresses} reference to set.
106       * @param office - The {@link #officePhone} value to set.
107       * @param home - The {@link #homePhone} value to set.
108       * @param mobile - The {@link #mobilePhone} value to set.
109       * @param pager - The {@link #pagerNumber} value to set.
110       * @param fax - The {@link #faxNumber} value to set.
111       */
112      public Person( String nick, String name, String sn, String cn,
113          String email, List addresses, String office,
114          String home, String mobile, String pager, String fax )
115      {
116        this.nickname = nick;
117        this.givenname = name;
118        this.surname = sn;
119        this.commonname = cn;
120        this.mail = email;
121        this.addresses = addresses;
122        this.officePhone = office;
123        this.homePhone = home;
124        this.mobilePhone = mobile;
125        this.pagerNumber = pager;
126        this.faxNumber = fax;
127      }
128    
129      /**
130       * Constructor that populates just the name fields.
131       *
132       * @param nick - The {@link #nickname} value to set.
133       * @param name - The {@link #givenname} value to set.
134       * @param sn - The {@link #surname} value to set.
135       * @param cn - The {@link #commonname} value to set.
136       * @param email - The {@link #mail} value to set.
137       */
138      public Person( String nick, String name, String sn, String cn,
139          String email )
140      {
141        this.nickname = nick;
142        this.givenname = name;
143        this.surname = sn;
144        this.commonname = cn;
145        this.mail = email;
146      }
147    
148      /**
149       * Add the specified {@link Address} to the {@link #addresses}
150       * <code>List</code>.  If {@link #addresses} is <code>null</code>,
151       * create a new <code>List</code> and add the specified {@link
152       * Address} to it.
153       *
154       * @param address - The {@link Address} that is to be added
155       *   to the {@link #addresses}.
156       */
157      public final void addAddress( Address address )
158      {
159        if ( addresses == null )
160        {
161          addresses = new ArrayList( 1 );
162        }
163    
164        addresses.add( address );
165      }
166      
167      /**
168       * Return the value/reference of the {@link #nickname}.
169       *
170       * @return String - The value/reference of nickname.
171       */
172      public final String getNickname()
173      {
174        return nickname;
175      }
176      
177      /**
178       * Set the value of {@link #nickname}.
179       *
180       * @param nickname - The value to set.
181       */
182      public final void setNickname(String nickname)
183      {
184        this.nickname = nickname;
185      }
186      
187      /**
188       * Return the value/reference of the {@link #givenname}.
189       *
190       * @return String - The value/reference of givenname.
191       */
192      public final String getGivenname()
193      {
194        return givenname;
195      }
196      
197      /**
198       * Set the value of {@link #givenname}.
199       *
200       * @param givenname - The value to set.
201       */
202      public final void setGivenname(String givenname)
203      {
204        this.givenname = givenname;
205      }
206      
207      /**
208       * Return the value/reference of the {@link #surname}.
209       *
210       * @return String - The value/reference of surname.
211       */
212      public final String getSurname()
213      {
214        return surname;
215      }
216      
217      /**
218       * Set the value of {@link #surname}.
219       *
220       * @param surname - The value to set.
221       */
222      public final void setSurname(String surname)
223      {
224        this.surname = surname;
225      }
226      
227      /**
228       * Return the value/reference of the {@link #commonname}.
229       *
230       * @return String - The value/reference of commonname.
231       */
232      public final String getCommonname()
233      {
234        return commonname;
235      }
236      
237      /**
238       * Set the value of {@link #commonname}.
239       *
240       * @param commonname - The value to set.
241       */
242      public final void setCommonname(String commonname)
243      {
244        this.commonname = commonname;
245      }
246      
247      /**
248       * Return the value/reference of the {@link #mail}.
249       *
250       * @return String - The value/reference of mail.
251       */
252      public final String getMail()
253      {
254        return mail;
255      }
256      
257      /**
258       * Set the value of {@link #mail}.
259       *
260       * @param mail - The value to set.
261       */
262      public final void setMail(String mail)
263      {
264        this.mail = mail;
265      }
266      
267      /**
268       * Return the value/reference of the {@link #officePhone}.
269       *
270       * @return String - The value/reference of officePhone.
271       */
272      public final String getOfficePhone()
273      {
274        return officePhone;
275      }
276      
277      /**
278       * Set the value of {@link #officePhone}.
279       *
280       * @param officePhone - The value to set.
281       */
282      public final void setOfficePhone(String officePhone)
283      {
284        this.officePhone = officePhone;
285      }
286      
287      /**
288       * Return the value/reference of the {@link #homePhone}.
289       *
290       * @return String - The value/reference of homePhone.
291       */
292      public final String getHomePhone()
293      {
294        return homePhone;
295      }
296      
297      /**
298       * Set the value of {@link #homePhone}.
299       *
300       * @param homePhone - The value to set.
301       */
302      public final void setHomePhone(String homePhone)
303      {
304        this.homePhone = homePhone;
305      }
306      
307      /**
308       * Return the value/reference of the {@link #mobilePhone}.
309       *
310       * @return String - The value/reference of mobilePhone.
311       */
312      public final String getMobilePhone()
313      {
314        return mobilePhone;
315      }
316      
317      /**
318       * Set the value of {@link #mobilePhone}.
319       *
320       * @param mobilePhone - The value to set.
321       */
322      public final void setMobilePhone(String mobilePhone)
323      {
324        this.mobilePhone = mobilePhone;
325      }
326      
327      /**
328       * Return the value/reference of the {@link #faxNumber}.
329       *
330       * @return String - The value/reference of faxNumber.
331       */
332      public final String getFaxNumber()
333      {
334        return faxNumber;
335      }
336      
337      /**
338       * Set the value of {@link #faxNumber}.
339       *
340       * @param faxNumber - The value to set.
341       */
342      public final void setFaxNumber(String faxNumber)
343      {
344        this.faxNumber = faxNumber;
345      }
346      
347      /**
348       * Return the value/reference of the {@link #addresses}.
349       *
350       * @return List - The value/reference of addresses.
351       */
352      public final List getAddresses()
353      {
354        return addresses;
355      }
356      
357      /**
358       * Set the value of {@link #addresses}.
359       *
360       * @param addresses - The value to set.
361       */
362      public final void setAddresses(List addresses)
363      {
364        this.addresses = addresses;
365      }
366      
367      /**
368       * Return the value/reference of the {@link #pagerNumber}.
369       *
370       * @return String - The value/reference of pagerNumber.
371       */
372      public final String getPagerNumber()
373      {
374        return pagerNumber;
375      }
376      
377      /**
378       * Set the value of {@link #pagerNumber}.
379       *
380       * @param pagerNumber - The value to set.
381       */
382      public final void setPagerNumber(String pagerNumber)
383      {
384        this.pagerNumber = pagerNumber;
385      }
386    }