001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.mailing.ejb;
034:
035: import org.libresource.LibresourceResourceBase;
036:
037: import org.libresource.mailing.util.MailingListResourceUtil;
038:
039: import java.util.Vector;
040:
041: import javax.ejb.CreateException;
042:
043: /**
044: * A libresource MailingList
045: *
046: * @libresource.resource name="MailingList" service="LibresourceMailing"
047: *
048: * @ejb.finder
049: * signature= "java.util.Collection findAll()"
050: * query ="SELECT OBJECT(m) FROM MailingListResource m"
051: * transaction-type="Supports"
052: */
053: public abstract class MailingListResourceBean extends
054: LibresourceResourceBase {
055: /**
056: * @ejb.create-method
057: */
058: public String ejbCreate(String mail, String description,
059: String subscribers) throws CreateException {
060: setId(MailingListResourceUtil.generateGUID(this ));
061: setMail(mail);
062: setDescription(description);
063: setSubscribersList(subscribers);
064:
065: return null;
066: }
067:
068: // persistents fields
069:
070: /**
071: * @ejb.persistent-field
072: * @ejb.interface-method
073: * @ejb.value-object match="libresource"
074: * @ejb.transaction type="Supports"
075: */
076: public abstract String getId();
077:
078: /**
079: * @ejb.persistent-field
080: * @ejb.interface-method
081: * @ejb.transaction type="Mandatory"
082: */
083: public abstract void setId(String id);
084:
085: /**
086: * @ejb.interface-method
087: * @ejb.value-object match="libresource"
088: * @ejb.transaction type="Supports"
089: */
090: public String getShortResourceName() {
091: return getMail();
092: }
093:
094: /**
095: * @ejb.persistent-field
096: * @ejb.interface-method
097: * @ejb.value-object match="libresource"
098: * @ejb.transaction type="Supports"
099: */
100: public abstract String getMail();
101:
102: /**
103: * @ejb.persistent-field
104: * @ejb.interface-method
105: * @ejb.transaction type="Mandatory"
106: */
107: public abstract void setMail(String mail);
108:
109: /**
110: * @ejb.persistent-field
111: * @ejb.interface-method
112: * @ejb.value-object match="libresource"
113: * @ejb.transaction type="Supports"
114: */
115: public abstract String getDescription();
116:
117: /**
118: * @ejb.persistent-field
119: * @ejb.interface-method
120: * @ejb.transaction type="Mandatory"
121: */
122: public abstract void setDescription(String description);
123:
124: /**
125: * @ejb.persistent-field
126: * @ejb.interface-method
127: * @ejb.value-object match="libresource"
128: * @ejb.transaction type="Supports"
129: */
130: public abstract String getSubscribersList();
131:
132: /**
133: * @ejb.persistent-field
134: * @ejb.interface-method
135: * @ejb.transaction type="Mandatory"
136: */
137: public abstract void setSubscribersList(String subscribers);
138:
139: // business methods
140:
141: /**
142: * @ejb.interface-method
143: * @ejb.value-object match="libresource"
144: * @ejb.transaction type="Supports"
145: */
146: public String[] getSubscribers() {
147: if ((getSubscribersList() == null)
148: || getSubscribersList().trim().equals("")) {
149: return new String[0];
150: }
151:
152: return getSubscribersList().split(",");
153: }
154:
155: /**
156: * @ejb.interface-method
157: * @ejb.value-object match="libresource"
158: * @ejb.transaction type="Mandatory"
159: */
160: public void setSubscribers(String[] subscribers) {
161: StringBuffer buffer = new StringBuffer();
162:
163: for (int i = 0; i < subscribers.length; i++) {
164: buffer.append(subscribers[i]);
165:
166: if (i != (subscribers.length - 1)) {
167: buffer.append(",");
168: }
169: }
170:
171: setSubscribersList(buffer.toString());
172: }
173:
174: /**
175: * @ejb.interface-method
176: * @ejb.transaction type="Mandatory"
177: */
178: public void addSubscriber(String subscriber) {
179: if (!isSubscriber(subscriber)) {
180: String[] subscribers = getSubscribers();
181: String[] newSubscribers = new String[subscribers.length + 1];
182: System.arraycopy(subscribers, 0, newSubscribers, 0,
183: subscribers.length);
184: newSubscribers[subscribers.length] = subscriber;
185: setSubscribers(newSubscribers);
186: }
187: }
188:
189: /**
190: * @ejb.interface-method
191: * @ejb.transaction type="Mandatory"
192: */
193: public void removeSubscriber(String subscriber) {
194: String[] subscribers = getSubscribers();
195: Vector newSubscribers = new Vector();
196:
197: for (int i = 0; i < subscribers.length; i++) {
198: if (!subscribers[i].equals(subscriber)) {
199: newSubscribers.add(subscribers[i]);
200: }
201: }
202:
203: String[] result = new String[newSubscribers.size()];
204:
205: for (int i = 0; i < newSubscribers.size(); i++) {
206: result[i] = (String) newSubscribers.get(i);
207: }
208:
209: setSubscribers(result);
210: }
211:
212: /**
213: * @ejb.interface-method
214: * @ejb.transaction type="Supports"
215: */
216: public boolean isSubscriber(String subscriber) {
217: String[] subscribers = getSubscribers();
218:
219: for (int i = 0; i < subscribers.length; i++) {
220: if (subscribers[i].equals("User:" + subscriber)) {
221: return true;
222: }
223:
224: if (subscribers[i].equals("Group:" + subscriber)) {
225: return true;
226: }
227: }
228:
229: return false;
230: }
231: }
|