001: /***
002: * jwma Java WebMail
003: * Copyright (c) 2000-2003 jwma team
004: *
005: * jwma is free software; you can distribute and use this source
006: * under the terms of the BSD-style license received along with
007: * the distribution.
008: ***/package dtw.webmail.plugin.std;
009:
010: import dtw.webmail.model.JwmaContact;
011: import dtw.webmail.model.JwmaContactGroupImpl;
012: import dtw.webmail.model.JwmaContactImpl;
013: import dtw.webmail.util.AssociatedAbstractIdentifiable;
014: import dtw.webmail.util.StringUtil;
015: import org.apache.log4j.Logger;
016: import org.exolab.castor.jdo.TimeStampable;
017:
018: import java.util.ArrayList;
019: import java.util.Collections;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: /**
024: * Class implementing a specialized <tt>JwmaContactGroupImpl</tt>
025: * for being persisted with the Castor Plugins.
026: *
027: * @author Dieter Wimberger
028: * @version 0.9.7 07/02/2003
029: */
030: public class CastorContactGroup extends AssociatedAbstractIdentifiable
031: implements JwmaContactGroupImpl, TimeStampable {
032:
033: private static Logger log = Logger
034: .getLogger(CastorContactGroup.class);
035:
036: private String m_Name = "";
037: private String m_Comments = "";
038: private CastorContacts m_Contacts;
039: private List m_ContactIDs;
040: private long m_Timestamp = TimeStampable.NO_TIMESTAMP;
041:
042: public CastorContactGroup() {
043: super ();
044: m_ContactIDs = Collections.synchronizedList(new ArrayList());
045: }//constructor
046:
047: public CastorContactGroup(CastorContacts ctdb) {
048: super ();
049: m_Contacts = ctdb;
050: m_ContactIDs = Collections.synchronizedList(new ArrayList());
051:
052: }//constructor
053:
054: public CastorContactGroup(CastorContacts ctdb, String name) {
055: super ();
056: m_Contacts = ctdb;
057: m_ContactIDs = Collections.synchronizedList(new ArrayList());
058: m_Name = name;
059: }//constructor
060:
061: public void setContactsDB(CastorContacts contacts) {
062: m_Contacts = contacts;
063: //log.debug("Set database: " + contacts.getUID());
064: }//setContactsDB
065:
066: public String getName() {
067: return m_Name;
068: }//getName
069:
070: public void setName(String name) {
071: m_Name = name;
072: }//setName
073:
074: public String getComments() {
075: return m_Comments;
076: }//getComments
077:
078: public void setComments(String comments) {
079: m_Comments = comments;
080: }//setComments
081:
082: /**
083: * Used by castor to get list for persistence.
084: */
085: public String getContactIDList() {
086: String list = StringUtil.join(listContactIDs(), ",");
087: //log.debug("List of ids=" + list);
088: return list;
089: //return StringUtil.joinList(listContactIDs());
090: }//getContactIDList
091:
092: /**
093: * Used by castor to set list from persistent store.
094: */
095: public void setContactIDList(String list) {
096: String[] cont = StringUtil.split(list, ",");
097: m_ContactIDs.clear();
098: for (int i = 0; i < cont.length; i++) {
099: addContactID(cont[i]);
100: }
101: }//setContactIDList
102:
103: protected void addContactID(String uid) {
104: m_ContactIDs.add(uid);
105: //log.debug("Added contact with id=" + uid);
106: }//addContactID
107:
108: protected void removeContactID(String uid) {
109: m_ContactIDs.remove(uid);
110: }//removeContactID
111:
112: protected String[] listContactIDs() {
113: String[] contacts = new String[m_ContactIDs.size()];
114: return (String[]) m_ContactIDs.toArray(contacts);
115: }//listContactIDs
116:
117: public JwmaContact[] listContacts() {
118: //log.debug("Listing " + m_ContactIDs.size() + " contacts.");
119: if (m_ContactIDs.size() == 0) {
120: return new JwmaContact[0];
121: }
122: List list = getContacts();
123: //log.debug("Retrieved contact references.");
124: //return the
125: JwmaContact[] contacts = new JwmaContact[list.size()];
126: return (JwmaContact[]) list.toArray(contacts);
127: }//listContacts
128:
129: public List getContacts() {
130: ArrayList contacts = new ArrayList(m_ContactIDs.size());
131: if (m_ContactIDs.size() > 0) {
132: for (Iterator iter = m_ContactIDs.iterator(); iter
133: .hasNext();) {
134: contacts.add(m_Contacts
135: .getContact((String) iter.next()));
136: //log.debug("getContacts()::Added contact");
137: }
138: }
139: //return list with references
140: return contacts;
141: }//getContacts
142:
143: public void addContact(JwmaContactImpl con) {
144: //add uid
145: addContactID(con.getUID());
146: }//addContact
147:
148: public void removeContact(JwmaContactImpl con) {
149: //remove from uids list
150: removeContactID(con.getUID());
151: }//removeContact
152:
153: public boolean containsContact(String uid) {
154: return m_ContactIDs.contains(uid);
155: }//containsContact
156:
157: public long jdoGetTimeStamp() {
158: return m_Timestamp;
159: }//jdoGetTimeStamp
160:
161: public void jdoSetTimeStamp(long timeStamp) {
162: m_Timestamp = timeStamp;
163: }//jdoSetTimeStamp
164:
165: }//class CastorContactGroup
|