KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > services > BaseWorker


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.core.model.services;
14
15 import java.util.Properties JavaDoc;
16
17 import org.apache.log4j.Logger;
18 import org.ejbca.core.model.InternalResources;
19 import org.ejbca.core.model.log.Admin;
20 import org.ejbca.core.model.services.intervals.DummyInterval;
21
22 /**
23  * Abstract base class that initializes the worker and its interval and action.
24  *
25  * @author Philip Vendil 2006 sep 27
26  *
27  * @version $Id: BaseWorker.java,v 1.6 2006/12/13 10:35:09 anatom Exp $
28  */

29 public abstract class BaseWorker extends BaseServiceComponent implements IWorker {
30
31     private static final Logger log = Logger.getLogger(BaseWorker.class);
32     
33     /** Internal localization of logs and errors */
34     private static final InternalResources intres = InternalResources.getInstance();
35     
36     protected Properties JavaDoc properties = null;
37     protected String JavaDoc serviceName = null;
38     private IAction action = null;
39     private IInterval interval = null;
40     
41     private Admin admin = null;
42
43     /**
44      * @see org.ejbca.core.model.services.IWorker#init(org.ejbca.core.model.services.ServiceConfiguration, java.lang.String)
45      */

46     public void init(Admin admin, ServiceConfiguration serviceConfiguration,
47             String JavaDoc serviceName) {
48         this.admin = admin;
49         this.serviceName = serviceName;
50         this.properties = serviceConfiguration.getWorkerProperties();
51         
52         String JavaDoc actionClassPath = serviceConfiguration.getActionClassPath();
53         if(actionClassPath != null){
54             try {
55                 action = (IAction) this.getClass().getClassLoader().loadClass(actionClassPath).newInstance();
56                 action.init(serviceConfiguration.getActionProperties(), serviceName);
57             } catch (Exception JavaDoc e) {
58                 String JavaDoc msg = intres.getLocalizedMessage("services.erroractionclasspath", serviceName);
59                 log.error(msg,e);
60             }
61         }else{
62             log.debug("Warning no action class i defined for the service " + serviceName);
63         }
64         
65         String JavaDoc intervalClassPath = serviceConfiguration.getIntervalClassPath();
66         if(intervalClassPath != null){
67             try {
68                 interval = (IInterval) this.getClass().getClassLoader().loadClass(intervalClassPath).newInstance();
69                 interval.init(serviceConfiguration.getIntervalProperties(), serviceName);
70             } catch (Exception JavaDoc e) {
71                 String JavaDoc msg = intres.getLocalizedMessage("services.errorintervalclasspath", serviceName);
72                 log.error(msg,e);
73             }
74         }else{
75             String JavaDoc msg = intres.getLocalizedMessage("services.errorintervalclasspath", serviceName);
76             log.error(msg);
77         }
78         
79         if(interval == null){
80             interval = new DummyInterval();
81         }
82
83     }
84
85     
86     /**
87      * @see org.ejbca.core.model.services.IWorker#getNextInterval()
88      */

89     public long getNextInterval() {
90         return interval.getTimeToExecution();
91     }
92     
93     protected IAction getAction(){
94         if(action == null){
95             String JavaDoc msg = intres.getLocalizedMessage("services.erroractionclasspath", serviceName);
96             log.error(msg);
97         }
98         return action;
99     }
100     
101     /**
102      * Returns the admin that should be used for other calls.
103      */

104     protected Admin getAdmin(){
105         return admin;
106     }
107     
108
109 }
110
Popular Tags