1 64 65 package com.jcorporate.expresso.services.job; 66 67 import com.jcorporate.expresso.core.controller.Controller; 68 import com.jcorporate.expresso.core.controller.ControllerRequest; 69 import com.jcorporate.expresso.core.controller.ControllerResponse; 70 import com.jcorporate.expresso.core.controller.Output; 71 import com.jcorporate.expresso.core.job.Job; 72 import com.jcorporate.expresso.core.job.ServerException; 73 import com.jcorporate.expresso.core.misc.ConfigManager; 74 import com.jcorporate.expresso.core.misc.StringUtil; 75 76 import java.util.Enumeration ; 77 import java.util.Hashtable ; 78 import java.util.Iterator ; 79 80 81 89 public class ControllerJob 90 extends Job { 91 92 97 public String getTitle() { 98 return "ControllerJob"; 99 } 100 101 106 public void run() { 107 super.run(); 108 try { 109 StringBuffer mailMsg = new StringBuffer (""); 110 String controllerName = StringUtil.notNull(getJobParameter(Controller.CONTROLLER_PARAM_KEY)); 111 112 if (controllerName.equals("")) { 113 throw new ServerException("Parameter 'controller' " + 114 "must be specified"); 115 } 116 117 Controller myController = ConfigManager.getControllerFactory().getController(controllerName); 118 ControllerRequest cparams = new ControllerRequest(); 119 120 Hashtable names = getParameterNamesAndDescriptions(); 122 Hashtable namesValues = new Hashtable (names.size()); 123 for (Iterator iterator = names.keySet().iterator(); iterator.hasNext();) { 124 String name = (String ) iterator.next(); 125 namesValues.put(name, getJobParameter(name)); 126 } 127 cparams.setParameters(namesValues); 128 129 String newState = StringUtil.notNull(getJobParameter(Controller.STATE_PARAM_KEY)); 130 ControllerResponse myResponse = myController.newState(newState, 131 cparams); 132 Output oneOutput = null; 133 134 for (Enumeration ov = myResponse.getOutputs().elements(); 135 ov.hasMoreElements();) { 136 oneOutput = (Output) ov.nextElement(); 137 mailMsg.append("\n" + oneOutput.getContent()); 138 } 139 140 finish(mailMsg.toString()); 141 } catch (Exception de) { 142 log.error("Error handling job", de); 143 finish(getString("Test_Job_Failed"), de); 144 } 145 } 146 147 } 148 | Popular Tags |