KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > task > TaskFactory


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: TaskFactory.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.task;
21
22 import org.apache.avalon.framework.configuration.Configuration;
23 import org.apache.avalon.framework.parameters.Parameters;
24 import org.apache.log4j.Category;
25
26 public class TaskFactory {
27     
28     /**
29      * Create a new instance of <code>TaskFactory</code>
30      *
31      */

32     protected TaskFactory() {
33     }
34
35     private static TaskFactory factory;
36     private static Category log = Category.getInstance(TaskFactory.class);
37
38     /**
39      * DOCUMENT ME!
40      *
41      * @return DOCUMENT ME!
42      */

43     public static TaskFactory getInstance() {
44         if (factory == null) {
45             factory = new TaskFactory();
46         }
47
48         return factory;
49     }
50
51     /**
52      * DOCUMENT ME!
53      *
54      * @param configuration DOCUMENT ME!
55      *
56      * @return DOCUMENT ME!
57      */

58     public Task createTask(Configuration configuration) {
59         try {
60             String JavaDoc className = configuration.getAttribute("class",
61                     "org.apache.lenya.cms.task.TaskSequence");
62             Class JavaDoc cl = Class.forName(className);
63             Task task = (Task) cl.newInstance();
64
65             task.setLabel(configuration.getChild("label").getValue("default task"));
66
67             task.parameterize(Parameters.fromConfiguration(configuration));
68
69             if (task instanceof TaskSequence) {
70                 ((TaskSequence) task).init(configuration);
71             }
72
73             return task;
74         } catch (Exception JavaDoc e) {
75             log.error("Cannot create Task: ", e);
76
77             return null;
78         }
79     }
80 }
81
Popular Tags