KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > processor > process > Step


1 package org.apache.slide.projector.processor.process;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7 import java.util.Map JavaDoc;
8 import java.util.logging.Level JavaDoc;
9 import java.util.logging.Logger JavaDoc;
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 JavaDoc logger = Logger.getLogger(Step.class.getName());
20
21     private URI processorURI;
22     private String JavaDoc name;
23     private Map JavaDoc parameterConfigurations = new HashMap JavaDoc();
24     private Map JavaDoc resultConfigurations = new HashMap JavaDoc();
25     private List JavaDoc routingConfigurations = new ArrayList JavaDoc();
26
27     public String JavaDoc getName() {
28         return name;
29     }
30
31     public URI getProcessorURI() {
32         return processorURI;
33     }
34
35     public Map JavaDoc getParameterConfigurations() {
36         return parameterConfigurations;
37     }
38
39     public Map JavaDoc getResultConfigurations() {
40         return resultConfigurations;
41     }
42
43     public List JavaDoc 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 JavaDoc loadElements = element.getChildren("load");
51         for ( Iterator JavaDoc i = loadElements.iterator(); i.hasNext(); ) {
52             Element loadElement = (Element)i.next();
53             String JavaDoc parameterName = loadElement.getAttributeValue("parameter");
54             ParameterConfiguration parameterConfiguration = new ParameterConfiguration(parameterName);
55             Iterator JavaDoc 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 JavaDoc saveElements = element.getChildren("save");
63         for ( Iterator JavaDoc i = saveElements.iterator(); i.hasNext(); ) {
64             Element saveElement = (Element)i.next();
65             String JavaDoc resultName = saveElement.getAttributeValue("result");
66             String JavaDoc resultStore = saveElement.getAttributeValue("store");
67             String JavaDoc resultDomain = saveElement.getAttributeValue("domain");
68             String JavaDoc resultKey = saveElement.getAttributeValue("key");
69             String JavaDoc 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 JavaDoc routeElements = element.getChildren("route");
84         for ( Iterator JavaDoc i = routeElements.iterator(); i.hasNext(); ) {
85             Element routeElement = (Element)i.next();
86             String JavaDoc state = routeElement.getAttributeValue("state");
87             String JavaDoc exception = routeElement.getAttributeValue("exception");
88             String JavaDoc step = routeElement.getAttributeValue("step");
89             String JavaDoc 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 JavaDoc clazz = Class.forName(exception);
102                     routingConfigurations.add(new RoutingConfiguration(clazz, step));
103                 } catch (ClassNotFoundException JavaDoc e) {
104                     logger.log(Level.SEVERE, "Could not find exception class=" + exception + ", skipping exception routing");
105                 }
106             }
107         }
108     }
109 }
110
Popular Tags