01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //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[] NAMES = new String[] { "work", "home",
23: "other" };
24:
25: public static final int TYPE_WORK = 0;
26:
27: public static final int TYPE_HOME = 1;
28:
29: public static final int TYPE_OTHER = 2;
30:
31: private String address;
32:
33: private int type;
34:
35: public EmailModel(String address, int type) {
36: if (address == null)
37: throw new IllegalArgumentException("address == null");
38: if (type < 0 || type >= NAMES.length)
39: throw new IllegalArgumentException(
40: "type is not supported= " + type);
41:
42: this .address = address;
43: this .type = type;
44: }
45:
46: public EmailModel(String address, String type) {
47: if (address == null)
48: throw new IllegalArgumentException("address == null");
49: this .address = address;
50:
51: boolean foundMatch = false;
52: for (int i = 0; i < NAMES.length; i++) {
53: if (type.equals(NAMES[i])) {
54: foundMatch = true;
55: this .type = i;
56: }
57: }
58:
59: // backwards compatibility
60: if (type.equals("internet")) {
61: foundMatch = true;
62: this .type = 0;
63: }
64:
65: //tstich: CA-41 bugfix
66: if (type.equals("x400")) {
67: foundMatch = true;
68: this .type = 0;
69: }
70:
71: if (!foundMatch)
72: throw new IllegalArgumentException("unsupported type: "
73: + type);
74:
75: }
76:
77: /* (non-Javadoc)
78: * @see org.columba.addressbook.model.IEmailModel#getAddress()
79: */
80: public String getAddress() {
81: return address;
82: }
83:
84: /* (non-Javadoc)
85: * @see org.columba.addressbook.model.IEmailModel#getType()
86: */
87: public int getType() {
88: return type;
89: }
90:
91: /* (non-Javadoc)
92: * @see org.columba.addressbook.model.IEmailModel#getTypeString()
93: */
94: public String getTypeString() {
95: return NAMES[type];
96: }
97: }
|