1 package org.apache.slide.projector.processor.process; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import java.util.Map ; 8 import java.util.logging.Level ; 9 import java.util.logging.Logger ; 10 11 import org.apache.slide.projector.Store; 12 import org.apache.slide.projector.URI; 13 import org.apache.slide.projector.value.URIValue; 14 import org.jdom.Element; 15 16 import de.zeigermann.xml.simpleImporter.ConversionHelpers; 17 18 public class Step { 19 private static Logger logger = Logger.getLogger(Step.class.getName()); 20 21 private URI processorURI; 22 private String name; 23 private Map parameterConfigurations = new HashMap (); 24 private Map resultConfigurations = new HashMap (); 25 private List routingConfigurations = new ArrayList (); 26 27 public String getName() { 28 return name; 29 } 30 31 public URI getProcessorURI() { 32 return processorURI; 33 } 34 35 public Map getParameterConfigurations() { 36 return parameterConfigurations; 37 } 38 39 public Map getResultConfigurations() { 40 return resultConfigurations; 41 } 42 43 public List getRoutingConfigurations() { 44 return routingConfigurations; 45 } 46 47 public void configure(Element element) { 48 name = element.getAttributeValue("id"); 49 processorURI = new URIValue(element.getAttributeValue("processor")); 50 List loadElements = element.getChildren("load"); 51 for ( Iterator i = loadElements.iterator(); i.hasNext(); ) { 52 Element loadElement = (Element)i.next(); 53 String parameterName = loadElement.getAttributeValue("parameter"); 54 ParameterConfiguration parameterConfiguration = new ParameterConfiguration(parameterName); 55 Iterator childIterator = loadElement.getChildren().iterator(); 56 if ( childIterator.hasNext() ) { 57 Element valueElement = (Element)childIterator.next(); 58 parameterConfiguration.configure(valueElement); 59 parameterConfigurations.put(parameterName, parameterConfiguration); 60 } 61 } 62 List saveElements = element.getChildren("save"); 63 for ( Iterator i = saveElements.iterator(); i.hasNext(); ) { 64 Element saveElement = (Element)i.next(); 65 String resultName = saveElement.getAttributeValue("result"); 66 String resultStore = saveElement.getAttributeValue("store"); 67 String resultDomain = saveElement.getAttributeValue("domain"); 68 String resultKey = saveElement.getAttributeValue("key"); 69 String timeoutAsString = saveElement.getAttributeValue("timeout"); 70 long timeout = -1; 71 if ( timeoutAsString != null ) { 72 timeout = Long.valueOf(timeoutAsString).longValue(); 73 } 74 boolean presentableResult = ConversionHelpers.getBoolean(saveElement.getAttributeValue("presentable"), false); 75 ResultConfiguration resultConfiguration; 76 if (resultStore == null) { 77 resultConfiguration = new ResultConfiguration(resultName, Store.NONE, resultDomain, resultKey, presentableResult, timeout); 78 } else { 79 resultConfiguration = new ResultConfiguration(resultName, resultStore, resultDomain, resultKey, presentableResult, timeout); 80 } 81 resultConfigurations.put(resultName, resultConfiguration); 82 } 83 List routeElements = element.getChildren("route"); 84 for ( Iterator i = routeElements.iterator(); i.hasNext(); ) { 85 Element routeElement = (Element)i.next(); 86 String state = routeElement.getAttributeValue("state"); 87 String exception = routeElement.getAttributeValue("exception"); 88 String step = routeElement.getAttributeValue("step"); 89 String returnValue = routeElement.getAttributeValue("return"); 90 if (state != null) { 91 RoutingConfiguration routingConfiguration = new RoutingConfiguration(state); 92 if (returnValue != null) { 93 routingConfiguration.setReturnValue(returnValue); 94 } 95 if (step != null) { 96 routingConfiguration.setStep(step); 97 } 98 routingConfigurations.add(routingConfiguration); 99 } else if (exception != null) { 100 try { 101 Class clazz = Class.forName(exception); 102 routingConfigurations.add(new RoutingConfiguration(clazz, step)); 103 } catch (ClassNotFoundException e) { 104 logger.log(Level.SEVERE, "Could not find exception class=" + exception + ", skipping exception routing"); 105 } 106 } 107 } 108 } 109 } 110 | Popular Tags |