KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > model > EmailModel


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.addressbook.model;
19
20 public class EmailModel implements IEmailModel {
21
22     public static final String JavaDoc[] NAMES = new String JavaDoc[] { "work", "home", "other" };
23
24     public static final int TYPE_WORK = 0;
25
26     public static final int TYPE_HOME = 1;
27
28     public static final int TYPE_OTHER = 2;
29
30     private String JavaDoc address;
31
32     private int type;
33
34     public EmailModel(String JavaDoc address, int type) {
35         if (address == null)
36             throw new IllegalArgumentException JavaDoc("address == null");
37         if (type < 0 || type >=NAMES.length)
38             throw new IllegalArgumentException JavaDoc("type is not supported= " + type);
39
40         this.address = address;
41         this.type = type;
42     }
43
44     public EmailModel(String JavaDoc address, String JavaDoc type) {
45         if (address == null)
46             throw new IllegalArgumentException JavaDoc("address == null");
47         this.address = address;
48
49         boolean foundMatch = false;
50         for (int i = 0; i < NAMES.length; i++) {
51             if (type.equals(NAMES[i])) {
52                 foundMatch = true;
53                 this.type = i;
54             }
55         }
56
57         // backwards compatibility
58
if (type.equals("internet")) {
59             foundMatch = true;
60             this.type = 0;
61         }
62
63         
64         //tstich: CA-41 bugfix
65
if( type.equals("x400")) {
66             foundMatch = true;
67             this.type = 0;
68         }
69         
70         if (!foundMatch)
71             throw new IllegalArgumentException JavaDoc("unsupported type: " + type);
72
73     }
74
75     /* (non-Javadoc)
76      * @see org.columba.addressbook.model.IEmailModel#getAddress()
77      */

78     public String JavaDoc getAddress() {
79         return address;
80     }
81
82     /* (non-Javadoc)
83      * @see org.columba.addressbook.model.IEmailModel#getType()
84      */

85     public int getType() {
86         return type;
87     }
88
89     /* (non-Javadoc)
90      * @see org.columba.addressbook.model.IEmailModel#getTypeString()
91      */

92     public String JavaDoc getTypeString() {
93         return NAMES[type];
94     }
95 }
96
Popular Tags