1 package org.oddjob.monitor.action; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.ByteArrayOutputStream ; 5 6 import org.apache.log4j.Logger; 7 import org.oddjob.arooa.ArooaRuntime; 8 import org.oddjob.arooa.ArooaContext; 9 import org.oddjob.arooa.ArooaConstants; 10 import org.oddjob.arooa.RuntimeConfiguration; 11 import org.oddjob.arooa.handlers.MainHandler; 12 import org.oddjob.arooa.handlers.XmlHandler; 13 import org.oddjob.arooa.xml.XMLDefinitionHelper; 14 import org.oddjob.designer.arooa.DesignParser; 15 import org.oddjob.designer.elements.scheduling.ScheduleInstructionDE; 16 import org.oddjob.designer.elements.scheduling.ScheduleListDE; 17 import org.oddjob.designer.elements.simple.ReferenceAttribute; 18 import org.oddjob.designer.model.DesignDefinition; 19 import org.oddjob.monitor.model.ExplorerContext; 20 import org.oddjob.monitor.model.JobAction; 21 import org.oddjob.scheduling.OddjobScheduler; 22 import org.oddjob.scheduling.ScheduleInstruction; 23 import org.oddjob.scheduling.ScheduleInstructionFactory; 24 import org.oddjob.values.types.ListType; 25 import org.xml.sax.InputSource ; 26 27 32 33 public class ScheduleAction extends JobAction { 34 private static final Logger logger = Logger.getLogger(ScheduleAction.class); 35 36 37 private Object job = null; 38 39 private ArooaContext arooaContext; 40 41 private boolean enabled; 42 43 private ScheduleInstructionDE designElement; 44 45 private OddjobScheduler oddjobScheduler; 46 47 public ScheduleAction(OddjobScheduler oddjobScheduler, String type) { 48 this.oddjobScheduler = oddjobScheduler; 49 this.designElement = (ScheduleInstructionDE) new ScheduleListDE() 50 .createType(type); 51 } 52 53 56 public String getName() { 57 return designElement.type(); 58 } 59 60 public void select(Object component, ExplorerContext eContext) { 61 this.job = component; 62 enabled = true; 63 ReferenceAttribute jobReference = new ReferenceAttribute(); 64 jobReference.attribute("Selected Job"); 65 designElement.setJob(jobReference); 66 67 arooaContext = eContext.getArooaContext(); 68 } 69 70 public void deSelect() { 71 enabled = false; 72 arooaContext = null; 73 } 74 75 public boolean enabled() { 76 return enabled; 77 } 78 79 public DesignDefinition form() { 80 return designElement.detail(); 81 } 82 83 public void action() throws Exception { 84 85 ByteArrayOutputStream out = new ByteArrayOutputStream (); 86 XmlHandler handler = new XmlHandler(out); 87 DesignParser dp = new DesignParser(new ArooaContext()); 88 dp.parse("ojschedule", designElement, new MainHandler(handler)); 89 logger.debug("Schedule XML:\n" + out.toString()); 90 91 ArooaContext ourcon = new ArooaContext(arooaContext); 92 93 ListType surrogate = new ListType(); 94 95 RuntimeConfiguration rtc = new ArooaRuntime(surrogate, 96 "surrogate", ourcon); 97 ourcon.set(ArooaConstants.CURRENTLY_CONFIGURING, rtc); 98 99 XMLDefinitionHelper ph = new XMLDefinitionHelper(ourcon); 100 101 InputSource inputSource = new InputSource (new ByteArrayInputStream (out.toByteArray())); 102 ph.parse(inputSource, new MainHandler( 103 ScheduleInstructionFactory.handlerFor(ourcon))); 104 rtc.configure(); 105 106 Object [] list = (Object []) surrogate.valueFor(Object .class); 107 if (list.length == 0) { 108 logger.debug("No property."); 109 return; 110 } 111 ScheduleInstruction scheduleInstruction = (ScheduleInstruction) list[0]; 112 113 scheduleInstruction.setJob(job); 114 oddjobScheduler.schedule(scheduleInstruction); 115 } 116 117 } 118 | Popular Tags |