001: /**
002: * %W% %G%
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and iPlanet
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.addressbook;
014:
015: import java.util.Map;
016: import java.util.HashMap;
017:
018: /**
019: * Element - Element is a base class for the Entry, Group and the AddressBook
020: * beans.
021: *
022: *
023: */
024:
025: public class Element {
026:
027: /*
028: * The fields of the Element
029: *
030: */
031:
032: /**
033: * Unique name.
034: */
035: protected String un = null;
036:
037: /**
038: * Common name.
039: */
040: protected String cn = null;
041:
042: /**
043: * Note for the address book entry.
044: */
045: protected String description = null;
046:
047: /**
048: * ElementType - either Entry, Group, or Address Book
049: */
050: protected int elementType = -1;
051:
052: /**
053: * Index of the element
054: */
055: protected String entryid = null;
056:
057: /**
058: * Additional properties to be stored in the Element. These are specific
059: * to the adapters. Check the docs for the adapters to see the exact
060: * additional properties supported.
061: */
062: protected Map properties = null;
063:
064: /**
065: * Type elements constants
066: */
067: public static final int ENTRY = 1;
068: public static final int GROUP = 2;
069: public static final int ALL = 3;
070: public static final int ADDRESSBOOK = 4;
071: public static final int UNSPECIFIED = -1;
072:
073: /**
074: * Get Common name.
075: *
076: * @return cn String
077: */
078: public String getCn() {
079: return cn;
080: }
081:
082: /**
083: * Get description.
084: *
085: * @return description String
086: */
087: public String getDescription() {
088: return description;
089: }
090:
091: /**
092: * Get unique name.
093: *
094: * @return un String
095: */
096: public String getUn() {
097: return un;
098: }
099:
100: /**
101: * Get entryid.
102: *
103: * @return entryid String
104: */
105: public String getEntryid() {
106: return entryid;
107: }
108:
109: /**
110: * Set common name.
111: *
112: * @param value the cn String
113: */
114: public void setCn(String value) {
115: cn = value;
116: }
117:
118: /**
119: * Set description.
120: *
121: * @param value the description String
122: */
123: public void setDescription(String value) {
124: description = value;
125: }
126:
127: /**
128: * Set unique name.
129: *
130: * @param value the un String
131: */
132: public void setUn(String value) {
133: un = value;
134: }
135:
136: /**
137: * Set entryid.
138: *
139: * @param value the entryid String
140: */
141: public void setEntryid(String value) {
142: entryid = value;
143: }
144:
145: /**
146: * Method to retreive a particular entry property.
147: *
148: * @return value of property
149: */
150: public Object getProperty(String property) {
151: if (properties != null) {
152: return properties.get(property);
153: }
154: return null;
155: }
156:
157: /**
158: * Method to check if a particular property exists.
159: *
160: * @return true if property exists, false otherwise
161: */
162: public boolean hasProperty(String property) {
163: if (properties != null) {
164: return properties.containsKey(property);
165: }
166: return false;
167: }
168:
169: /**
170: * Set additional properties that maybe associated with this entry bean. These
171: * are specific to the adapter.
172: *
173: * @param property property keyword
174: * @param value value of property
175: */
176: public void setProperty(String property, Object value) {
177: if (properties == null) {
178: properties = new HashMap();
179: }
180: properties.put(property, value);
181: }
182:
183: /**
184: * Get ElementType
185: *
186: * @return int indicating an element type
187: */
188: public int getElementType() {
189: return elementType;
190: }
191:
192: /**
193: * Set ElementType
194: *
195: * @param int indicating an element type
196: */
197: public void setElementType(int elementType) {
198: this .elementType = elementType;
199: }
200:
201: /**
202: * Convenience method to check if element is of type Entry
203: *
204: * @return boolean indicating whether elementType is Entry
205: */
206: public boolean isEntry() {
207: if (this .elementType == ENTRY) {
208: return true;
209: }
210: return false;
211: }
212:
213: /**
214: * Convenience method to check if element is of type Group
215: *
216: * @return boolean indicating whether elementType is Group
217: */
218: public boolean isGroup() {
219: if (this .elementType == GROUP) {
220: return true;
221: }
222: return false;
223: }
224:
225: /**
226: * Convenience method to check if element is of type AddressBook
227: *
228: * @return boolean indicating whether elementType is AddressBook
229: */
230: public boolean isAddressBook() {
231: if (this .elementType == ADDRESSBOOK) {
232: return true;
233: }
234: return false;
235: }
236:
237: }
|