KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > service > core > impl > RoleManagerImpl


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.service.core.impl;
17
18 import com.blandware.atleap.common.util.PartialCollection;
19 import com.blandware.atleap.common.util.QueryInfo;
20 import com.blandware.atleap.model.core.Role;
21 import com.blandware.atleap.persistence.core.RoleDAO;
22 import com.blandware.atleap.service.core.RoleManager;
23 import com.blandware.atleap.service.exception.BeanAlreadyExistsException;
24 import com.blandware.atleap.service.exception.BeanNotFoundException;
25
26 /**
27  * <p>Implementation of RoleManager interface.
28  * </p>
29  * <p><a HREF="RoleManagerImpl.java.htm"> <i>View Source </i> </a>
30  * </p>
31  *
32  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
33  * @version $Revision: 1.11 $ $Date: 2006/03/06 18:12:30 $
34  */

35 public class RoleManagerImpl extends BaseManagerImpl implements RoleManager {
36
37     /**
38      * Role DAO
39      */

40     protected RoleDAO roleDAO;
41
42     /**
43      * Sets DAO to work with roles
44      *
45      * @param dao DAO to set
46      */

47     public void setRoleDAO(RoleDAO dao) {
48         this.roleDAO = dao;
49     }
50
51     // ~ CRUD Methods ================================================================
52

53     /**
54      * @see com.blandware.atleap.service.core.RoleManager#createRole(com.blandware.atleap.model.core.Role)
55      */

56     public void createRole(Role role) throws BeanAlreadyExistsException {
57         if ( log.isDebugEnabled() ) {
58             log.debug("Creating new Role [roleName=" + role.getName() + "]...");
59         }
60
61         // check is done directly, because it is impossible to write one query for create and update methods
62
Role tmp = roleDAO.retrieveRole(role.getName());
63         if ( tmp != null ) {
64             // role with the same name already exists
65
String JavaDoc errorMessage = "Role with the name '" + role.getName() + "' already exists";
66             if ( log.isErrorEnabled() ) {
67                 log.error(errorMessage);
68             }
69             throw new BeanAlreadyExistsException(errorMessage);
70         }
71         tmp = roleDAO.findRoleByTitle(role.getTitle());
72         if ( tmp != null ) {
73             // role with the same title already exists
74
String JavaDoc errorMessage = "Role with the title '" + role.getTitle() + "' already exists";
75             if ( log.isErrorEnabled() ) {
76                 log.error(errorMessage);
77             }
78             throw new BeanAlreadyExistsException(errorMessage);
79         }
80         roleDAO.createRole(role);
81
82         if ( log.isDebugEnabled() ) {
83             log.debug("New role has been created succesfully");
84         }
85     }
86
87     /**
88      * @see com.blandware.atleap.service.core.RoleManager#retrieveRole(java.lang.String)
89      */

90     public Role retrieveRole(String JavaDoc roleName) {
91         Role role = null;
92         role = roleDAO.retrieveRole(roleName);
93         return role;
94     }
95
96     /**
97      * @see com.blandware.atleap.service.core.RoleManager#updateRole(com.blandware.atleap.model.core.Role)
98      */

99     public void updateRole(Role role) throws BeanAlreadyExistsException {
100
101         // remove role from cache in order to prevent Hibernate from assigning new version number
102
roleDAO.removeFromCache(role);
103         if ( log.isDebugEnabled() ) {
104             log.debug("Updating Role [roleName=" + role.getName() + "]...");
105         }
106
107         if ( roleDAO.hasDuplicates(role) ) {
108             throw new BeanAlreadyExistsException("Role with the same title already exists");
109         }
110
111         roleDAO.updateRole(role);
112
113         if ( log.isDebugEnabled() ) {
114             log.debug("Role has been updated succesfully");
115         }
116     }
117
118     /**
119      * @see com.blandware.atleap.service.core.RoleManager#deleteRole(java.lang.String)
120      */

121     public void deleteRole(String JavaDoc roleName) throws BeanNotFoundException {
122         Role role = roleDAO.retrieveRole(roleName);
123         if ( role == null ) {
124             String JavaDoc errorMessage = "No role with ID=" + role + "could be found";
125             throw new BeanNotFoundException(errorMessage);
126         }
127         roleDAO.deleteRole(role);
128     }
129
130     // ~ Additional methods ================================================================
131

132     /**
133      * @see com.blandware.atleap.service.core.RoleManager#listRoles(com.blandware.atleap.common.util.QueryInfo)
134      */

135     public PartialCollection listRoles(QueryInfo queryInfo) {
136         return roleDAO.listRoles(queryInfo);
137     }
138
139 }
Popular Tags