KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > navigation > NavigationImpl


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: NavigationImpl.java,v $
31  * Revision 1.3 2005/04/10 20:09:39 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:09 colinmacleod
38  * Changed copyright text to GPL v2 explicitly.
39  *
40  * Revision 1.1.1.1 2005/03/10 17:50:35 colinmacleod
41  * Restructured ivata op around Hibernate/PicoContainer.
42  * Renamed ivata groupware.
43  *
44  * Revision 1.4 2004/11/12 18:17:11 colinmacleod
45  * Ordered imports.
46  *
47  * Revision 1.3 2004/11/12 15:57:07 colinmacleod
48  * Removed dependencies on SSLEXT.
49  * Moved Persistence classes to ivata masks.
50  *
51  * Revision 1.2 2004/07/19 18:17:34 colinmacleod
52  * Made synchronized collection.
53  *
54  * Revision 1.1 2004/07/13 19:41:16 colinmacleod
55  * Moved project to POJOs from EJBs.
56  * Applied PicoContainer to services layer (replacing session EJBs).
57  * Applied Hibernate to persistence layer (replacing entity EJBs).
58  * -----------------------------------------------------------------------------
59  */

60 package com.ivata.groupware.navigation;
61
62
63 import java.util.Collection JavaDoc;
64 import java.util.Collections JavaDoc;
65
66 import javax.ejb.EJBException JavaDoc;
67
68 import com.ivata.groupware.admin.security.server.SecuritySession;
69 import com.ivata.groupware.business.BusinessLogic;
70 import com.ivata.groupware.container.persistence.QueryPersistenceManager;
71 import com.ivata.groupware.navigation.menu.item.MenuItemDO;
72 import com.ivata.mask.persistence.PersistenceSession;
73 import com.ivata.mask.util.SystemException;
74
75
76 /**
77  * <p>Lets you access the menues and folders in the system and generally get
78  * around.</p>
79  *
80  * @since 2002-05-07
81  * @author Colin MacLeod
82  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
83  * @version $Revision: 1.3 $
84  */

85 public class NavigationImpl extends BusinessLogic implements Navigation {
86     /**
87      * Persistence manger used to store/retrieve data objects, or retrieve a
88      * new persistence session.
89      */

90     private QueryPersistenceManager persistenceManager;
91
92     /**
93      * Construct and initialize the navigation implementation.
94      *
95      * @param persistenceManager persistence manager used to store/retrieve data
96      * objects.
97      */

98     public NavigationImpl(QueryPersistenceManager persistenceManager) {
99         this.persistenceManager = persistenceManager;
100     }
101
102     /**
103      * <p>Add a new menu item, with no image associated with it initially.</p>
104      *
105      * @param userName the user for whom to insert the new menu item, or
106      * <code>null</code> if everyone should see it.
107      * @param menuId the unique identifier of the menu into which the new item
108      * will be inserted.
109      * @param text human-readable english language text for the menu item.
110      * Should be unique within the menu it is in though this is not enforced
111      * server-side.
112      * @param URL the <code>URL</code> the new menu item links to.
113      *
114      * @ejb.interface-method
115      * view-type="remote"
116      */

117     public void addMenuItem(final SecuritySession securitySession,
118             final MenuItemDO menuItem)
119             throws SystemException {
120         PersistenceSession persistenceSession = persistenceManager.openSession(securitySession);
121         try {
122             persistenceManager.add(persistenceSession, menuItem);
123         } catch (Exception JavaDoc e) {
124             persistenceSession.cancel();
125             throw new SystemException(e);
126         } finally {
127             persistenceSession.close();
128         }
129     }
130
131     /**
132      * <p>changes a menu item, if it belongs to the given user</p>
133      *
134      * @param menuItemId the unique identifier of the menu item to change.
135      * @param text human-readable english language text for the menu item.
136      * Should be unique within the menu it is in though this is not enforced
137      * server-side.
138      * @param URL the <code>URL</code> the new menu item links to.
139      * @param userName the user for whom the menu item should belong
140      *
141      * @ejb.interface-method
142      * view-type="remote"
143      */

144     public void amendMenuItem(final SecuritySession securitySession,
145             final MenuItemDO menuItem)
146             throws SystemException {
147         PersistenceSession persistenceSession = persistenceManager.openSession(securitySession);
148         try {
149             persistenceManager.amend(persistenceSession, menuItem);
150         } catch (Exception JavaDoc e) {
151             persistenceSession.cancel();
152             throw new SystemException(e);
153         } finally {
154             persistenceSession.close();
155         }
156     }
157
158     /**
159      * <p>Find all the menues for a given user.</p>
160      *
161      * @param userName the user to search for
162      * @return a <code>Collection</code>Containing all the user's menues, as
163      * instances of {@link com.ivata.groupware.menu.MenuDO MenuDO}
164      * @see com.ivata.groupware.menu.MenuDOHome#findByUserName( String sUserName )
165      * @throws EJBException if there is a <code>FinderException</code> calling
166      * <code>MenuDOHome.findByUserName</code>
167      * @throws EJBException if there is a <code>NamingException</code> setting
168      * looking up the MenuHome
169      *
170      * @ejb.interface-method
171      * view-type="remote"
172      */

173     public Collection JavaDoc findMenues(final SecuritySession securitySession)
174             throws SystemException {
175         PersistenceSession persistenceSession = persistenceManager.openSession(securitySession);
176         try {
177             return Collections.synchronizedCollection(persistenceManager.find(
178                     persistenceSession,
179                     "navigationMenuByUserNameOrderByPriority",
180                     new Object JavaDoc[] {securitySession.getUser().getName()}));
181         } catch (Exception JavaDoc e) {
182             persistenceSession.cancel();
183             throw new SystemException(e);
184         } finally {
185             persistenceSession.close();
186         }
187     }
188
189     /**
190      * <p>removes a menu item, if it belongs to the given user</p>
191      *
192      * @param menuItemId the unique identifier of the menu item to remove.
193      * @param userName the user for whom the menu item should belong
194      *
195      * @ejb.interface-method
196      * view-type="remote"
197      */

198     public void removeMenuItem(final SecuritySession securitySession,
199             final String JavaDoc menuItemId)
200             throws SystemException {
201         PersistenceSession persistenceSession =
202             persistenceManager.openSession(securitySession);
203         try {
204             persistenceManager.remove(persistenceSession,
205                     MenuItemDO.class, menuItemId);
206         } catch (Exception JavaDoc e) {
207             persistenceSession.cancel();
208             throw new SystemException(e);
209         } finally {
210             persistenceSession.close();
211         }
212     }
213 }
214
Popular Tags