KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > processor > form > Trigger


1 package org.apache.slide.projector.processor.form;
2
3 import java.util.Map JavaDoc;
4
5 import org.apache.slide.projector.ConfigurationException;
6 import org.apache.slide.projector.Context;
7 import org.apache.slide.projector.Result;
8 import org.apache.slide.projector.URI;
9 import org.apache.slide.projector.descriptor.ArrayValueDescriptor;
10 import org.apache.slide.projector.descriptor.BooleanValueDescriptor;
11 import org.apache.slide.projector.descriptor.ParameterDescriptor;
12 import org.apache.slide.projector.descriptor.StringValueDescriptor;
13 import org.apache.slide.projector.descriptor.URIValueDescriptor;
14 import org.apache.slide.projector.i18n.ParameterMessage;
15 import org.apache.slide.projector.processor.TemplateRenderer;
16 import org.apache.slide.projector.processor.process.Process;
17 import org.apache.slide.projector.value.ArrayValue;
18 import org.apache.slide.projector.value.BooleanValue;
19 import org.apache.slide.projector.value.StreamableValue;
20 import org.apache.slide.projector.value.StringValue;
21 import org.apache.slide.projector.value.Value;
22
23 /**
24  * @version $Revision: 1.3 $
25  */

26
27 public abstract class Trigger extends TemplateRenderer {
28     public final static String JavaDoc INSTRUCTION = "instruction";
29     public final static String JavaDoc ACTION = "action";
30     public final static String JavaDoc VALIDATE = "validate";
31     public final static String JavaDoc WIZARD = "wizard";
32     public final static String JavaDoc INVOLVED_PARAMETERS = "involvedParameters";
33     public final char SEPARATOR = ';';
34     
35     private ParameterDescriptor[] parameterDescriptors;
36
37     public Trigger() {
38         setRequiredFragments(new String JavaDoc[] { getName() });
39     }
40
41     public Result process(Map JavaDoc parameter, Context context) throws Exception JavaDoc {
42         Value []involvedParameters = (Value[])((ArrayValue)parameter.get(INVOLVED_PARAMETERS)).getArray();
43         String JavaDoc targetStep = parameter.get(Process.STEP).toString();
44         BooleanValue validate = (BooleanValue)parameter.get(VALIDATE);
45         BooleanValue wizard = (BooleanValue)parameter.get(WIZARD);
46         URI actionUri = (URI)parameter.get(ACTION);
47         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(128);
48         buffer.append(actionUri).append(SEPARATOR).append(validate).append(SEPARATOR).append(wizard).append(SEPARATOR).append(context.getStep()).append(SEPARATOR).append(targetStep).append(SEPARATOR).append(context.getProcess());
49         if ( validate.booleanValue() ) {
50             for ( int i = 0; i < involvedParameters.length; i++ ) {
51                 buffer.append(SEPARATOR).append(involvedParameters[i]);
52             }
53         }
54         String JavaDoc instruction = buffer.toString();
55         parameter.put(INSTRUCTION, new StringValue(instruction));
56         return new Result(OK, OUTPUT, renderFragment(getName(), parameter));
57     }
58     
59     public void configure(StreamableValue config) throws ConfigurationException {
60         super.configure(config);
61         ParameterDescriptor[] parentParameterDescriptors = super.getParameterDescriptors();
62         parameterDescriptors = new ParameterDescriptor[parentParameterDescriptors.length + 4];
63         int counter = 0;
64         for ( int i = 0; i < parentParameterDescriptors.length; i++ ) {
65             if (!parentParameterDescriptors[i].getName().equals(FRAGMENT)) {
66                 parameterDescriptors[counter] = parentParameterDescriptors[i];
67                 counter++;
68             }
69         }
70         parameterDescriptors[parentParameterDescriptors.length - 1] =
71                 new ParameterDescriptor(ACTION, new ParameterMessage("trigger/action"), new URIValueDescriptor());
72         parameterDescriptors[parentParameterDescriptors.length ] =
73             new ParameterDescriptor(Process.STEP, new ParameterMessage("trigger/step"), new StringValueDescriptor());
74         parameterDescriptors[parentParameterDescriptors.length + 1] =
75             new ParameterDescriptor(VALIDATE, new ParameterMessage("trigger/validate"), new BooleanValueDescriptor(), BooleanValue.TRUE);
76         parameterDescriptors[parentParameterDescriptors.length + 2] =
77             new ParameterDescriptor(INVOLVED_PARAMETERS, new ParameterMessage("trigger/involvedParameters"), new ArrayValueDescriptor(new StringValueDescriptor()));
78         parameterDescriptors[parentParameterDescriptors.length + 3] =
79             new ParameterDescriptor(WIZARD, new ParameterMessage("trigger/wizard"), new BooleanValueDescriptor(), BooleanValue.FALSE);
80     }
81
82     public ParameterDescriptor[] getParameterDescriptors() {
83         return parameterDescriptors;
84     }
85
86     protected abstract String JavaDoc getName();
87 }
Popular Tags