KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > essiembre > library > scheduler > SchedulerTask


1 /*
2  * Copyright (C) 2003, 2004 Pascal Essiembre, Essiembre Consultant Inc.
3  *
4  * This file is part of Essiembre Scheduler.
5  *
6  * Essiembre Scheduler is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Essiembre Scheduler is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Essiembre Scheduler; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19  * Boston, MA 02111-1307 USA
20  */

21 package com.essiembre.library.scheduler;
22
23
24 import java.util.Enumeration JavaDoc;
25 import java.util.Hashtable JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.TimerTask JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 import javax.servlet.ServletConfig JavaDoc;
31
32 import org.exolab.castor.mapping.MapItem;
33
34
35 /**
36  * A task that can be scheduled for one-time or repeated execution by a
37  * <code>Scheduler</code>. The inherited run() method is called by a
38  * <code>Timer</code> and must be overridden.
39  *
40  * @author Pascal Essiembre
41  * @version $Id: SchedulerTask.java,v 1.3 2004/06/07 03:46:40 essiembre Exp $
42  */

43 public abstract class SchedulerTask
44         extends TimerTask JavaDoc {
45
46     /** Parameters from scheduler configuration file */
47     private final Map JavaDoc initParameters = new Hashtable JavaDoc();
48     
49     /** Application servlet context */
50     private ServletConfig JavaDoc servletConfig;
51
52     /**
53      * Constructor
54      */

55     public SchedulerTask() {
56         super();
57     }
58
59     /**
60      * Gets the servletConfig
61      * @return Returns a ServletConfig
62      */

63     public ServletConfig JavaDoc getServletConfig() {
64         return servletConfig;
65     }
66
67     /**
68      * Sets the servletConfig
69      * @param servletConfig The servletConfig to set
70      */

71     public void setServletConfig(ServletConfig JavaDoc servletConfig) {
72         this.servletConfig = servletConfig;
73     }
74
75     /**
76      * Gets parameter value from scheduler configuration file, matching
77      * supplied parameter name.
78      * @param paramName name of parameter to get
79      * @return parameter value
80      * @since 1.1
81      */

82     public String JavaDoc getInitParameter(String JavaDoc paramName) {
83         return (String JavaDoc) initParameters.get(paramName);
84     }
85     
86     /**
87      * Gets all parameter names defined in scheduler configuration file.
88      * @return parameter names
89      * @since 1.1
90      */

91     public Enumeration JavaDoc getInitParameterNames() {
92         return ((Hashtable JavaDoc) initParameters).keys();
93     }
94     
95     /**
96      * Sets initialization parameters for this scheduler task.
97      * @param initParameters initialization parameters
98      * @since 1.1
99      */

100     protected void setInitParameters(Vector JavaDoc initParameters) {
101         for (int i = 0; i < initParameters.size(); i++) {
102             MapItem mapItem = (MapItem) initParameters.get(i);
103             this.initParameters.put(mapItem.getKey(), mapItem.getValue());
104         }
105     }
106     
107
108 }
Popular Tags