01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: /* $Id: TaskFactory.java 473861 2006-11-12 03:51:14Z gregor $ */
20:
21: package org.apache.lenya.cms.task;
22:
23: import org.apache.avalon.framework.configuration.Configuration;
24: import org.apache.avalon.framework.configuration.ConfigurationException;
25: import org.apache.avalon.framework.parameters.ParameterException;
26: import org.apache.avalon.framework.parameters.Parameters;
27: import org.apache.log4j.Logger;
28:
29: /**
30: * A Task factory
31: * @deprecated Use the usecase framework instead.
32: */
33: public class TaskFactory {
34:
35: /**
36: * Create a new instance of <code>TaskFactory</code>
37: */
38: protected TaskFactory() {
39: // do nothing
40: }
41:
42: private static TaskFactory factory;
43: private static Logger log = Logger.getLogger(TaskFactory.class);
44:
45: /**
46: * Get an instance of the task factory
47: * @return A task factory
48: */
49: public static TaskFactory getInstance() {
50: if (factory == null) {
51: factory = new TaskFactory();
52: }
53:
54: return factory;
55: }
56:
57: /**
58: * Create a task
59: * @param configuration The configuration for the task
60: * @return The task
61: */
62: public Task createTask(Configuration configuration) {
63:
64: try {
65: String className = configuration.getAttribute("class",
66: "org.apache.lenya.cms.task.TaskSequence");
67: Class cl = Class.forName(className);
68: Task task = (Task) cl.newInstance();
69:
70: task.setLabel(configuration.getChild("label").getValue(
71: "default task"));
72:
73: task.parameterize(Parameters
74: .fromConfiguration(configuration));
75:
76: if (task instanceof TaskSequence) {
77: ((TaskSequence) task).init(configuration);
78: }
79:
80: return task;
81: } catch (final ParameterException e) {
82: log.error("Cannot create Task: ", e);
83: return null;
84: } catch (final ConfigurationException e) {
85: log.error("Cannot create Task: ", e);
86: return null;
87: } catch (final ClassNotFoundException e) {
88: log.error("Cannot create Task: ", e);
89: return null;
90: } catch (final InstantiationException e) {
91: log.error("Cannot create Task: ", e);
92: return null;
93: } catch (final IllegalAccessException e) {
94: log.error("Cannot create Task: ", e);
95: return null;
96: }
97: }
98: }
|