KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > webapps > addressbook > Contact


1 package org.jahia.webapps.addressbook;
2
3 import java.util.*;
4
5 import org.jahia.tools.*;
6 import org.jahia.tools.db.*;
7
8 /**
9  * Class Contact : defines the structure of a contact
10  * and provides methods to handle it
11  *
12  * @author Jerome Tamiotti <a HREF="mailto:tamiotti@xo3.com">tamiotti@xo3.com</a>
13  * @version %I%, %G%
14  * @see com.mycomponents.webapps.addressbook.AddressBook
15  */

16 public class Contact {
17
18     protected int id = -1;
19     private int addbook_id = 0;
20     private String JavaDoc last_name = "";
21     private String JavaDoc first_name = "";
22     private String JavaDoc civil_title = "";
23     private String JavaDoc prof_title = "";
24     private String JavaDoc company = "";
25     private String JavaDoc address1 = "";
26     private String JavaDoc address2 = "";
27     private String JavaDoc city = "";
28     private String JavaDoc zip = "";
29     private String JavaDoc state = "";
30     private String JavaDoc country = "";
31     private String JavaDoc notes = "";
32     private int category = -1;
33     private int[] comm_ids = new int[5];
34     private String JavaDoc[] comm_values = new String JavaDoc[5];
35     private int commid_0 = 0;
36     private int commid_1= 0;
37     private int commid_2= 0;
38     private int commid_3 = 0;
39     private int commid_4 = 0;
40     private String JavaDoc commval_0 = null;
41     private String JavaDoc commval_1= null;
42     private String JavaDoc commval_2= null;
43     private String JavaDoc commval_3 = null;
44     private String JavaDoc commval_4 = null;
45
46
47     /**
48      * The class constructor (empty)
49      */

50     public Contact() {
51         //initialize the values of comm
52
for(int i=0; i<5; i++) {
53             comm_ids[i] = 0;
54             comm_values[i] = "";
55         }
56                     commval_0= comm_values[0];
57                     commval_1=comm_values[1];
58                     commval_2=comm_values[2];
59                     commval_3=comm_values[3];
60                     commval_4=comm_values[4];
61                     commid_0 = comm_ids[0];
62                     commid_1= comm_ids[1];
63                     commid_2= comm_ids[2];
64                     commid_3 = comm_ids[3];
65                     commid_4 = comm_ids[4];
66
67     }
68
69     /**
70      * Get the contact id
71      *
72      * @return the contact id
73      */

74     public int getId() {
75         return this.id;
76     }
77
78     /**
79      * Set the contact id
80      *
81      * @param the contact id
82      */

83     protected void setId(int id) {
84         this.id = id;
85     }
86
87     /**
88      * Get the address book id
89      *
90      * @return the address book id
91      */

92     public int getAddBookId() {
93         return this.addbook_id;
94     }
95
96     /**
97      * Set the contact id
98      *
99      * @param the contact id
100      */

101     protected void setAddBookId(int id) {
102         this.addbook_id = id;
103     }
104
105
106     /**
107      * Get the contact surname
108      *
109      * @return the contact last name
110      */

111     public String JavaDoc getLastName() {
112         return this.last_name;
113     }
114
115     /**
116      * Set the contact last name
117      *
118      * @param the contact last name
119      */

120     public void setLastName(String JavaDoc last_name) {
121         this.last_name = last_name;
122     }
123
124     /**
125      * Get the contact first name
126      *
127      * @return the contact first name
128      */

129     public String JavaDoc getFirstName() {
130         return this.first_name;
131     }
132
133     /**
134      * Set the contact first name
135      *
136      * @param the contact first name
137      */

138     public void setFirstName(String JavaDoc first_name) {
139         this.first_name = first_name;
140     }
141
142     /**
143      * Get the contact civil title
144      *
145      * @return the contact civil title
146      */

147     public String JavaDoc getCivilTitle() {
148         return this.civil_title;
149     }
150
151     /**
152      * Set the contact civil title
153      *
154      * @param the contact civil title
155      */

156      public void setCivilTitle(String JavaDoc civil_title) {
157          this.civil_title = civil_title;
158     }
159
160     /**
161      * Get the contact professional title
162      *
163      * @return the contact professional title
164      */

165     public String JavaDoc getProfTitle() {
166         return this.prof_title;
167     }
168
169     /**
170      * Set the contact professional title
171      *
172      * @param the contact professional title
173      */

174      public void setProfTitle(String JavaDoc prof_title) {
175          this.prof_title = prof_title;
176     }
177
178     /**
179      * Get the contact company name
180      *
181      * @return the contact company name
182      */

183      public String JavaDoc getCompany() {
184          return this.company;
185     }
186
187     /**
188      * Set the contact company name
189      *
190      * @param the contact company name
191      */

192     public void setCompany(String JavaDoc company) {
193         this.company = company;
194     }
195
196     /**
197      * Get the first part of contact address
198      *
199      * @return the first part of the contact address
200      */

201     public String JavaDoc getAddress1() {
202         return this.address1;
203     }
204
205     /**
206      * Set the first part of contact address
207      *
208      * @param the first part of the contact address
209      */

210     public void setAddress1(String JavaDoc address1) {
211         this.address1 = address1;
212     }
213
214     /**
215      * Get the second part of contact address
216      *
217      * @return the second part of the contact address
218      */

219     public String JavaDoc getAddress2() {
220         return this.address2;
221     }
222
223     /**
224      * Set the second part of contact address
225      *
226      * @param the second part of the contact address
227      */

228     public void setAddress2(String JavaDoc address2) {
229         this.address2 = address2;
230     }
231
232     /**
233      * Get the contact city
234      *
235      * @return the contact city name
236      */

237     public String JavaDoc getCity() {
238         return this.city;
239     }
240
241     /**
242      * Set the contact city
243      *
244      * @param the contact city name
245      */

246     public void setCity(String JavaDoc city) {
247         this.city = city;
248     }
249
250     /**
251      * Get the contact zip
252      *
253      * @return the contact zip
254      */

255     public String JavaDoc getZip() {
256         return this.zip;
257     }
258
259     /**
260      * Set the contact zip
261      *
262      * @param the contact zip
263      */

264     public void setZip(String JavaDoc zip) {
265         this.zip = zip;
266     }
267
268     /**
269      * Get the contact state
270      *
271      * @return the contact state name
272      */

273     public String JavaDoc getState() {
274         return this.state;
275     }
276
277     /**
278      * Set the contact state
279      *
280      * @param the contact state name
281      */

282     public void setState(String JavaDoc state) {
283         this.state = state;
284     }
285
286     /**
287      * Get the contact country
288      *
289      * @return the contact country name
290      */

291     public String JavaDoc getCountry() {
292         return this.country;
293     }
294
295     /**
296      * Set the contact country
297      *
298      * @param the contact country name
299      */

300     public void setCountry(String JavaDoc country) {
301         this.country = country;
302     }
303
304     /**
305      * Get the contact category
306      *
307      * @return the contact category name
308      */

309     public int getCategory() {
310         return this.category;
311     }
312
313     /**
314      * Set the contact category
315      *
316      * @param the contact category name
317      */

318     public void setCategory(int category) {
319         this.category = category;
320     }
321
322     /**
323      * Get the notes relative to the contact
324      *
325      * @return the notes
326      */

327     public String JavaDoc getNotes() {
328         return this.notes;
329     }
330
331     /**
332      * Set the notes relative to the contact
333      *
334      * @param notes the notes
335      */

336     public void setNotes(String JavaDoc notes) {
337         this.notes = notes;
338     }
339
340     /**
341      * Add a phone or email value
342      *
343      * @param name the way of communication (phone, email,...)
344      * @param value the value
345      */

346     public void setNumber(int i, int id, String JavaDoc value) {
347         this.comm_ids[i] = id;
348         this.comm_values[i] = value;
349     }
350
351     /**
352      * Get the names of communications ways
353      *
354      * @return these names
355      */

356     public int[] getNumbersIds() {
357         return this.comm_ids;
358     }
359     public void setNumbersIds(int [] a) {
360       for(int i=0; i<a.length;i++)
361         this.comm_ids[i]= a[i];
362        }
363
364     /**
365      * Get the values of the previous numbers
366      *
367      * @return these values
368      */

369     public String JavaDoc[] getNumbersValues() {
370         return this.comm_values;
371     }
372     public void setNumbersValues(String JavaDoc[] a) {
373       for(int i=0; i<a.length;i++)
374                    this.comm_values[i]= a[i];
375        }
376
377     /**
378      * Check if all the required fields of a contact are filled in
379      *
380      * @return a string displaying the fields names
381      */

382     public boolean isCorrect() {
383
384         if (!this.last_name.equals("")) {
385             return true;
386         }
387         if (!this.first_name.equals("")) {
388             return true;
389         }
390         if (!this.company.equals("")) {
391             this.last_name = this.company;
392             this.civil_title = "Company";
393             return true;
394         }
395         return false;
396     }
397
398 }
399
Popular Tags