001: /**
002: * Copyright (c) 2006, Sun Microsystems, Inc
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: * * Redistributions in binary form must reproduce the above
012: * copyright notice, this list of conditions and the following
013: * disclaimer in the documentation and/or other materials provided
014: * with the distribution.
015: * * Neither the name of the TimingFramework project nor the names of its
016: * contributors may be used to endorse or promote products derived
017: * from this software without specific prior written permission.
018: *
019: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
020: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
021: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
022: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
023: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
024: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
025: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
029: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: */package org.zilonis.tool.ext.mailman.model;
031:
032: import java.io.IOException;
033: import java.lang.ref.SoftReference;
034: import java.util.Date;
035: import java.util.Arrays;
036: import java.util.Map;
037: import java.util.HashMap;
038:
039: public class Message {
040: private int position;
041: private String id;
042: private Contact from;
043: private Contact[] to;
044: private Contact[] cc;
045: private String subject;
046: private long date;
047: private String[] refs;
048: private SoftReference<String> bodyRef;
049: private boolean read;
050:
051: public Message(int position) {
052: this .position = position;
053: }
054:
055: public void setRead(boolean read) {
056: this .read = read;
057: }
058:
059: public boolean isRead() {
060: return read;
061: }
062:
063: int getPosition() {
064: return position;
065: }
066:
067: public String toString() {
068: return "Message [" + "id=" + id + "read=" + read + " subject="
069: + subject + " from=" + from + " to="
070: + ((to == null) ? "" : Arrays.asList(to)) + " cc="
071: + ((cc == null) ? "" : Arrays.asList(cc)) + " refs="
072: + ((refs == null) ? "" : Arrays.asList(refs))
073: + " date=" + new Date(date) + "]";
074: }
075:
076: // public Message(Contact from, Contact[] to, Contact[] cc, String subject,
077: // String body, Attachment[] attachment,
078: // Map<String, String> headers, Date dateTime) {
079: // if (from == null) {
080: // throw new IllegalArgumentException("Sender cannot be null.");
081: // } else if (to == null || to.length == 0) {
082: // throw new IllegalArgumentException("One recipient is required.");
083: // }
084: // this.from = from;
085: // this.to = to;
086: // this.cc = cc;
087: // this.subject = subject == null ? "" : subject;
088: // this.body = body == null ? "" : body;
089: // this.attachment = attachment;
090: // this.headers = headers == null ? new HashMap<String, String>() : headers;
091: // if (dateTime == null) {
092: // dateTime = new Date();
093: // }
094: // this.dateTime = (Date) dateTime.clone();
095: // }
096:
097: public long getDateTime() {
098: return date;
099: }
100:
101: public Map<String, String> getHeaders() {
102: // PENDING:
103: throw new RuntimeException("implement me");
104: // return null;
105: }
106:
107: /**
108: * Returns a clone of the contact
109: */
110: public Contact getFrom() {
111: return from;
112: }
113:
114: /**
115: * Returns a clone of the contacts
116: */
117: public Contact[] getTo() {
118: if (to == null) {
119: return to;
120: }
121: return to.clone();
122: }
123:
124: /**
125: * Returns a clone of the contacts
126: */
127: public Contact[] getCc() {
128: if (cc == null) {
129: return null;
130: }
131: return cc.clone();
132: }
133:
134: public String getSubject() {
135: return subject;
136: }
137:
138: // @Override
139: // public boolean equals(Object o) {
140: // if (this == o) {
141: // return true;
142: // }
143: // if (o == null || getClass() != o.getClass()) {
144: // return false;
145: // }
146: // final Message message = (Message) o;
147: // if (!Arrays.equals(attachment, message.attachment)) {
148: // return false;
149: // }
150: // if (body != null ? !body.equals(message.body) : message.body != null) {
151: // return false;
152: // }
153: // if (!Arrays.equals(cc, message.cc)) {
154: // return false;
155: // }
156: // if (dateTime != null ? !dateTime.equals(message.dateTime) :
157: // message.dateTime != null) {
158: // return false;
159: // }
160: // if (from != null ? !from.equals(message.from) : message.from != null) {
161: // return false;
162: // }
163: // if (subject != null ? !subject.equals(message.subject) :
164: // message.subject != null) {
165: // return false;
166: // }
167: // return Arrays.equals(to, message.to);
168: // }
169: //
170: // @Override
171: // public int hashCode() {
172: // int result;
173: // result = (from != null ? from.hashCode() : 0);
174: // result = 29 * result + (subject != null ? subject.hashCode() : 0);
175: // result = 29 * result + (body != null ? body.hashCode() : 0);
176: // result = 29 * result + (dateTime != null ? dateTime.hashCode() : 0);
177: // return result;
178: // }
179:
180: public void setCc(Contact[] contact) {
181: this .cc = contact;
182: }
183:
184: public void setDate(long date) {
185: this .date = date;
186: }
187:
188: public void setFrom(Contact from) {
189: this .from = from;
190: }
191:
192: public void setID(String id) {
193: this .id = id;
194: }
195:
196: public void setReferences(String[] refs) {
197: this .refs = refs;
198: }
199:
200: public void setSubject(String subject) {
201: this .subject = subject;
202: }
203:
204: public void setTo(Contact[] to) {
205: this.to = to;
206: }
207: }
|