You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by df...@apache.org on 2004/09/11 17:06:37 UTC
cvs commit: jakarta-slide/projector/src/java/org/apache/slide/projector/descriptor ListValueFactory.java ListValueDescriptor.java
dflorey 2004/09/11 08:06:37
Modified: projector/src/java/org/apache/slide/projector/processor/process
Step.java Process.java
Added: projector/src/java/org/apache/slide/projector/processor/core
ProcessorReflector.java
projector/src/java/org/apache/slide/projector/value
ListValue.java
projector/src/java/org/apache/slide/projector/descriptor
ListValueFactory.java ListValueDescriptor.java
Log:
Introduced ListValue descriptors
Revision Changes Path
1.1 jakarta-slide/projector/src/java/org/apache/slide/projector/processor/core/ProcessorReflector.java
Index: ProcessorReflector.java
===================================================================
package org.apache.slide.projector.processor.core;
import java.text.DateFormat;
import java.util.Locale;
import java.util.Map;
import org.apache.slide.projector.ContentType;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.Processor;
import org.apache.slide.projector.Result;
import org.apache.slide.projector.Store;
import org.apache.slide.projector.URI;
import org.apache.slide.projector.descriptor.DateValueDescriptor;
import org.apache.slide.projector.descriptor.LocaleValueDescriptor;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.RequiredEnvironmentDescriptor;
import org.apache.slide.projector.descriptor.ResultDescriptor;
import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
import org.apache.slide.projector.descriptor.StateDescriptor;
import org.apache.slide.projector.descriptor.StringValueDescriptor;
import org.apache.slide.projector.descriptor.URIValueDescriptor;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.LocalizedMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.value.ArrayValue;
import org.apache.slide.projector.value.DateValue;
import org.apache.slide.projector.value.LocaleValue;
import org.apache.slide.projector.value.StringValue;
public class ProcessorReflector implements Processor {
private final static String PROCESSOR_URI = "processor-uri";
private final static String PARAMETERS = "parameters";
private final static String RESULTS = "results";
private final static String STATES = "states";
private final static ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[]{
new ParameterDescriptor(PROCESSOR_URI, new ParameterMessage("processorReflector/parameter/processor-url"), new URIValueDescriptor())
};
private final static ResultDescriptor resultDescriptor = new ResultDescriptor(
new StateDescriptor[]{ StateDescriptor.OK_DESCRIPTOR },
new ResultEntryDescriptor[]{
new ResultEntryDescriptor(PARAMETERS,
new LocalizedMessage("processorReflector/result/parameters"),
ArrayValue.CONTENT_TYPE, false),
new ResultEntryDescriptor(RESULTS, new LocalizedMessage("processorReflector/result/results"),
ArrayValue.CONTENT_TYPE, false),
new ResultEntryDescriptor(STATES, new LocalizedMessage("processorReflector/result/states"),
ArrayValue.CONTENT_TYPE, false)
});
public Result process(Map parameters, Context context) throws Exception {
URI processorUri = (URI)parameters.get(PROCESSOR_URI);
Processor processor = ProcessorManager.getInstance().getProcessor(processorUri);
ParameterDescriptor[] parameterDescriptor = processor.getParameterDescriptors();
for ( int i = 0; i < parameterDescriptor.length; i++ ) {
}
return new Result(StateDescriptor.OK);
}
public ParameterDescriptor[] getParameterDescriptors() {
return parameterDescriptors;
}
public ResultDescriptor getResultDescriptor() {
return resultDescriptor;
}
}
1.3 +3 -3 jakarta-slide/projector/src/java/org/apache/slide/projector/processor/process/Step.java
Index: Step.java
===================================================================
RCS file: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/processor/process/Step.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Step.java 22 Jul 2004 12:09:26 -0000 1.2
+++ Step.java 11 Sep 2004 15:06:37 -0000 1.3
@@ -21,7 +21,7 @@
private URI processorURI;
private String name;
private Map parameterConfigurations = new HashMap();
- private Map resultConfigurations = new HashMap();
+ private List resultConfigurations = new ArrayList();
private List routingConfigurations = new ArrayList();
public String getName() {
@@ -36,7 +36,7 @@
return parameterConfigurations;
}
- public Map getResultConfigurations() {
+ public List getResultConfigurations() {
return resultConfigurations;
}
@@ -78,7 +78,7 @@
} else {
resultConfiguration = new ResultConfiguration(resultName, resultStore, resultDomain, resultKey, presentableResult, timeout);
}
- resultConfigurations.put(resultName, resultConfiguration);
+ resultConfigurations.add(resultConfiguration);
}
List routeElements = element.getChildren("route");
for ( Iterator i = routeElements.iterator(); i.hasNext(); ) {
1.8 +4 -5 jakarta-slide/projector/src/java/org/apache/slide/projector/processor/process/Process.java
Index: Process.java
===================================================================
RCS file: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/processor/process/Process.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Process.java 28 Aug 2004 09:59:02 -0000 1.7
+++ Process.java 11 Sep 2004 15:06:37 -0000 1.8
@@ -310,11 +310,10 @@
public static void saveResults(Step step, Result stepResult, Store stepStore, Result result, ResultEntryDescriptor[] resultEntryDescriptors, Context context) throws ProcessException {
// save results by using result configuration
- for (Iterator i = step.getResultConfigurations().entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry)i.next();
- String resultName = (String)entry.getKey();
- Value resultValue = (Value)stepResult.getResultEntries().get(resultName);
- ((ResultConfiguration)entry.getValue()).storeValue(resultValue, stepStore, result, resultEntryDescriptors, context);
+ for (Iterator i = step.getResultConfigurations().iterator(); i.hasNext();) {
+ ResultConfiguration resultConfiguration = (ResultConfiguration)i.next();
+ Value resultValue = (Value)stepResult.getResultEntries().get(resultConfiguration.getName());
+ resultConfiguration.storeValue(resultValue, stepStore, result, resultEntryDescriptors, context);
}
}
1.1 jakarta-slide/projector/src/java/org/apache/slide/projector/value/ListValue.java
Index: ListValue.java
===================================================================
package org.apache.slide.projector.value;
import java.util.List;
public class ListValue implements Value {
private List list;
public final static String CONTENT_TYPE = "application/projector-list";
public ListValue(List list) {
this.list = list;
}
public List getList() {
return list;
}
public String getContentType() {
return CONTENT_TYPE;
}
}
1.1 jakarta-slide/projector/src/java/org/apache/slide/projector/descriptor/ListValueFactory.java
Index: ListValueFactory.java
===================================================================
package org.apache.slide.projector.descriptor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.slide.projector.value.ArrayValue;
import org.apache.slide.projector.value.ListValue;
import org.apache.slide.projector.value.Value;
import org.jdom.Element;
import de.zeigermann.xml.XMLStringWriter;
import de.zeigermann.xml.XMLWriter;
public class ListValueFactory implements ValueFactory {
public Class getValueClass() {
return ListValue.class;
}
public String getElementName() {
return "list";
}
public Value load(Element element) {
List children = new ArrayList();
for ( Iterator i = element.getChildren().iterator(); i.hasNext(); ) {
Element childElement = (Element)i.next();
children.add(ValueFactoryManager.getInstance().loadValue(childElement));
}
return new ListValue(children);
}
public void save(Value value, XMLStringWriter writer) {
writer.writeStartTag(XMLWriter.createStartTag(getElementName()));
for ( Iterator i = ((ListValue)value).getList().iterator(); i.hasNext(); ) {
ValueFactoryManager.getInstance().saveValue((Value)i.next(), writer);
}
writer.writeEndTag(XMLWriter.createEndTag(getElementName()));
}
public ValueDescriptor loadDescriptor(Element element) {
Element allowedListValueElement = (Element)element.getChildren().iterator().next();
ValueDescriptor allowedListValue = ValueFactoryManager.getInstance().loadValueDescriptor(allowedListValueElement);
return new ListValueDescriptor(allowedListValue);
}
}
1.1 jakarta-slide/projector/src/java/org/apache/slide/projector/descriptor/ListValueDescriptor.java
Index: ListValueDescriptor.java
===================================================================
package org.apache.slide.projector.descriptor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.value.AnyValue;
import org.apache.slide.projector.value.ArrayValue;
import org.apache.slide.projector.value.ListValue;
import org.apache.slide.projector.value.NullValue;
import org.apache.slide.projector.value.Value;
public class ListValueDescriptor implements ValueDescriptor {
protected ValueDescriptor entryValueDescriptor;
public ListValueDescriptor() {
}
public ListValueDescriptor(ValueDescriptor entryValueDescriptor) {
this.entryValueDescriptor = entryValueDescriptor;
}
public void setEntryValueDescriptor(ValueDescriptor entryValueDescriptor) {
this.entryValueDescriptor = entryValueDescriptor;
}
public ValueDescriptor getEntryValueDescriptor() {
return entryValueDescriptor;
}
public Value valueOf(Object value, Context context) throws ValueCastException {
List list = new ArrayList();
if ( value instanceof String[] ) {
for ( int i = 0; i < ((String[])value).length; i++ ) {
list.add(entryValueDescriptor.valueOf(((String [])value)[i], context));
}
} else if ( value instanceof List || value instanceof ListValue ) {
if ( value instanceof ListValue ) {
value = ((ListValue)value).getList();
}
for ( Iterator i = ((List)value).iterator(); i.hasNext(); ) {
Object entry = i.next();
if ( entry instanceof AnyValue ) {
try {
entry = ((AnyValue)entry).load(context);
} catch (Exception e) {
throw new ValueCastException(new ErrorMessage("uncastableListValue", new Object[] { entry }));
}
}
list.add(entryValueDescriptor.valueOf(entry, context));
}
} else if ( value instanceof ArrayValue ) {
for ( int i = 0; i < ((ArrayValue)value).getArray().length; i++ ) {
Object entry = ((ArrayValue)value).getArray()[i];
if ( entry instanceof AnyValue ) {
try {
entry = ((AnyValue)entry).load(context);
} catch (Exception e) {
throw new ValueCastException(new ErrorMessage("uncastableListValue", new Object[] { value }));
}
}
list.add(entryValueDescriptor.valueOf(entry, context));
}
} else {
throw new ValueCastException(new ErrorMessage("uncastableListValue", new Object[] { value }));
}
return new ListValue(list);
}
public void validate(Value value, Context context) throws ValidationException {
try {
List list = ((ListValue)value).getList();
for ( Iterator i = list.iterator(); i.hasNext();) {
Value entry = (Value)i.next();
if ( !(entry instanceof NullValue) ) {
entryValueDescriptor.validate(entry, context);
}
}
} catch ( ValidationException exception ) {
throw new ValidationException(new ErrorMessage("invalidListEntry", new Object[] { value }), exception);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org