KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
16 import java.util.Date JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.Properties JavaDoc;
20
21 import org.ejbca.core.model.UpgradeableDataHashMap;
22
23 /**
24  * Value class used for persist the worker, interval and action configurations
25  * to database
26  *
27  * @author Philip Vendil 2006 sep 27
28  *
29  * @version $Id: ServiceConfiguration.java,v 1.4 2006/11/11 12:57:23 herrvendil Exp $
30  */

31 public class ServiceConfiguration extends UpgradeableDataHashMap implements Serializable JavaDoc, Cloneable JavaDoc {
32
33     private static final float LATEST_VERSION = 1;
34     
35     private static final String JavaDoc INTERVALCLASSPATH = "INTERVALCLASSPATH";
36     private static final String JavaDoc INTERVALPROPERTIES = "INTERVALPROPERTIES";
37     private static final String JavaDoc WORKERCLASSPATH = "WORKERCLASSPATH";
38     private static final String JavaDoc WORKERPROPERTIES = "WORKERPROPERTIES";
39     private static final String JavaDoc ACTIONCLASSPATH = "ACTIONCLASSPATH";
40     private static final String JavaDoc ACTIONPROPERTIES = "ACTIONPROPERTIES";
41     private static final String JavaDoc DESCRIPTION = "DESCRIPTION";
42     private static final String JavaDoc ACTIVE = "ACTIVE";
43     private static final String JavaDoc NEXTRUNTIMESTAMP = "NEXTRUNTIMESTAMP";
44     
45     /**
46      * Constructor used to create a new service configuration.
47      */

48     public ServiceConfiguration(){
49         setActive(false);
50         setDescription("");
51         setActionClassPath("");
52         setActionProperties(new Properties JavaDoc());
53         setWorkerClassPath("");
54         setWorkerProperties(new Properties JavaDoc());
55         setIntervalClassPath("");
56         setIntervalProperties(new Properties JavaDoc());
57         setNextRunTimestamp(new Date JavaDoc(0));
58     }
59     
60     
61     /**
62      * @return the Action Class Path
63      */

64     public String JavaDoc getActionClassPath() {
65         return (String JavaDoc) data.get(ACTIONCLASSPATH);
66     }
67
68     /**
69      * @param actionClassPath the actionClassPath to set
70      */

71     public void setActionClassPath(String JavaDoc actionClassPath) {
72         data.put(ACTIONCLASSPATH,actionClassPath);
73     }
74
75     /**
76      * @return the actionProperties
77      */

78     public Properties JavaDoc getActionProperties() {
79         return (Properties JavaDoc) data.get(ACTIONPROPERTIES);
80     }
81
82     /**
83      * @param actionProperties the actionProperties to set
84      */

85     public void setActionProperties(Properties JavaDoc actionProperties) {
86         data.put(ACTIONPROPERTIES, actionProperties);
87     }
88
89     /**
90      * @return the active
91      */

92     public boolean isActive() {
93         return ((Boolean JavaDoc) data.get(ACTIVE)).booleanValue();
94     }
95
96     /**
97      * @param active the active to set
98      */

99     public void setActive(boolean active) {
100         data.put(ACTIVE, new Boolean JavaDoc(active));
101     }
102     
103     /**
104      * @return the date of the next time this service should run.
105      * This is a special service flag ensuring that not two nodes
106      * runs the service at the same time.
107      *
108      */

109     public Date JavaDoc getNextRunTimestamp() {
110         if(data.get(NEXTRUNTIMESTAMP) == null){
111             return new Date JavaDoc(0);
112         }
113         
114         return new Date JavaDoc(((Long JavaDoc) data.get(NEXTRUNTIMESTAMP)).longValue());
115     }
116
117     /**
118      * @param active the active to set
119      */

120     public void setNextRunTimestamp(Date JavaDoc nextRunTimeStamp) {
121         data.put(NEXTRUNTIMESTAMP, new Long JavaDoc(nextRunTimeStamp.getTime()));
122     }
123
124     /**
125      * @return the description
126      */

127     public String JavaDoc getDescription() {
128         return (String JavaDoc) data.get(DESCRIPTION);
129     }
130
131     /**
132      * @param description the description to set
133      */

134     public void setDescription(String JavaDoc description) {
135         data.put(DESCRIPTION, description);
136     }
137
138     /**
139      * @return the intervalClassPath
140      */

141     public String JavaDoc getIntervalClassPath() {
142         return (String JavaDoc) data.get(INTERVALCLASSPATH);
143     }
144
145     /**
146      * @param intervalClassPath the intervalClassPath to set
147      */

148     public void setIntervalClassPath(String JavaDoc intervalClassPath) {
149         data.put(INTERVALCLASSPATH,intervalClassPath);
150     }
151
152     /**
153      * @return the intervalProperties
154      */

155     public Properties JavaDoc getIntervalProperties() {
156         return (Properties JavaDoc) data.get(INTERVALPROPERTIES);
157     }
158
159     /**
160      * @param intervalProperties the intervalProperties to set
161      */

162     public void setIntervalProperties(Properties JavaDoc intervalProperties) {
163         data.put(INTERVALPROPERTIES, intervalProperties);
164     }
165
166     /**
167      * @return the workerClassPath
168      */

169     public String JavaDoc getWorkerClassPath() {
170         return (String JavaDoc) data.get(WORKERCLASSPATH);
171     }
172
173     /**
174      * @param workerClassPath the workerClassPath to set
175      */

176     public void setWorkerClassPath(String JavaDoc workerClassPath) {
177         data.put(WORKERCLASSPATH,workerClassPath);
178     }
179
180     /**
181      * @return the workerProperties
182      */

183     public Properties JavaDoc getWorkerProperties() {
184         return (Properties JavaDoc) data.get(WORKERPROPERTIES);
185     }
186
187     /**
188      * @param workerProperties the workerProperties to set
189      */

190     public void setWorkerProperties(Properties JavaDoc workerProperties) {
191         data.put(WORKERPROPERTIES, workerProperties);
192     }
193
194     public float getLatestVersion() {
195         return LATEST_VERSION;
196     }
197
198     public void upgrade() {
199        if(getVersion() != LATEST_VERSION){
200            
201        }
202     }
203     
204     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
205         ServiceConfiguration clone = new ServiceConfiguration();
206         HashMap JavaDoc clonedata = (HashMap JavaDoc) clone.saveData();
207
208         Iterator JavaDoc i = (data.keySet()).iterator();
209         while(i.hasNext()){
210           Object JavaDoc key = i.next();
211           clonedata.put(key, data.get(key));
212         }
213
214         clone.loadData(clonedata);
215         return clone;
216       }
217     
218     
219
220 }
221
Popular Tags