KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > role > CreateRoleAction


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.webapp.action.core.role;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.Role;
20 import com.blandware.atleap.service.core.RoleManager;
21 import com.blandware.atleap.service.exception.BeanAlreadyExistsException;
22 import com.blandware.atleap.webapp.action.core.BaseAction;
23 import com.blandware.atleap.webapp.form.RoleForm;
24 import com.blandware.atleap.webapp.util.core.WebappUtil;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.action.ActionMessage;
29 import org.apache.struts.action.ActionMessages;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33
34 /**
35  * <p>Creates new role
36  * </p>
37  * <p><a HREF="CreateRoleAction.java.htm"><i>View Source</i></a></p>
38  * <p/>
39  *
40  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
41  * @version $Revision: 1.13 $ $Date: 2006/03/10 17:10:29 $
42  * @struts.action path="/core/role/create"
43  * name="roleForm"
44  * scope="request"
45  * input="inputForward"
46  * validate="true"
47  * roles="core-role-create"
48  * @struts.action-forward name="inputForward"
49  * path=".core.role.create"
50  * @struts.action-forward name="listRoles"
51  * path="/core/role/list.do"
52  * redirect="true"
53  * @struts.action-forward name="unsatisfiable"
54  * path="/core/role/list.do"
55  */

56 public final class CreateRoleAction extends BaseAction {
57     /**
58      * @param mapping The ActionMapping used to select this instance
59      * @param form The optional ActionForm bean for this request (if any)
60      * @param request The HTTP request we are proceeding
61      * @param response The HTTP response we are creating
62      * @return an ActionForward instance describing where and how
63      * control should be forwarded, or null if response
64      * has already been completed
65      */

66     public ActionForward execute(ActionMapping mapping, ActionForm form,
67                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
68
69         if ( !isCancelled(request) ) {
70
71             RoleForm roleForm = (RoleForm) form;
72             Role role = new Role();
73             WebappUtil.copyProperties(role, roleForm, request);
74             role.setFixed(Boolean.FALSE);
75             RoleManager roleManager = (RoleManager) getBean(Constants.ROLE_MANAGER_BEAN);
76             try {
77                 roleManager.createRole(role);
78             } catch ( BeanAlreadyExistsException e ) {
79                 // role already exists
80
ActionMessages errors = new ActionMessages();
81                 errors.add("roleAlreadyExists", new ActionMessage("core.role.errors.alreadyExists"));
82                 saveErrors(request, errors);
83                 saveToken(request);
84                 return mapping.getInputForward();
85             }
86         }
87         return mapping.findForward("listRoles");
88     }
89 }
Popular Tags