KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > scheduler > ServletJobFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: ServletJobFactory.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.scheduler;
21
22 import org.apache.log4j.Category;
23
24
25 /**
26  * Factory for building serlvet jobs.
27  */

28 public final class ServletJobFactory {
29     
30     /**
31      * Ctor.
32      */

33     private ServletJobFactory() {
34     }
35
36     private static Category log = Category.getInstance(ServletJobFactory.class);
37
38     /**
39      * Creates a job.
40      * @param jobClassName The name of the Java class used to instanciate the job object.
41      * @return A servlet job.
42      */

43     public static ServletJob createJob(String JavaDoc jobClassName) {
44         try {
45             Class JavaDoc cl = Class.forName(jobClassName);
46
47             return createJob(cl);
48         } catch (Exception JavaDoc e) {
49             log.error("Cannot create Job instance: " + e);
50
51             return null;
52         }
53     }
54
55     /**
56      * Creates a job.
57      *
58      * @param cl The Java class used to instanciate the job object.
59      *
60      * @return A servlet job.
61      */

62     public static ServletJob createJob(Class JavaDoc cl) {
63         try {
64             ServletJob job = (ServletJob) cl.newInstance();
65
66             return job;
67         } catch (Exception JavaDoc e) {
68             log.error("Cannot create Job instance: " + e);
69
70             return null;
71         }
72     }
73     
74 }
75
Popular Tags