KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > workflowtool > function > Owner


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23 package org.infoglue.cms.applications.workflowtool.function;
24
25 import org.infoglue.cms.controllers.kernel.impl.simple.GroupControllerProxy;
26 import org.infoglue.cms.controllers.kernel.impl.simple.RoleControllerProxy;
27 import org.infoglue.cms.security.InfoGlueGroup;
28 import org.infoglue.cms.security.InfoGlueRole;
29 import org.infoglue.cms.util.workflow.OwnerFactory;
30
31 import com.opensymphony.workflow.WorkflowException;
32
33 /**
34  * This function is used for creating an owner object that can be used to set the owner in the workflow definition file.
35  * <p>
36  * If the <code>group</code> argument is specified, then all users that are members of both the role and the group will be owners.
37  * Otherwise all users that are members of the role will be owners.
38  * </p>
39  * <p>
40  * <code>
41  * &lt;result old-status="Finished" status="Queued" step="1" owner="${<strong>owner</strong>}"&gt;
42  * </code>
43  * </p>
44  * <h1 class="workflow">Context in</h1>
45  * <table class="workflow">
46  * <thead class="workflow">
47  * <tr class="workflow"><th class="workflow">Name</th><th class="workflow">Type</th><th class="workflow">Class</th><th class="workflow">Required</th><th class="workflow">Default</th><th class="workflow">Comments</th></tr>
48  * </thead>
49  * <tbody class="workflow">
50  * <tr class="workflow"><td class="workflow">role</td><td class="workflow">argument</td><td class="workflow">String</td><td class="workflow">true</td><td class="workflow">-</td><td class="workflow_comment">The name of the InfoGlueRole.</td></tr>
51  * <tr class="workflow"><td class="workflow">group</td><td class="workflow">argument</td><td class="workflow">String</td><td class="workflow">false</td><td class="workflow">-</td><td class="workflow_comment">The name of the InfoGlueGroup.</td></tr>
52  * </tbody>
53  * </table>
54  * <h1 class="workflow">Context out</h1>
55  * <table class="workflow">
56  * <thead class="workflow">
57  * <tr class="workflow"><th class="workflow">Name</th><th class="workflow">Type</th><th class="workflow">Class</th><th class="workflow">Comments</th></tr>
58  * </thead>
59  * <tbody class="workflow">
60  * <tr class="workflow"><td class="workflow">owner</td><td class="workflow">parameter</td><td class="workflow">org.infoglue.cms.util.workflow.Owner</td><td class="workflow_comment">The owner object.</td></tr>
61  * </tbody>
62  * </table>
63  */

64 public class Owner extends InfoglueFunction
65 {
66     /**
67      * The key used by the <code>owner</code> in the <code>parameters</code>.
68      */

69     private static final String JavaDoc OWNER_PARAMETER = "owner";
70     
71     /**
72      * The name of the role argument.
73      */

74     private static final String JavaDoc ROLE_ARGUMENT = "role";
75     
76     /**
77      * The name of the group argument.
78      */

79     private static final String JavaDoc GROUP_ARGUMENT = "group";
80     
81     /**
82      * The name of the owner role.
83      */

84     private String JavaDoc roleName;
85     
86     /**
87      * The name of the owner group (optional).
88      */

89     private String JavaDoc groupName;
90     
91     /**
92      * Default constructor.
93      */

94     public Owner()
95     {
96         super();
97     }
98
99     /**
100      * Checks if the group is specified, creates the owner object and stores it in the parameters.
101      *
102      * @throws WorkflowException if an error occurs during the execution.
103      */

104     protected void execute() throws WorkflowException
105     {
106         try
107         {
108             final InfoGlueRole role = RoleControllerProxy.getController(getDatabase()).getRole(roleName);
109             if(groupName == null)
110             {
111                 setParameter(OWNER_PARAMETER, OwnerFactory.create(role).getIdentifier());
112             }
113             else
114             {
115                 final InfoGlueGroup group = GroupControllerProxy.getController(getDatabase()).getGroup(groupName);
116                 setParameter(OWNER_PARAMETER, OwnerFactory.create(role, group).getIdentifier());
117             }
118         }
119         catch(Exception JavaDoc e)
120         {
121             throwException(e);
122         }
123     }
124     
125     /**
126      * Method used for initializing the function; will be called before <code>execute</code> is called.
127      * <p><strong>Note</strong>! You must call <code>super.initialize()</code> first.</p>
128      *
129      * @throws WorkflowException if an error occurs during the initialization.
130      */

131     protected void initialize() throws WorkflowException
132     {
133         super.initialize();
134         this.roleName = getArgument(ROLE_ARGUMENT);
135         this.groupName = getArgument(GROUP_ARGUMENT, null);
136     }
137 }
138
Popular Tags