KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > library > listener > UserRemoveBean


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: UserRemoveBean.java,v $
31  * Revision 1.3 2005/04/10 20:31:59 colinmacleod
32  * Added new themes.
33  * Changed id type to String.
34  * Changed i tag to em and b tag to strong.
35  * Improved PicoContainerFactory with NanoContainer scripts.
36  *
37  * Revision 1.2 2005/04/09 17:19:45 colinmacleod
38  * Changed copyright text to GPL v2 explicitly.
39  *
40  * Revision 1.1.1.1 2005/03/10 17:51:59 colinmacleod
41  * Restructured ivata op around Hibernate/PicoContainer.
42  * Renamed ivata groupware.
43  *
44  * Revision 1.4 2004/07/13 19:47:29 colinmacleod
45  * Moved project to POJOs from EJBs.
46  * Applied PicoContainer to services layer (replacing session EJBs).
47  * Applied Hibernate to persistence layer (replacing entity EJBs).
48  *
49  * Revision 1.3 2004/03/21 21:16:29 colinmacleod
50  * Shortened name to ivata op.
51  *
52  * Revision 1.2 2004/02/01 22:07:31 colinmacleod
53  * Added full names to author tags
54  *
55  * Revision 1.1.1.1 2004/01/27 20:58:40 colinmacleod
56  * Moved ivata openportal to SourceForge..
57  *
58  * Revision 1.5 2003/11/13 16:11:08 jano
59  * commitng everything to CVS
60  * can deploy and application is ruuning, can login into
61  *
62  * Revision 1.4 2003/11/03 11:29:44 jano
63  * commiting library,
64  * tryinjg to fix deploying problem
65  *
66  * Revision 1.3 2003/10/28 13:16:14 jano
67  * commiting library,
68  * still fixing compile and building openGroupware project
69  *
70  * Revision 1.2 2003/10/15 14:16:53 colin
71  * fixing for XDoclet
72  * -----------------------------------------------------------------------------
73  */

74 package com.ivata.groupware.business.library.listener;
75
76 import javax.ejb.EJBException JavaDoc;
77 import javax.ejb.MessageDrivenBean JavaDoc;
78 import javax.ejb.MessageDrivenContext JavaDoc;
79 import javax.jms.JMSException JavaDoc;
80 import javax.jms.Message JavaDoc;
81 import javax.jms.MessageListener JavaDoc;
82 import javax.jms.ObjectMessage JavaDoc;
83
84 import com.ivata.groupware.admin.security.user.UserEvent;
85
86
87 /**
88  * <p>This bean listens for events when a user is removed.</p>
89  *
90  * @since 2003-10-09
91  * @author Colin MacLeod
92  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
93  * @version $Revision: 1.3 $
94  *
95  * @ejb.bean
96  * name = "UserRemoveLibrary"
97  * display-name = "UserRemoveLibrary"
98  * acknowledge-mode = "Auto-acknowledge"
99  * destination-type = "javax.jms.Topic"
100  *
101  * @jboss.destination-jndi-name
102  * name = "topic/topicUserRemove"
103  */

104 public class UserRemoveBean implements MessageDrivenBean JavaDoc, MessageListener JavaDoc {
105     MessageDrivenContext JavaDoc messageDrivenContext;
106
107     public void ejbCreate() {
108     }
109
110     public void ejbRemove() {
111     }
112
113     public void onMessage(final Message JavaDoc message) {
114         // check this is an object message
115
if (!ObjectMessage JavaDoc.class.isInstance(message)) {
116             throw new EJBException JavaDoc(
117                 "ERROR in folder.UserRemoveBean: unknown messaage class (" +
118                 message.getClass().getName() + ")");
119         }
120
121         ObjectMessage JavaDoc objectMessage = (ObjectMessage JavaDoc) message;
122         UserEvent userEvent = null;
123
124         try {
125             userEvent = (UserEvent) objectMessage.getObject();
126         } catch (JMSException JavaDoc e) {
127             throw new EJBException JavaDoc(e);
128         }
129
130         String JavaDoc userName = userEvent.getUserName();
131
132         /**
133 try {
134     boolean deleteUser = true;
135     // check if we can removeUser
136     // find library items
137     LibraryItemLocalHome libraryItemHome = (LibraryItemLocalHome)
138         ApplicationServer.findLocalHome("LibraryItemLocal",
139             LibraryItemLocalHome.class);
140     java.util.Collection items = libraryItemHome.findByCreatedBy(this.getName());
141
142
143     // if he has not LIN -> find comments
144     if (items.isEmpty()) {
145         CommentLocalHome commentHome = (CommentLocalHome)
146             ApplicationServer.findLocalHome("CommentLocal",
147                 CommentLocalHome.class);
148         java.util.Collection comments = commentHome.findByUserName(this.getName());
149
150         // if he has not comments -> find files
151         if (comments.isEmpty()) {
152             FileLocalHome fileHome = (FileLocalHome)
153                 ApplicationServer.findLocalHome("FileLocal",
154                     FileLocalHome.class);
155             java.util.Collection files = fileHome.findByUserName(this.getName());
156
157             // if he has not files -> find events
158             // if he has events in futer he can have privet events
159             if (files.isEmpty()) {
160                 EventLocalHome eventHome = (EventLocalHome)
161                     ApplicationServer.findLocalHome("EventLocal",
162                         EventLocalHome.class);
163                 java.util.Collection events = eventHome.findByUserName(this.getName());
164
165                 //if he has not events -> find groups
166                 if (events.isEmpty()) {
167
168                     java.util.Collection groups = groupHome.findByCreatedBy(this.getName());
169
170                     // if he has not groups -> find contacts
171                     if (groups.isEmpty()) {
172                         PersonLocalHome personHome = (PersonLocalHome)
173                             ApplicationServer.findLocalHome("PersonLocal",
174                                 PersonLocalHome.class);
175                         java.util.Collection persons = personHome.findByCreatedBy(this.getName());
176
177                         if (!persons.isEmpty()) {
178                             deleteUser = false;
179                         }
180
181                     } else {
182                         deleteUser = false;
183                     }
184
185                 } else {
186                     deleteUser = false;
187                 }
188             } else {
189                 deleteUser = false;
190             }
191         } else {
192             deleteUser = false;
193         }
194     } else {
195         deleteUser = false;
196     }
197 } catch (FinderException e) {
198     throw new EJBException(e);
199 } catch (NamingException e) {
200     throw new EJBException(e);
201 } catch (RemoveException e) {
202     throw new EJBException(e);
203 }
204 */

205     }
206
207     public final void setMessageDrivenContext(final MessageDrivenContext JavaDoc messageDrivenContext) {
208         this.messageDrivenContext = messageDrivenContext;
209     }
210 }
211
Popular Tags