1 20 package org.apache.slide.projector.processor.core; 21 22 import java.util.Map ; 23 24 import org.apache.slide.projector.Context; 25 import org.apache.slide.projector.Processor; 26 import org.apache.slide.projector.Result; 27 import org.apache.slide.projector.URI; 28 import org.apache.slide.projector.descriptor.BooleanValueDescriptor; 29 import org.apache.slide.projector.descriptor.MapValueDescriptor; 30 import org.apache.slide.projector.descriptor.ParameterDescriptor; 31 import org.apache.slide.projector.descriptor.ResultDescriptor; 32 import org.apache.slide.projector.descriptor.StateDescriptor; 33 import org.apache.slide.projector.descriptor.URIValueDescriptor; 34 import org.apache.slide.projector.descriptor.XMLValueDescriptor; 35 import org.apache.slide.projector.engine.Job; 36 import org.apache.slide.projector.engine.ProcessorManager; 37 import org.apache.slide.projector.engine.Scheduler; 38 import org.apache.slide.projector.expression.Expression; 39 import org.apache.slide.projector.expression.ExpressionFactory; 40 import org.apache.slide.projector.i18n.ParameterMessage; 41 import org.apache.slide.projector.value.BooleanValue; 42 import org.apache.slide.projector.value.MapValue; 43 import org.apache.slide.projector.value.NullValue; 44 import org.apache.slide.projector.value.URIValue; 45 import org.apache.slide.projector.value.Value; 46 import org.apache.slide.projector.value.XMLValue; 47 48 50 public class Thread implements Processor { 51 public final static String PROCESSOR = "processor"; 53 public final static String REPEAT = "repeat"; 54 public final static String CONDITION = "condition"; 55 public final static String REMAINING_CONDITION = "remainingCondition"; 56 public final static String PARAMETERS = "parameters"; 57 public final static String PERSISTENT = "persistent"; 58 59 private final static ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[] { 60 new ParameterDescriptor(PROCESSOR, new ParameterMessage("job/parameter/processor"), new URIValueDescriptor()), 61 new ParameterDescriptor(REPEAT, new ParameterMessage("job/parameter/repeat"), new BooleanValueDescriptor(), BooleanValue.FALSE), 62 new ParameterDescriptor(PERSISTENT, new ParameterMessage("job/parameter/persistent"), new BooleanValueDescriptor(), BooleanValue.TRUE), 63 new ParameterDescriptor(CONDITION, new ParameterMessage("job/parameter/condition"), new XMLValueDescriptor()), 64 new ParameterDescriptor(REMAINING_CONDITION, new ParameterMessage("job/parameter/remainingCondition"), new XMLValueDescriptor(), NullValue.NULL), 65 new ParameterDescriptor(PARAMETERS, new ParameterMessage("job/parameter/parameters"), MapValueDescriptor.ANY) 66 }; 67 68 private final static ResultDescriptor resultDescriptor = new ResultDescriptor(new StateDescriptor[] { 69 StateDescriptor.OK_DESCRIPTOR 70 }); 71 72 public Result process(Map parameters, Context context) throws Exception { 73 Map jobParameters = ((MapValue)parameters.get(PARAMETERS)).getMap(); 74 URI jobUri = (URIValue)parameters.get(PROCESSOR); 75 XMLValue initialCondition = (XMLValue)parameters.get(CONDITION); 76 boolean repeatJob = ((BooleanValue)parameters.get(REPEAT)).booleanValue(); 77 Value remainingConditionValue = (Value)parameters.get(REMAINING_CONDITION); 78 XMLValue remainingCondition = null; 79 if ( remainingConditionValue == NullValue.NULL ) { 80 remainingCondition = initialCondition; 81 } else { 82 remainingCondition = (XMLValue)remainingConditionValue; 83 } 84 boolean persistentJob = ((BooleanValue)parameters.get(PERSISTENT)).booleanValue(); 85 Expression remainingExpression = ExpressionFactory.create(remainingCondition.getRootElement()); 86 Expression initialExpression = ExpressionFactory.create(initialCondition.getRootElement()); 87 Processor jobProcessor = ProcessorManager.getInstance().getProcessor(jobUri); 88 ProcessorManager.prepareValues(jobProcessor.getParameterDescriptors(), jobParameters, context); 89 String processorId = context.getProcessId(); 90 Job job; 91 if ( processorId == null ) { 92 job = new Job(context.getStep(), jobUri, initialExpression, remainingExpression, jobParameters, repeatJob, persistentJob); 93 } else { 94 job = new Job(context.getProcessId()+":"+context.getStep(), jobUri, initialExpression, remainingExpression, jobParameters, repeatJob, persistentJob); 95 } 96 Scheduler.getInstance().registerJob(job); 97 Scheduler.getInstance().saveJobs(); 98 return Result.OK; 99 } 100 101 public ParameterDescriptor[] getParameterDescriptors() { 102 return parameterDescriptors; 103 } 104 105 public ResultDescriptor getResultDescriptor() { 106 return resultDescriptor; 107 } 108 } | Popular Tags |