KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > communication > message > impl > MessageHeaderImpl


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.communication.message.impl;
6
7 import java.util.Date JavaDoc;
8
9 import org.apache.commons.lang.StringUtils;
10 import org.exoplatform.services.communication.message.MessageHeader;
11
12
13 /**
14  * Fri, May 30, 2003 @ @author: Tuan Nguyen
15  * @version: $Id: MessageHeaderImpl.java,v 1.8 2004/10/27 03:11:16 tuan08 Exp $
16  * @since: 0.0
17  * @email: tuan08@yahoo.com Author : Benjamin Mestrallet
18  * benjamin.mestrallet@exoplatform.com
19  *
20  * @hibernate.class table="EXO_MESSAGE"
21  */

22 public class MessageHeaderImpl implements MessageHeader {
23   private String JavaDoc id_;
24
25   private String JavaDoc folderId_;
26
27   private String JavaDoc mailMessageId_;
28
29   private String JavaDoc from_ = "";
30
31   private String JavaDoc flags_ = "";
32
33   private String JavaDoc subject_ = "";
34
35   private Date JavaDoc receivedDate_;
36
37   public MessageHeaderImpl() {
38   }
39
40   /**
41    * @hibernate.id generator-class="assigned"
42    */

43   public String JavaDoc getId() {
44     return id_;
45   }
46
47   public void setId(String JavaDoc value) {
48     id_ = value;
49   }
50
51   /**
52    * @hibernate.property
53    */

54   public String JavaDoc getFolderId() {
55     return folderId_;
56   }
57
58   public void setFolderId(String JavaDoc value) {
59     folderId_ = value;
60   }
61
62   /**
63    * @hibernate.property
64    */

65   public String JavaDoc getMailMessageId() {
66     return mailMessageId_;
67   }
68
69   public void setMailMessageId(String JavaDoc value) {
70     mailMessageId_ = value;
71   }
72
73   public String JavaDoc getFrom() {
74     return from_;
75   }
76
77   public void setFrom(String JavaDoc value) {
78     from_ = value;
79   }
80
81   /**
82    * @hibernate.property
83    */

84   public String JavaDoc getSender() {
85     return from_;
86   }
87
88   public void setSender(String JavaDoc value) {
89     from_ = value;
90   }
91
92   /**
93    * @hibernate.property
94    */

95   public String JavaDoc getFlags() {
96     return flags_;
97   }
98
99   public void setFlags(String JavaDoc value) {
100     flags_ = value;
101   }
102
103   /**
104    * @hibernate.property
105    */

106   public String JavaDoc getSubject() {
107     return subject_;
108   }
109
110   public void setSubject(String JavaDoc value) {
111     subject_ = value;
112   }
113
114   /**
115    * @hibernate.property
116    */

117   public Date JavaDoc getReceivedDate() {
118     return receivedDate_;
119   }
120
121   public void setReceivedDate(Date JavaDoc value) {
122     receivedDate_ = value;
123   }
124
125   public boolean isNew() {
126     return !hasFlag(MessageHeader.SEEN_FLAG);
127   }
128
129   public boolean hasFlag(String JavaDoc flag) {
130     if(flags_ == null) return false ;
131     return flags_.indexOf(flag) >= 0 ;
132   }
133
134   public void addFlag(String JavaDoc flag) {
135     if(flags_ == null || flags_.length() == 0) {
136       flags_ = flag ;
137     } else if(flags_.indexOf(flag) < 0){
138       flags_ = "," + flag ;
139     }
140   }
141
142   public void removeFlag(String JavaDoc flag) {
143     String JavaDoc[] flags = StringUtils.split(flags_, ',');
144     StringBuffer JavaDoc b = new StringBuffer JavaDoc() ;
145     for (int i = 0; i < flags.length; i++) {
146       if (!flags[i].equals(flag)) {
147         if(i == 0) b.append(flags[i]) ;
148         else b.append(',').append(flags[i]) ;
149       }
150     }
151     flags_ = b.toString() ;
152   }
153   
154   public String JavaDoc[] getFlagsAsArray(){
155     return StringUtils.split(flags_, ',');
156   }
157 }
Popular Tags