1 17 18 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 32 protected TaskFactory() { 33 } 34 35 private static TaskFactory factory; 36 private static Category log = Category.getInstance(TaskFactory.class); 37 38 43 public static TaskFactory getInstance() { 44 if (factory == null) { 45 factory = new TaskFactory(); 46 } 47 48 return factory; 49 } 50 51 58 public Task createTask(Configuration configuration) { 59 try { 60 String className = configuration.getAttribute("class", 61 "org.apache.lenya.cms.task.TaskSequence"); 62 Class 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 e) { 75 log.error("Cannot create Task: ", e); 76 77 return null; 78 } 79 } 80 } 81 | Popular Tags |