001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-hbm/src/java/org/sakaiproject/component/app/messageforums/dao/hibernate/PrivateMessageImpl.java $
003: * $Id: PrivateMessageImpl.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006, 2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.component.app.messageforums.dao.hibernate;
021:
022: import java.util.Comparator;
023: import java.util.List;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.sakaiproject.api.app.messageforums.MessageForumsUser;
028: import org.sakaiproject.api.app.messageforums.PrivateMessage;
029:
030: public class PrivateMessageImpl extends MessageImpl implements
031: PrivateMessage {
032:
033: private static final Log LOG = LogFactory
034: .getLog(PrivateMessageImpl.class);
035:
036: private List recipients = null;//new UniqueArrayList();
037: private Boolean externalEmail;
038: private String externalEmailAddress;
039: private String recipientsAsText;
040:
041: public static Comparator RECIPIENT_LIST_COMPARATOR_ASC;
042: public static Comparator RECIPIENT_LIST_COMPARATOR_DESC;
043:
044: // indecies for hibernate
045: //private int tindex;
046:
047: public Boolean getExternalEmail() {
048: return externalEmail;
049: }
050:
051: public void setExternalEmail(Boolean externalEmail) {
052: this .externalEmail = externalEmail;
053: }
054:
055: public String getExternalEmailAddress() {
056: return externalEmailAddress;
057: }
058:
059: public void setExternalEmailAddress(String externalEmailAddress) {
060: this .externalEmailAddress = externalEmailAddress;
061: }
062:
063: public List getRecipients() {
064: return recipients;
065: }
066:
067: public void setRecipients(List recipients) {
068: this .recipients = recipients;
069: }
070:
071: public String getRecipientsAsText() {
072: return recipientsAsText;
073: }
074:
075: public void setRecipientsAsText(String recipientsAsText) {
076: this .recipientsAsText = recipientsAsText;
077: }
078:
079: // public int getTindex() {
080: // try {
081: // return getTopic().getMessages().indexOf(this);
082: // } catch (Exception e) {
083: // return tindex;
084: // }
085: // }
086: //
087: // public void setTindex(int tindex) {
088: // this.tindex = tindex;
089: // }
090:
091: ////////////////////////////////////////////////////////////////////////
092: // helper methods for collections
093: ////////////////////////////////////////////////////////////////////////
094:
095: public void addRecipient(MessageForumsUser user) {
096: if (LOG.isDebugEnabled()) {
097: LOG.debug("addRecipient(MessageForumsUser " + user + ")");
098: }
099:
100: if (user == null) {
101: throw new IllegalArgumentException("user == null");
102: }
103:
104: user.setPrivateMessage(this );
105: recipients.add(user);
106: }
107:
108: public void removeRecipient(MessageForumsUser user) {
109: if (LOG.isDebugEnabled()) {
110: LOG
111: .debug("removeRecipient(MessageForumsUser " + user
112: + ")");
113: }
114:
115: if (user == null) {
116: throw new IllegalArgumentException(
117: "Illegal attachment argument passed!");
118: }
119:
120: user.setPrivateMessage(null);
121: recipients.remove(user);
122: }
123:
124: // SORT BY RECIPIENT
125: static {
126: RECIPIENT_LIST_COMPARATOR_ASC = new Comparator() {
127: public int compare(Object pvtMsg, Object otherPvtMsg) {
128: if (pvtMsg != null && otherPvtMsg != null
129: && pvtMsg instanceof PrivateMessage
130: && otherPvtMsg instanceof PrivateMessage) {
131: String msg1 = ((PrivateMessage) pvtMsg)
132: .getRecipientsAsText().toLowerCase();
133: String msg2 = ((PrivateMessage) otherPvtMsg)
134: .getRecipientsAsText().toLowerCase();
135: return msg1.compareTo(msg2);
136: }
137: return -1;
138:
139: }
140: };
141:
142: RECIPIENT_LIST_COMPARATOR_DESC = new Comparator() {
143: public int compare(Object pvtMsg, Object otherPvtMsg) {
144: if (pvtMsg != null && otherPvtMsg != null
145: && pvtMsg instanceof PrivateMessage
146: && otherPvtMsg instanceof PrivateMessage) {
147: String msg1 = ((PrivateMessage) pvtMsg)
148: .getRecipientsAsText().toLowerCase();
149: String msg2 = ((PrivateMessage) otherPvtMsg)
150: .getRecipientsAsText().toLowerCase();
151: return msg2.compareTo(msg1);
152: }
153: return -1;
154:
155: }
156: };
157: }
158: }
|