KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > services > ServiceConfigurationView


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13 package org.ejbca.ui.web.admin.services;
14
15
16
17 import java.io.IOException JavaDoc;
18 import java.io.Serializable JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 import javax.faces.model.SelectItem;
25
26 import org.apache.log4j.Logger;
27 import org.ejbca.core.model.services.ServiceConfiguration;
28 import org.ejbca.ui.web.admin.configuration.EjbcaJSFHelper;
29 import org.ejbca.ui.web.admin.services.servicetypes.ActionType;
30 import org.ejbca.ui.web.admin.services.servicetypes.CustomActionType;
31 import org.ejbca.ui.web.admin.services.servicetypes.CustomIntervalType;
32 import org.ejbca.ui.web.admin.services.servicetypes.CustomWorkerType;
33 import org.ejbca.ui.web.admin.services.servicetypes.IntervalType;
34 import org.ejbca.ui.web.admin.services.servicetypes.ServiceType;
35 import org.ejbca.ui.web.admin.services.servicetypes.WorkerType;
36
37 /**
38  * Class resposible for converting the data between the GUI and a
39  * SystemConfiguration VO
40  *
41  * @author Philip Vendil 2006 sep 30
42  *
43  * @version $Id: ServiceConfigurationView.java,v 1.3 2006/10/26 11:02:18 herrvendil Exp $
44  */

45 public class ServiceConfigurationView implements Serializable JavaDoc{
46     private static final Logger log = Logger.getLogger(ServiceConfigurationView.class);
47     
48     private WorkerType workerType;
49     private ActionType actionType;
50     private IntervalType intervalType;
51     
52     private String JavaDoc selectedWorker;
53     private String JavaDoc selectedInterval;
54     private String JavaDoc selectedAction;
55     
56     private ServiceTypeManager typeManager;
57     
58     private boolean active = false;
59     private String JavaDoc description = "";
60     
61     private ServiceConfiguration serviceConfiguration;
62     
63     public ServiceConfigurationView(ServiceConfiguration serviceConfiguration) throws IOException JavaDoc {
64         
65         typeManager = new ServiceTypeManager();
66     
67         this.serviceConfiguration = serviceConfiguration;
68         WorkerType workerType = (WorkerType) typeManager.getServiceTypeByClassPath(serviceConfiguration.getWorkerClassPath());
69         if(workerType == null){
70            workerType = (WorkerType) typeManager.getServiceTypeByName(CustomWorkerType.NAME);
71           ((CustomWorkerType) workerType).setClassPath(serviceConfiguration.getWorkerClassPath());
72         }
73         setWorkerType(workerType);
74         selectedWorker = workerType.getName();
75         
76         IntervalType intervalType = (IntervalType) typeManager.getServiceTypeByClassPath(serviceConfiguration.getIntervalClassPath());
77         if(intervalType == null){
78           intervalType = (IntervalType) typeManager.getServiceTypeByName(CustomIntervalType.NAME);
79           ((CustomIntervalType) intervalType).setClassPath(serviceConfiguration.getIntervalClassPath());
80         }
81         setIntervalType(intervalType);
82         selectedInterval = intervalType.getName();
83         
84         ActionType actionType = (ActionType) typeManager.getServiceTypeByClassPath(serviceConfiguration.getActionClassPath());
85         if(actionType == null){
86           actionType = (ActionType) typeManager.getServiceTypeByName(CustomActionType.NAME);
87           ((CustomActionType) actionType).setClassPath(serviceConfiguration.getActionClassPath());
88         }
89         setActionType(actionType);
90         selectedAction = actionType.getName();
91         
92         setDescription(serviceConfiguration.getDescription());
93         setActive(serviceConfiguration.isActive());
94         
95         
96     }
97     
98     /**
99      * Method that populates a service configuration from a
100      * GUI data.
101      */

102     public ServiceConfiguration getServiceConfiguration(ArrayList JavaDoc errorMessages) throws IOException JavaDoc{
103         ServiceConfiguration retval = new ServiceConfiguration();
104         retval.setActive(isActive());
105         retval.setDescription(getDescription());
106         retval.setActionClassPath(getActionType().getClassPath());
107         retval.setActionProperties(getActionType().getProperties(errorMessages));
108         retval.setIntervalClassPath(getIntervalType().getClassPath());
109         retval.setIntervalProperties(getIntervalType().getProperties(errorMessages));
110         retval.setWorkerClassPath(getWorkerType().getClassPath());
111         retval.setWorkerProperties(getWorkerType().getProperties(errorMessages));
112         return retval;
113     }
114
115     /**
116      * @return the actionType
117      */

118     public ActionType getActionType() {
119         return actionType;
120     }
121
122     /**
123      * @param actionType the actionType to set
124      */

125     public void setActionType(ActionType actionType) {
126         try {
127             actionType.setProperties(serviceConfiguration.getActionProperties());
128         } catch (IOException JavaDoc e) {
129           log.error(e);
130         }
131         this.actionType = actionType;
132     }
133
134     /**
135      * @return the active
136      */

137     public boolean isActive() {
138         return active;
139     }
140
141     /**
142      * @param active the active to set
143      */

144     public void setActive(boolean active) {
145         this.active = active;
146     }
147
148     /**
149      * @return the description
150      */

151     public String JavaDoc getDescription() {
152         return description;
153     }
154
155     /**
156      * @param description the description to set
157      */

158     public void setDescription(String JavaDoc description) {
159         this.description = description;
160     }
161
162     /**
163      * @return the intervalType
164      */

165     public IntervalType getIntervalType() {
166         return intervalType;
167     }
168
169     /**
170      * @param intervalType the intervalType to set
171      */

172     public void setIntervalType(IntervalType intervalType) {
173         try {
174             intervalType.setProperties(serviceConfiguration.getIntervalProperties());
175         } catch (IOException JavaDoc e) {
176           log.error(e);
177         }
178         this.intervalType = intervalType;
179     }
180
181     /**
182      * @return the workerType
183      */

184     public WorkerType getWorkerType() {
185         return workerType;
186     }
187
188     /**
189      * @param workerType the workerType to set
190      */

191     public void setWorkerType(WorkerType workerType) {
192         try{
193           workerType.setProperties(serviceConfiguration.getWorkerProperties());
194           this.workerType = workerType;
195           
196         
197           if(selectedInterval != null && !workerType.getCompatibleIntervalTypeNames().contains(selectedInterval)){
198             setSelectedInterval((String JavaDoc) workerType.getCompatibleIntervalTypeNames().iterator().next());
199             setIntervalType((IntervalType) typeManager.getServiceTypeByName(getSelectedInterval()));
200           }
201           
202         
203           if(selectedAction != null && !workerType.getCompatibleActionTypeNames().contains(selectedAction)){
204             setSelectedAction((String JavaDoc) workerType.getCompatibleActionTypeNames().iterator().next());
205             setActionType((ActionType) typeManager.getServiceTypeByName(getSelectedAction()));
206           }
207           
208         }catch(IOException JavaDoc e){
209             log.error(e);
210         }
211     }
212     
213
214
215     /**
216      * @return the selectedAction
217      */

218     public String JavaDoc getSelectedAction() {
219         return selectedAction;
220     }
221
222     /**
223      * @param selectedAction the selectedAction to set
224      */

225     public void setSelectedAction(String JavaDoc selectedAction) {
226         this.selectedAction = selectedAction;
227     }
228
229     /**
230      * @return the selectedInterval
231      */

232     public String JavaDoc getSelectedInterval() {
233         return selectedInterval;
234     }
235
236     /**
237      * @param selectedInterval the selectedInterval to set
238      */

239     public void setSelectedInterval(String JavaDoc selectedInterval) {
240         this.selectedInterval = selectedInterval;
241     }
242
243     /**
244      * @return the selectedWorker
245      */

246     public String JavaDoc getSelectedWorker() {
247         return selectedWorker;
248     }
249
250     /**
251      * @param selectedWorker the selectedWorker to set
252      */

253     public void setSelectedWorker(String JavaDoc selectedWorker) {
254         this.selectedWorker = selectedWorker;
255     }
256     
257     public List JavaDoc getAvailableWorkers(){
258         ArrayList JavaDoc retval = new ArrayList JavaDoc();
259         Collection JavaDoc available = typeManager.getAvailableWorkerTypes();
260         Iterator JavaDoc iter = available.iterator();
261         while(iter.hasNext()){
262             ServiceType next = (ServiceType) iter.next();
263             String JavaDoc label = next.getName();
264             if(next.isTranslatable()){
265                 label = (String JavaDoc) EjbcaJSFHelper.getBean().getText().get(next.getName());
266             }
267             retval.add(new SelectItem(next.getName(),label));
268         }
269         
270         return retval;
271     }
272     
273     public List JavaDoc getAvailableIntervals(){
274         ArrayList JavaDoc retval = new ArrayList JavaDoc();
275         WorkerType currentWorkerType = (WorkerType) typeManager.getServiceTypeByName(selectedWorker);
276         Iterator JavaDoc iter = currentWorkerType.getCompatibleIntervalTypeNames().iterator();
277         while(iter.hasNext()){
278             String JavaDoc name = (String JavaDoc) iter.next();
279             ServiceType next = typeManager.getServiceTypeByName(name);
280             String JavaDoc label = name;
281             if(next.isTranslatable()){
282                 label = (String JavaDoc) EjbcaJSFHelper.getBean().getText().get(name);
283             }
284             
285             retval.add(new SelectItem(name,label));
286         }
287         
288         
289         return retval;
290     }
291     
292     public List JavaDoc getAvailableActions(){
293         ArrayList JavaDoc retval = new ArrayList JavaDoc();
294         WorkerType currentWorkerType = (WorkerType) typeManager.getServiceTypeByName(selectedWorker);
295         Iterator JavaDoc iter = currentWorkerType.getCompatibleActionTypeNames().iterator();
296         while(iter.hasNext()){
297             String JavaDoc name = (String JavaDoc) iter.next();
298             ServiceType next = typeManager.getServiceTypeByName(name);
299             String JavaDoc label = name;
300             if(next.isTranslatable()){
301                 label = (String JavaDoc) EjbcaJSFHelper.getBean().getText().get(name);
302             }
303             retval.add(new SelectItem(name,label));
304         }
305         return retval;
306     }
307     
308     /** returns this sessions service type manager */
309     public ServiceTypeManager getServiceTypeManager(){
310         return typeManager;
311     }
312     
313     
314     
315
316
317 }
318
Popular Tags