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/06/08 11:04:06 UTC
cvs commit: jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/xml XPathQuery.java
dflorey 2004/06/08 02:04:06
Modified: proposals/projector/src/java/org/apache/slide/projector/processor/form
Control.java Form.java FormHandler.java
FormGenerator.java Trigger.java
ControlComposer.java Test.java
proposals/projector/src/java/org/apache/slide/projector/engine
Scheduler.java ProcessorManager.java
proposals/projector/src/java/org/apache/slide/projector/processor
Exists.java MapEntry.java Echo.java URL.java
TemplateRenderer.java Link.java
proposals/projector/src/java/org/apache/slide/projector/descriptor
ResourceValueDescriptor.java
proposals/projector/src/java/org/apache/slide/projector/value
StringValue.java DocumentValue.java
proposals/projector/src/java/org/apache/slide/projector/processor/xml
XPathQuery.java
Added: proposals/projector/src/java/org/apache/slide/projector/processor/process
RoutingConfiguration.java Process.java
ParameterConfiguration.java
ResultConfiguration.java Step.java
proposals/projector/src/java/org/apache/slide/projector/processor
Thread.java
proposals/projector/src/java/org/apache/slide/projector
ContentType.java
Removed: proposals/projector/src/java/org/apache/slide/projector/engine
ParameterConfiguration.java
RoutingConfiguration.java ResultConfiguration.java
Process.java Step.java ContentType.java
Log:
Refactored the asynchronous process handling
Revision Changes Path
1.6 +1 -2 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Control.java
Index: Control.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Control.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Control.java 1 Jun 2004 07:49:55 -0000 1.5
+++ Control.java 8 Jun 2004 09:04:05 -0000 1.6
@@ -2,7 +2,6 @@
import org.apache.slide.projector.*;
import org.apache.slide.projector.descriptor.*;
-import org.apache.slide.projector.engine.ContentType;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
1.9 +4 -5 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Form.java
Index: Form.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Form.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Form.java 1 Jun 2004 07:49:55 -0000 1.8
+++ Form.java 8 Jun 2004 09:04:05 -0000 1.9
@@ -25,11 +25,10 @@
import org.apache.slide.projector.*;
import org.apache.slide.projector.descriptor.*;
-import org.apache.slide.projector.engine.Process;
-import org.apache.slide.projector.engine.ContentType;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
+import org.apache.slide.projector.processor.process.Process;
import org.apache.slide.projector.util.ProcessorHelper;
import org.apache.slide.projector.value.*;
1.11 +2 -3 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/FormHandler.java
Index: FormHandler.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/FormHandler.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FormHandler.java 1 Jun 2004 07:49:55 -0000 1.10
+++ FormHandler.java 8 Jun 2004 09:04:05 -0000 1.11
@@ -2,17 +2,16 @@
import org.apache.slide.projector.*;
import org.apache.slide.projector.descriptor.*;
-import org.apache.slide.projector.engine.ContentType;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
+import org.apache.slide.projector.processor.process.Process;
import org.apache.slide.projector.util.ProcessorHelper;
import org.apache.slide.projector.value.BooleanValue;
import org.apache.slide.projector.value.MapValue;
import org.apache.slide.projector.value.StringValue;
import org.apache.slide.projector.value.URIValue;
-import org.apache.slide.projector.engine.Process;
import java.util.ArrayList;
import java.util.HashMap;
1.11 +2 -2 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/FormGenerator.java
Index: FormGenerator.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/FormGenerator.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FormGenerator.java 3 Jun 2004 14:53:14 -0000 1.10
+++ FormGenerator.java 8 Jun 2004 09:04:05 -0000 1.11
@@ -2,11 +2,11 @@
import org.apache.slide.projector.*;
import org.apache.slide.projector.descriptor.*;
-import org.apache.slide.projector.engine.Process;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
+import org.apache.slide.projector.processor.process.Process;
import org.apache.slide.projector.value.*;
import java.util.*;
1.9 +2 -2 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Trigger.java
Index: Trigger.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Trigger.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Trigger.java 1 Jun 2004 07:49:55 -0000 1.8
+++ Trigger.java 8 Jun 2004 09:04:05 -0000 1.9
@@ -2,7 +2,6 @@
import java.util.Map;
-import org.apache.slide.projector.engine.Process;
import org.apache.slide.projector.ConfigurationException;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.Result;
@@ -14,6 +13,7 @@
import org.apache.slide.projector.descriptor.URIValueDescriptor;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.TemplateRenderer;
+import org.apache.slide.projector.processor.process.Process;
import org.apache.slide.projector.value.ArrayValue;
import org.apache.slide.projector.value.BooleanValue;
import org.apache.slide.projector.value.NullValue;
1.9 +1 -1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/ControlComposer.java
Index: ControlComposer.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/ControlComposer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ControlComposer.java 1 Jun 2004 07:49:55 -0000 1.8
+++ ControlComposer.java 8 Jun 2004 09:04:05 -0000 1.9
@@ -2,7 +2,6 @@
import org.apache.slide.projector.*;
import org.apache.slide.projector.descriptor.*;
-import org.apache.slide.projector.engine.Process;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
@@ -10,6 +9,7 @@
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
import org.apache.slide.projector.processor.TemplateRenderer;
+import org.apache.slide.projector.processor.process.Process;
import org.apache.slide.projector.store.FormStore;
import org.apache.slide.projector.util.ProcessorHelper;
import org.apache.slide.projector.value.*;
1.6 +1 -1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Test.java
Index: Test.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/form/Test.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Test.java 3 Jun 2004 14:53:14 -0000 1.5
+++ Test.java 8 Jun 2004 09:04:05 -0000 1.6
@@ -15,10 +15,10 @@
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResultDescriptor;
import org.apache.slide.projector.descriptor.URIValueDescriptor;
-import org.apache.slide.projector.engine.Process;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
+import org.apache.slide.projector.processor.process.Process;
import org.apache.slide.projector.store.FormStore;
import org.apache.slide.projector.util.ProcessorHelper;
import org.apache.slide.projector.value.BooleanValue;
1.7 +2 -0 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/Scheduler.java
Index: Scheduler.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/Scheduler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Scheduler.java 7 Jun 2004 17:21:53 -0000 1.6
+++ Scheduler.java 8 Jun 2004 09:04:05 -0000 1.7
@@ -63,6 +63,7 @@
public void install(URI jobsUri) {
logger.log(Level.INFO, "Installing scheduled jobs of application '"+jobsUri+"'");
+ /*
try {
Map applicationJobs = new HashMap();
StreamableValue jobsResource = (StreamableValue)ConnectorFactory.getConnector().getResource(jobsUri, Constants.CREDENTIALS);
@@ -95,6 +96,7 @@
} catch (Exception exception) {
logger.log(Level.SEVERE, "Error while parsing messages", exception);
}
+ */
}
public void uninstall(URI jobsUri) {
1.15 +1 -0 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessorManager.java
Index: ProcessorManager.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/engine/ProcessorManager.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ProcessorManager.java 3 Jun 2004 14:53:14 -0000 1.14
+++ ProcessorManager.java 8 Jun 2004 09:04:05 -0000 1.15
@@ -13,6 +13,7 @@
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.processor.SimpleProcessor;
+import org.apache.slide.projector.processor.process.Process;
import org.apache.slide.projector.util.ProcessorHelper;
import org.apache.slide.projector.value.StreamableValue;
import org.apache.slide.projector.value.URIValue;
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/process/RoutingConfiguration.java
Index: RoutingConfiguration.java
===================================================================
package org.apache.slide.projector.processor.process;
/*
* $Header: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/process/RoutingConfiguration.java,v 1.1 2004/06/08 09:04:05 dflorey Exp $
* $Revision: 1.1 $
* $Date: 2004/06/08 09:04:05 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Slide", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
public class RoutingConfiguration {
private String state, step, returnValue;
private Class exception;
public RoutingConfiguration(String state) {
this.state = state;
}
public RoutingConfiguration(Class exception, String step) {
this.exception = exception;
this.step = step;
}
public String getReturnValue() {
return returnValue;
}
public void setReturnValue(String returnValue) {
this.returnValue = returnValue;
}
public String getState() {
return state;
}
public Class getException() {
return exception;
}
public void setStep(String step) {
this.step = step;
}
public String getStep() {
return step;
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/process/Process.java
Index: Process.java
===================================================================
package org.apache.slide.projector.processor.process;
import de.zeigermann.xml.simpleImporter.ConversionHelpers;
import org.apache.slide.projector.*;
import org.apache.slide.projector.descriptor.*;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.store.*;
import org.apache.slide.projector.util.StoreHelper;
import org.apache.slide.projector.value.DocumentValue;
import org.apache.slide.projector.value.StreamableValue;
import org.apache.slide.projector.value.StringValue;
import org.apache.slide.projector.value.Value;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.xpath.XPath;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Process implements ConfigurableProcessor, EnvironmentConsumer, EnvironmentProvider {
private static Logger logger = Logger.getLogger(Process.class.getName());
public final static String STEP = "step";
private final static String OK = "ok";
protected Map steps;
protected String firstStep;
protected RequiredEnvironmentDescriptor[] requiredEnvironmentDescriptors;
protected ProvidedEnvironmentDescriptor[] providedEnvironmentDescriptors;
protected ParameterDescriptor[] parameterDescriptors;
protected ResultDescriptor resultDescriptor = ResultDescriptor.OK;
public void configure(StreamableValue config) throws ConfigurationException {
steps = new HashMap();
try {
DocumentValue documentResource = new DocumentValue(config);
Document document = documentResource.getDocument();
Element rootElement = document.getRootElement();
firstStep = rootElement.getAttributeValue("first-step");
List inputParamters = XPath.newInstance("/process/description/input/parameter").selectNodes(rootElement);
List parameterDescriptors = new ArrayList();
for ( Iterator i = inputParamters.iterator(); i.hasNext(); ) {
Element inputParameter = (Element)i.next();
String name = inputParameter.getAttributeValue("name");
String description = inputParameter.getAttributeValue("description");
ParameterDescriptor parameterDescriptor;
if ( description != null ) {
parameterDescriptor = new ParameterDescriptor(name, new ParameterMessage(description), null);
} else {
parameterDescriptor = new ParameterDescriptor(name, new ParameterMessage(ParameterMessage.NO_MESSAGE_AVAILABLE, new String[] {name}), null);
}
parameterDescriptors.add(parameterDescriptor);
Element valueDescriptorElement = (Element)inputParameter.getChildren().iterator().next();
ValueDescriptor valueDescriptor = ValueDescriptorManager.getInstance().loadValueDescriptor(valueDescriptorElement);
parameterDescriptor.setValueDescriptor(valueDescriptor);
}
this.parameterDescriptors = (ParameterDescriptor [])parameterDescriptors.toArray(new ParameterDescriptor[parameterDescriptors.size()]);
List outputResults = XPath.newInstance("/process/description/output/result").selectNodes(rootElement);
List resultEntryDescriptors = new ArrayList();
for ( Iterator i = outputResults.iterator(); i.hasNext(); ) {
Element outputResult = (Element)i.next();
String name = outputResult.getAttributeValue("name");
String description = outputResult.getAttributeValue("description");
String contentType = outputResult.getAttributeValue("content-type");
boolean presentable = ConversionHelpers.getBoolean(outputResult.getAttributeValue("presentable"), false);
resultEntryDescriptors.add(new ResultEntryDescriptor(name, new DefaultMessage(description), contentType, presentable));
}
List stateElements = XPath.newInstance("/process/description/output/state").selectNodes(rootElement);
List states = new ArrayList();
for ( Iterator i = stateElements.iterator(); i.hasNext(); ) {
Element stateElement = (Element)i.next();
String description = stateElement.getAttributeValue("description");
states.add(new StateDescriptor(stateElement.getTextTrim(), new DefaultMessage(description)));
}
resultDescriptor = new ResultDescriptor((StateDescriptor [])states.toArray(new StateDescriptor[states.size()]), (ResultEntryDescriptor[])resultEntryDescriptors.toArray(new ResultEntryDescriptor[resultEntryDescriptors.size()]));
List providedEnvironmentElements = XPath.newInstance("/process/description/output/environment").selectNodes(rootElement);
List providedEnvironment = new ArrayList();
for ( Iterator i = providedEnvironmentElements.iterator(); i.hasNext(); ) {
Element environmentElement = (Element)i.next();
String key = environmentElement.getAttributeValue("key");
String storeName = environmentElement.getAttributeValue("store");
String description = environmentElement.getAttributeValue("description");
String contentType = environmentElement.getAttributeValue("content-type");
boolean presentable = ConversionHelpers.getBoolean(environmentElement.getAttributeValue("presentable"), false);
int store = StoreHelper.getStoreByName(storeName);
ProvidedEnvironmentDescriptor environmentDescriptor = new ProvidedEnvironmentDescriptor(key, new DefaultMessage(description), contentType, presentable);
environmentDescriptor.setStore(store);
providedEnvironment.add(environmentDescriptor);
}
providedEnvironmentDescriptors = (ProvidedEnvironmentDescriptor [])providedEnvironment.toArray(new ProvidedEnvironmentDescriptor[providedEnvironment.size()]);
List requiredEnvironmentElements = XPath.newInstance("/process/description/input/environment").selectNodes(rootElement);
List requiredEnvironment = new ArrayList();
for ( Iterator i = requiredEnvironmentElements.iterator(); i.hasNext(); ) {
Element requiredEnvironmentElement = (Element)i.next();
String name = requiredEnvironmentElement.getAttributeValue("name");
String description = requiredEnvironmentElement.getAttributeValue("description");
RequiredEnvironmentDescriptor environmentDescriptor;
if ( description != null ) {
environmentDescriptor = new RequiredEnvironmentDescriptor(name, new ParameterMessage(description), null);
} else {
environmentDescriptor = new RequiredEnvironmentDescriptor(name, new ParameterMessage(ParameterMessage.NO_MESSAGE_AVAILABLE, new String[] {name}), null);
}
requiredEnvironment.add(environmentDescriptor);
Element valueDescriptorElement = (Element)requiredEnvironmentElement.getChildren().iterator().next();
ValueDescriptor valueDescriptor = ValueDescriptorManager.getInstance().loadValueDescriptor(valueDescriptorElement);
environmentDescriptor.setValueDescriptor(valueDescriptor);
}
requiredEnvironmentDescriptors = (RequiredEnvironmentDescriptor [])requiredEnvironment.toArray(new RequiredEnvironmentDescriptor[requiredEnvironment.size()]);
List stepElements = XPath.newInstance("/process/step").selectNodes(rootElement);
for ( Iterator i = stepElements.iterator(); i.hasNext(); ) {
Element stepElement = (Element)i.next();
Step step = new Step();
step.configure(stepElement);
steps.put(step.getName(), step);
}
} catch (Exception exception) {
logger.log(Level.SEVERE, "Error while parsing process configuration", exception);
throw new ConfigurationException(new ErrorMessage("process/configurationException"), exception);
}
}
public Result process(Map parameter, Context context) throws Exception {
URI processorUri = ProcessorManager.getInstance().getProcessorDescriptor(this).getUri();
context.setProcess(processorUri); // Remember current process in context
String nextStep = getStep(firstStep, context); // Lookup the first step of this process
Store stepStore = new Cache(); // This store is used to allow stack-like result/parameter delivery between steps
Result result = new Result(OK); // The result of this process processor
Result stepResult = null; // The result of the last executed step
Step step; // The current step
do {
logger.log(Level.INFO, "Processing "+processorUri+", step=" + nextStep);
context.setStep(nextStep); // Remember current step in context
step = (Step)steps.get(nextStep);
if (step == null) throw new ProcessException(new ErrorMessage("stepNotFound", new String[]{nextStep}));
Processor processor = ProcessorManager.getInstance().getProcessor(step.getProcessorURI());
try {
Map processorParameters = loadParameters(step, processor, parameter, stepStore, context);
if ( processor instanceof EnvironmentConsumer ) {
checkRequirements((EnvironmentConsumer)processor, context);
}
checkRoutings(step, processor);
try {
stepResult = processor.process(processorParameters, context);
saveResults(step, stepResult, stepStore, result, getResultDescriptor().getResultEntryDescriptors(), context);
nextStep = routeState(step, stepResult.getState());
} catch (Exception e) {
nextStep = routeException(step, e);
}
} catch ( ValidationException exception ) {
throw new ValidationException(new ErrorMessage("validationFailed", new Object[] { step.getProcessorURI(), nextStep }), exception);
}
} while (nextStep != null);
result.setState(getState(step, stepResult.getState()));
return result;
}
public ParameterDescriptor[] getParameterDescriptors() {
return parameterDescriptors;
}
public ResultDescriptor getResultDescriptor() {
return resultDescriptor;
}
public RequiredEnvironmentDescriptor[] getRequiredEnvironmentDescriptors() {
return requiredEnvironmentDescriptors;
}
public ProvidedEnvironmentDescriptor[] getProvidedEnvironmentDescriptors() {
return providedEnvironmentDescriptors;
}
static String getStep(String firstStep, Context context) {
Store sessionStore = context.getStore(Store.SESSION);
if ( sessionStore != null ) {
Value stepParameter = (Value)StoreHelper.get(sessionStore, context.getProcess().toString(), STEP);
if (stepParameter != null && stepParameter instanceof StringValue ) {
return stepParameter.toString();
}
}
return firstStep;
}
static void checkRoutings(Step step, Processor processor) throws ValidationException {
ResultDescriptor resultDescriptor = processor.getResultDescriptor();
StateDescriptor[] states = resultDescriptor.getStateDescriptors();
for ( int i = 0; i < states.length; i++ ) {
String state = states[i].getState();
List routings = step.getRoutingConfigurations();
boolean routingFound = false;
for ( Iterator j = routings.iterator(); j.hasNext() ; ) {
if ( ((RoutingConfiguration)j.next()).getState().equals(state) ) {
routingFound = true;
break;
}
}
if ( !routingFound ) {
throw new ValidationException(new ErrorMessage("stateNotRouted", new String[] { step.getName(), state }));
}
}
}
public static void checkRequirements(EnvironmentConsumer processor, Context context) throws ValidationException, IOException {
RequiredEnvironmentDescriptor[] requirementDescriptor = processor.getRequiredEnvironmentDescriptors();
for ( int i = 0; i < requirementDescriptor.length; i++ ) {
Store store = context.getStore(requirementDescriptor[i].getStore());
Object value = store.get(requirementDescriptor[i].getName());
if ( value == null ) {
if ( requirementDescriptor[i].isRequired() ) {
throw new ContextException(new ErrorMessage("requiredContextMissing", new Object[] { requirementDescriptor[i].getName(), Store.stores[requirementDescriptor[i].getStore()] }));
} else {
value = requirementDescriptor[i].getDefaultValue();
store.put(requirementDescriptor[i].getName(), value);
}
}
Value resource = requirementDescriptor[i].getValueDescriptor().validate(value, context);
if ( resource != value ) {
store.put(requirementDescriptor[i].getName(), resource);
}
}
}
static String evaluateKey(String key, Context context) {
if ( key.startsWith("$") ) {
String storeToken = key.substring(1, key.indexOf(':'));
String keyToken = key.substring(key.indexOf(':')+1);
Store keyStore = context.getStore(StoreHelper.getStoreByName(storeToken));
try {
Object dynamicKey = keyStore.get(keyToken);
key = StringValueDescriptor.toString(dynamicKey);
} catch ( IOException e ) {
logger.log(Level.SEVERE, "Dynamic key '"+keyToken+"' could not be loaded from store '"+storeToken+"'", e);
key = null;
}
return key;
}
return key;
}
static Map loadParameters(Step step, Processor processor, Map parameter, Store stepStore, Context context) throws Exception {
// Collect parameters for this processor
Map parameters = new HashMap();
ParameterDescriptor[] parameterDescriptors = processor.getParameterDescriptors();
for (int j = 0; j < parameterDescriptors.length; j++) {
// validate...
ParameterDescriptor parameterDescriptor = parameterDescriptors[j];
ParameterConfiguration parameterConfiguration = (ParameterConfiguration)step.getParameterConfigurations().get(parameterDescriptor.getName());
if ( parameterConfiguration == null ) {
if ( parameterDescriptor.isRequired()) {
logger.log(Level.SEVERE, "Required parameter '" + parameterDescriptor.getName() + "' not assigned in step '" + step.getName() + "'!");
throw new ProcessException(new ErrorMessage("requiredStepParameterMissing", new String[]{parameterDescriptor.getName(), step.getName()}));
} else {
parameters.put(parameterDescriptor.getName(), parameterDescriptor.getDefaultValue());
}
} else if ( parameterConfiguration != null ) {
try {
Value validatedValue = parameterConfiguration.getValidatedValue(parameterDescriptor, parameter, stepStore, context);
parameters.put(parameterDescriptor.getName(), validatedValue);
} catch ( ValidationException exception ) {
throw new ProcessException(new ErrorMessage("invalidParameter", new String[]{parameterDescriptor.getName()}), exception);
}
}
}
return parameters;
}
private static void saveResults(Step step, Result stepResult, Store stepStore, Result result, ResultEntryDescriptor[] resultEntryDescriptors, Context context) {
// 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);
}
}
private static String routeState(Step step, String state) {
// find routing for result state
for (Iterator i = step.getRoutingConfigurations().iterator(); i.hasNext();) {
RoutingConfiguration routingConfiguration = (RoutingConfiguration)i.next();
if (state.equals(routingConfiguration.getState())) {
if (routingConfiguration.getStep() != null) {
return routingConfiguration.getStep();
}
}
}
return null;
}
private static String routeException(Step step, Exception e) throws Exception {
logger.log(Level.SEVERE, "Exception occured:", e);
for (Iterator i = step.getRoutingConfigurations().iterator(); i.hasNext();) {
RoutingConfiguration routingConfiguration = (RoutingConfiguration)i.next();
Class exception = routingConfiguration.getException();
if (exception != null && exception.isAssignableFrom(e.getClass())) {
return routingConfiguration.getStep();
}
}
throw(e);
}
private String getState(Step step, String state) throws ProcessException {
// find processor return state for result state
for (Iterator i = step.getRoutingConfigurations().iterator(); i.hasNext();) {
RoutingConfiguration routingConfiguration = (RoutingConfiguration)i.next();
if (routingConfiguration.getReturnValue() != null && state.equals(routingConfiguration.getState())) {
String returnState = routingConfiguration.getReturnValue();
// check if state is legal
StateDescriptor[] validStates = resultDescriptor.getStateDescriptors();
for (int j = 0; j < validStates.length; j++) {
if (validStates[j].getState().equals(returnState)) {
return returnState;
}
}
logger.log(Level.SEVERE, "State '" + returnState + "' not defined!");
throw new ProcessException(new ErrorMessage("stateNotDefined", new String[]{returnState}));
}
}
return OK;
}
private Result generateResult(String state, Result result) {
Result processResult = new Result(state);
// copy defined results from context store to result
ResultEntryDescriptor[] resultEntryDescriptors = getResultDescriptor().getResultEntryDescriptors();
for (int i = 0; i < resultEntryDescriptors.length; i++) {
ResultEntryDescriptor descriptor = resultEntryDescriptors[i];
Value resultValue = (Value)result.getResultEntries().get(descriptor.getName());
if (resultValue != null) {
processResult.addResultEntry(descriptor.getName(), resultValue);
}
}
return processResult;
}
public class ProcessStore extends AbstractStore {
protected Map map = new HashMap();
public void put(String key, Object value) throws IOException {
map.put(key, value);
}
public Object get(String key) throws IOException {
return map.get(key);
}
public void dispose(String key) throws IOException {
map.remove(key);
}
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/process/ParameterConfiguration.java
Index: ParameterConfiguration.java
===================================================================
package org.apache.slide.projector.processor.process;
import org.apache.slide.projector.*;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.util.StoreHelper;
import org.apache.slide.projector.value.MapValue;
import org.apache.slide.projector.value.URIValue;
import org.apache.slide.projector.value.Value;
import org.jdom.Element;
import java.io.IOException;
import java.util.*;
import java.util.logging.Logger;
class ParameterConfiguration {
private static Logger logger = Logger.getLogger(ParameterConfiguration.class.getName());
private String name;
private Configuration configuration;
public ParameterConfiguration(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void configure(Element element) {
this.configuration = createConfiguration(element);
}
private Configuration createConfiguration(Element element) {
Configuration configuration = null;
if ( element.getName().equals("value") ) {
configuration = new ValueConfiguration();
} else if ( element.getName().equals("array") ) {
configuration = new ArrayConfiguration();
} else if ( element.getName().equals("map") ) {
configuration = new MapConfiguration();
} else if ( element.getName().equals("entry") ) {
configuration = new MapEntryConfiguration();
}
if ( configuration != null ) {
configuration.configure(element);
}
return configuration;
}
public Configuration getConfiguration() {
return configuration;
}
public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}
public Value getValidatedValue(ParameterDescriptor descriptor, Map parameter, Store stepStore, Context context) throws ProcessException, IOException {
Object evaluatedValue = configuration.getEvaluatedValue(parameter, stepStore, context);
if ( evaluatedValue == null && !descriptor.isRequired() ) {
return descriptor.getDefaultValue();
} else {
return descriptor.getValueDescriptor().validate(evaluatedValue, context);
}
}
public interface Configuration {
public void configure(Element element);
public Object getEvaluatedValue(Map parameter, Store stepStore, Context context) throws ProcessException, IOException;
}
public abstract class EnclosingConfiguration implements Configuration {
public void configure(Element element) {
List children = element.getChildren();
for ( Iterator i = children.iterator(); i.hasNext(); ) {
Element child = (Element)i.next();
Configuration configuration = createConfiguration(child);
if ( configuration != null ) addNestedConfiguration(configuration);
}
}
public abstract void addNestedConfiguration(Configuration configuration);
public abstract Configuration[] getNestedConfigurations();
}
public class ArrayConfiguration extends EnclosingConfiguration {
private List elements = new ArrayList();
public void addNestedConfiguration(Configuration configuration) {
elements.add(configuration);
}
public Configuration[] getNestedConfigurations() {
Configuration[] configurations = new Configuration[elements.size()];
return (Configuration[])elements.toArray(configurations);
}
public Object getEvaluatedValue(Map parameter, Store stepStore, Context context) throws ProcessException, IOException {
List array = new ArrayList();
for ( Iterator i = elements.iterator(); i.hasNext(); ) {
Object evaluatedValue = ((Configuration)i.next()).getEvaluatedValue(parameter, stepStore, context);
array.add(evaluatedValue);
}
return array;
}
}
public class MapConfiguration extends EnclosingConfiguration {
private List entries = new ArrayList();
public void addNestedConfiguration(Configuration configuration) {
entries.add(configuration);
}
public Configuration[] getNestedConfigurations() {
Configuration[] configurations = new Configuration[entries.size()];
return (Configuration[])entries.toArray(configurations);
}
public Object getEvaluatedValue(Map parameter, Store stepStore, Context context) throws ProcessException, IOException {
Map map = new HashMap();
for ( Iterator i = entries.iterator(); i.hasNext(); ) {
MapEntryConfiguration entry = (MapEntryConfiguration)i.next();
map.put(entry.getKey(), entry.getEvaluatedValue(parameter, stepStore, context));
}
return map;
}
}
public class MapEntryConfiguration extends EnclosingConfiguration {
private String key;
private Configuration configuration;
public void configure(Element element) {
super.configure(element);
key = element.getAttributeValue("key");
}
public void addNestedConfiguration(Configuration configuration) {
this.configuration = configuration;
}
public Configuration[] getNestedConfigurations() {
return new Configuration[] { configuration };
}
public Object getEvaluatedValue(Map parameter, Store stepStore, Context context) throws ProcessException, IOException {
return configuration.getEvaluatedValue(parameter, stepStore, context);
}
public String getKey() {
return key;
}
}
public class ValueConfiguration implements Configuration {
private boolean storeUsed;
private int store = Store.NONE;
private String storeKey, domain, value, resultKey;
private URI processorUri;
public void configure(Element element) {
String processor = element.getAttributeValue("processor");
resultKey = element.getAttributeValue("result");
String storeName = element.getAttributeValue("store");
store = StoreHelper.getStoreByName(storeName);
storeKey = element.getAttributeValue("key");
if ( storeKey != null ) {
storeUsed = true;
}
domain = element.getAttributeValue("domain");
value = element.getTextTrim();
processorUri = ( processor == null ? null : new URIValue(processor) );
}
public Object getEvaluatedValue(Map parameter, Store stepStore, Context context) throws ProcessException, IOException {
Object value = getValue();
if (isStoreUsed()) {
String key = Process.evaluateKey(storeKey, context);
if ( getStore() == Store.NONE ) {
value = stepStore.get(key);
} else if ( getStore() == Store.INPUT ) {
value = parameter.get(key);
} else {
Store store = context.getStore(getStore());
if ( store != null ) {
if ( domain != null ) {
MapValue mapResource = (MapValue)store.get(domain);
if ( mapResource != null ) {
value = mapResource.getMap().get(key);
}
} else {
value = store.get(key);
}
}
}
}
if (getProcessorUri() != null ) {
value = ProcessorManager.getInstance().process(getProcessorUri(), value, getResultKey(), context);
}
return value;
}
private URI getProcessorUri() {
return processorUri;
}
private boolean isStoreUsed() {
return storeUsed;
}
private int getStore() {
return store;
}
private String getValue() {
return value;
}
private String getResultKey() {
return resultKey;
}
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/process/ResultConfiguration.java
Index: ResultConfiguration.java
===================================================================
package org.apache.slide.projector.processor.process;
import org.apache.slide.projector.*;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.Result;
import org.apache.slide.projector.Store;
import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
import org.apache.slide.projector.util.StoreHelper;
import org.apache.slide.projector.value.MapValue;
import org.apache.slide.projector.value.StreamableValue;
import org.apache.slide.projector.value.Value;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
class ResultConfiguration {
private static Logger logger = Logger.getLogger(ResultConfiguration.class.getName());
private int store = Store.NONE;
private String name, key, domain;
private boolean presentable;
private long timeout = -1;
public ResultConfiguration(String name, String store, String domain, String key, boolean presentable, long timeout) {
this(name, StoreHelper.getStoreByName(store), domain, key, presentable, timeout);
}
public ResultConfiguration(String name, int store, String domain, String key, boolean presentable, long timeout) {
this.name = name;
this.store = store;
this.domain = domain;
this.key = key;
this.presentable = presentable;
this.timeout = timeout;
}
public int getStore() {
return store;
}
public String getDomain() {
return domain;
}
public String getKey() {
return key;
}
public boolean isPresentable() {
return presentable;
}
public String getName() {
return name;
}
protected void storeValue(Value value, Store stepStore, Result result, ResultEntryDescriptor[] resultEntryDescriptors, Context context) {
// FIXME: Throw process exception instead of severe logging
if (presentable ) {
if ( value instanceof StreamableValue ) {
if ( context instanceof HttpContext ) {
((HttpContext)context).setPresentableResource((StreamableValue)value);
} else {
logger.log(Level.INFO, "Result can only be shown in http-context!");
}
} else {
logger.log(Level.SEVERE, "Only resources of type StreamableResource can be presented!");
}
}
Store resultStore = stepStore;
if ( store == Store.OUTPUT ) {
// check if result is defined
boolean resultDefined = false;
for ( int i = 0; i < resultEntryDescriptors.length; i++ ) {
if ( resultEntryDescriptors[i].getName().equals(key) ) {
// check if result matches description
if ( ContentType.matches(resultEntryDescriptors[i].getContentType(), value.getContentType()) ) {
result.addResultEntry(key, value);
resultDefined = true;
break;
} else {
logger.log(Level.SEVERE, "Storing result with key '"+key+"' failed, because content type of generated result is '"+value.getContentType()+"' and does not match defined content type '"+resultEntryDescriptors[i].getContentType()+"'");
}
}
}
if ( !resultDefined ) {
logger.log(Level.SEVERE, "Storing result failed, because result with key '"+key+"' is not defined in processor description!");
}
} else {
if ( store != Store.NONE ) {
resultStore = context.getStore(store);
}
if ( resultStore == null ) {
logger.log(Level.SEVERE, "Storing result with key '"+key+"' failed, because store '"+Store.stores[store]+"' in not available in context '"+context+"'");
} else {
try {
String evaluatedKey = Process.evaluateKey(key, context);
if ( evaluatedKey != null ) {
if ( domain != null ) {
Map map;
MapValue mapResource = (MapValue)resultStore.get(domain);
if ( mapResource == null ) {
map = new HashMap();
mapResource = new MapValue(map);
} else {
map = mapResource.getMap();
}
map.put(evaluatedKey, value);
evaluatedKey = domain;
value = mapResource;
}
if ( timeout != -1 ) {
resultStore.put(evaluatedKey, value, timeout);
} else {
resultStore.put(evaluatedKey, value);
}
}
} catch ( IOException e ) {
logger.log(Level.SEVERE, "Storing result with key '"+key+"' failed!", e);
}
}
}
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/process/Step.java
Index: Step.java
===================================================================
package org.apache.slide.projector.processor.process;
import org.apache.slide.projector.Store;
import org.apache.slide.projector.URI;
import org.apache.slide.projector.expression.Expression;
import org.apache.slide.projector.expression.ExpressionFactory;
import org.apache.slide.projector.value.URIValue;
import org.jdom.Element;
import de.zeigermann.xml.simpleImporter.ConversionHelpers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Step {
private static Logger logger = Logger.getLogger(Step.class.getName());
private URI processorURI;
private String name;
private Map parameterConfigurations = new HashMap();
private Map resultConfigurations = new HashMap();
private List routingConfigurations = new ArrayList();
public String getName() {
return name;
}
public URI getProcessorURI() {
return processorURI;
}
public Map getParameterConfigurations() {
return parameterConfigurations;
}
public Map getResultConfigurations() {
return resultConfigurations;
}
public List getRoutingConfigurations() {
return routingConfigurations;
}
public void configure(Element element) {
name = element.getAttributeValue("id");
processorURI = new URIValue(element.getAttributeValue("processor"));
List loadElements = element.getChildren("load");
for ( Iterator i = loadElements.iterator(); i.hasNext(); ) {
Element loadElement = (Element)i.next();
String parameterName = loadElement.getAttributeValue("parameter");
ParameterConfiguration parameterConfiguration = new ParameterConfiguration(parameterName);
Iterator childIterator = loadElement.getChildren().iterator();
if ( childIterator.hasNext() ) {
Element valueElement = (Element)childIterator.next();
parameterConfiguration.configure(valueElement);
parameterConfigurations.put(parameterName, parameterConfiguration);
}
}
List saveElements = element.getChildren("save");
for ( Iterator i = saveElements.iterator(); i.hasNext(); ) {
Element saveElement = (Element)i.next();
String resultName = saveElement.getAttributeValue("result");
String resultStore = saveElement.getAttributeValue("store");
String resultDomain = saveElement.getAttributeValue("domain");
String resultKey = saveElement.getAttributeValue("key");
String timeoutAsString = saveElement.getAttributeValue("timeout");
long timeout = -1;
if ( timeoutAsString != null ) {
timeout = Long.valueOf(timeoutAsString).longValue();
}
boolean presentableResult = ConversionHelpers.getBoolean(saveElement.getAttributeValue("presentable"), false);
ResultConfiguration resultConfiguration;
if (resultStore == null) {
resultConfiguration = new ResultConfiguration(resultName, Store.NONE, resultDomain, resultKey, presentableResult, timeout);
} else {
resultConfiguration = new ResultConfiguration(resultName, resultStore, resultDomain, resultKey, presentableResult, timeout);
}
resultConfigurations.put(resultName, resultConfiguration);
}
List routeElements = element.getChildren("route");
for ( Iterator i = routeElements.iterator(); i.hasNext(); ) {
Element routeElement = (Element)i.next();
String state = routeElement.getAttributeValue("state");
String exception = routeElement.getAttributeValue("exception");
String step = routeElement.getAttributeValue("step");
String returnValue = routeElement.getAttributeValue("return");
if (state != null) {
RoutingConfiguration routingConfiguration = new RoutingConfiguration(state);
if (returnValue != null) {
routingConfiguration.setReturnValue(returnValue);
}
if (step != null) {
routingConfiguration.setStep(step);
}
routingConfigurations.add(routingConfiguration);
} else if (exception != null) {
try {
Class clazz = Class.forName(exception);
routingConfigurations.add(new RoutingConfiguration(clazz, step));
} catch (ClassNotFoundException e) {
logger.log(Level.SEVERE, "Could not find exception class=" + exception + ", skipping exception routing");
}
}
}
}
}
1.3 +7 -4 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/Exists.java
Index: Exists.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/Exists.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Exists.java 1 Jun 2004 07:49:55 -0000 1.2
+++ Exists.java 8 Jun 2004 09:04:06 -0000 1.3
@@ -23,6 +23,12 @@
public final static String TRUE = "true";
public final static String FALSE = "false";
+ private final static ResultDescriptor resultDescriptor = new ResultDescriptor(new StateDescriptor[]{
+ new StateDescriptor(TRUE, new DefaultMessage("exists/state/true")),
+ new StateDescriptor(FALSE, new DefaultMessage("exists/state/false"))
+ });
+
+
public Result process(Map parameter, Context context) throws Exception {
Value input = (Value)parameter.get(INPUT);
if ( input instanceof ObjectValue && ((ObjectValue)input).getObject() == null ) {
@@ -35,9 +41,6 @@
return new ParameterDescriptor[]{ new ParameterDescriptor(INPUT, new ParameterMessage("exists/input"), new ResourceValueDescriptor()) }; }
public ResultDescriptor getResultDescriptor() {
- return new ResultDescriptor(new StateDescriptor[]{
- new StateDescriptor(TRUE, new DefaultMessage("exists/state/true")),
- new StateDescriptor(FALSE, new DefaultMessage("exists/state/false"))
- });
+ return resultDescriptor;
}
}
1.3 +4 -4 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/MapEntry.java
Index: MapEntry.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/MapEntry.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MapEntry.java 1 Jun 2004 07:49:55 -0000 1.2
+++ MapEntry.java 8 Jun 2004 09:04:06 -0000 1.3
@@ -23,11 +23,11 @@
package org.apache.slide.projector.processor;
+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.descriptor.*;
-import org.apache.slide.projector.engine.ContentType;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.value.MapValue;
1.3 +1 -1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/Echo.java
Index: Echo.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/Echo.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Echo.java 1 Jun 2004 07:49:55 -0000 1.2
+++ Echo.java 8 Jun 2004 09:04:06 -0000 1.3
@@ -1,10 +1,10 @@
package org.apache.slide.projector.processor;
+import org.apache.slide.projector.ContentType;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResourceValueDescriptor;
import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
-import org.apache.slide.projector.engine.ContentType;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.value.Value;
1.5 +1 -1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/URL.java
Index: URL.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/URL.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- URL.java 1 Jun 2004 07:49:55 -0000 1.4
+++ URL.java 8 Jun 2004 09:04:06 -0000 1.5
@@ -1,12 +1,12 @@
package org.apache.slide.projector.processor;
+import org.apache.slide.projector.ContentType;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.HttpContext;
import org.apache.slide.projector.ProcessException;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
import org.apache.slide.projector.descriptor.StringValueDescriptor;
-import org.apache.slide.projector.engine.ContentType;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
1.5 +0 -1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/TemplateRenderer.java
Index: TemplateRenderer.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/TemplateRenderer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TemplateRenderer.java 1 Jun 2004 07:49:55 -0000 1.4
+++ TemplateRenderer.java 8 Jun 2004 09:04:06 -0000 1.5
@@ -2,7 +2,6 @@
import org.apache.slide.projector.*;
import org.apache.slide.projector.descriptor.*;
-import org.apache.slide.projector.engine.ContentType;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
1.4 +1 -1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/Link.java
Index: Link.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/Link.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Link.java 1 Jun 2004 07:49:55 -0000 1.3
+++ Link.java 8 Jun 2004 09:04:06 -0000 1.4
@@ -18,9 +18,9 @@
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.Process;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
+import org.apache.slide.projector.processor.process.Process;
import org.apache.slide.projector.value.BooleanValue;
import org.apache.slide.projector.value.MapValue;
import org.apache.slide.projector.value.NullValue;
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/Thread.java
Index: Thread.java
===================================================================
/*
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.projector.processor;
import java.util.Map;
import org.apache.slide.projector.Context;
import org.apache.slide.projector.Processor;
import org.apache.slide.projector.Result;
import org.apache.slide.projector.URI;
import org.apache.slide.projector.descriptor.BooleanValueDescriptor;
import org.apache.slide.projector.descriptor.MapValueDescriptor;
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResultDescriptor;
import org.apache.slide.projector.descriptor.StateDescriptor;
import org.apache.slide.projector.descriptor.URIValueDescriptor;
import org.apache.slide.projector.descriptor.XMLValueDescriptor;
import org.apache.slide.projector.engine.Job;
import org.apache.slide.projector.engine.ProcessorManager;
import org.apache.slide.projector.engine.Scheduler;
import org.apache.slide.projector.expression.Expression;
import org.apache.slide.projector.expression.ExpressionFactory;
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.util.ProcessorHelper;
import org.apache.slide.projector.value.BooleanValue;
import org.apache.slide.projector.value.MapValue;
import org.apache.slide.projector.value.URIValue;
import org.apache.slide.projector.value.XMLValue;
/**
* @author dflorey
*/
public class Thread implements Processor {
// parameters
public final static String PROCESSOR = "processor";
public final static String REPEAT = "repeat";
public final static String CONDITION = "condition";
public final static String PARAMETERS = "parameters";
public final static String PERSISTENT = "persistent";
private final static ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[] {
new ParameterDescriptor(PROCESSOR, new ParameterMessage("job/parameter/processor"), new URIValueDescriptor()),
new ParameterDescriptor(REPEAT, new ParameterMessage("job/parameter/repeat"), new BooleanValueDescriptor(), BooleanValue.FALSE),
new ParameterDescriptor(PERSISTENT, new ParameterMessage("job/parameter/persistent"), new BooleanValueDescriptor(), BooleanValue.TRUE),
new ParameterDescriptor(CONDITION, new ParameterMessage("job/parameter/condition"), new XMLValueDescriptor()),
new ParameterDescriptor(PARAMETERS, new ParameterMessage("job/parameter/parameters"), new MapValueDescriptor())
};
private final static ResultDescriptor resultDescriptor = new ResultDescriptor(new StateDescriptor[] {
StateDescriptor.OK_DESCRIPTOR
});
public Result process(Map parameters, Context context) throws Exception {
Map jobParameters = ((MapValue)parameters.get(PARAMETERS)).getMap();
URI jobUri = (URIValue)parameters.get(PROCESSOR);
XMLValue condition = (XMLValue)parameters.get(CONDITION);
boolean repeatJob = ((BooleanValue)parameters.get(REPEAT)).booleanValue();
boolean persistentJob = ((BooleanValue)parameters.get(PERSISTENT)).booleanValue();
Expression expression = ExpressionFactory.create(condition.getRootElement());
Processor jobProcessor = ProcessorManager.getInstance().getProcessor(jobUri);
ProcessorHelper.validate(jobProcessor.getParameterDescriptors(), jobParameters, context);
Job job = new Job(expression, jobUri, jobParameters, repeatJob, persistentJob);
Scheduler.getInstance().activateJob(job);
return Result.OK;
}
public ParameterDescriptor[] getParameterDescriptors() {
return parameterDescriptors;
}
public ResultDescriptor getResultDescriptor() {
return resultDescriptor;
}
}
1.1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/ContentType.java
Index: ContentType.java
===================================================================
package org.apache.slide.projector;
import java.util.Iterator;
import java.util.List;
public class ContentType {
public final static String XML = "text/xml";
public final static String HTML = "text/html";
public final static String PLAIN_TEXT = "text/plain";
public final static String ANY_TEXT = "text/*";
public final static String DYNAMIC = "*";
public static String determineContentType(String content) {
if (content.indexOf("<html") != -1 ) {
return HTML;
} else if (content.startsWith("<?xml")) {
return XML;
} else {
return PLAIN_TEXT;
}
}
public static boolean determineIsDocument(String content) {
if (determineContentType(content) == PLAIN_TEXT ) {
return false;
}
return true;
}
public static boolean matches(String requiredContentType, String givenContentType) {
if ( requiredContentType.equals(givenContentType) ) return true;
if ( requiredContentType.endsWith("*") && givenContentType.startsWith(requiredContentType.substring(0, requiredContentType.length()-1)) ) return true;
return false;
}
public static boolean matches(String []allowedContentTypes, String givenContentType) {
for ( int i = 0; i < allowedContentTypes.length; i++ ) {
if ( matches(allowedContentTypes[i], givenContentType ) ) return true;
}
return false;
}
public static String getContentTypesAsString(List contentTypes) {
StringBuffer buffer = new StringBuffer(256);
boolean first = true;
for ( Iterator i = contentTypes.iterator(); i.hasNext(); ) {
if ( !first ) {
buffer.append(", ");
}
first = false;
buffer.append(i.next());
}
return buffer.toString();
}
public static String getContentTypesAsString(String[] contentTypes) {
StringBuffer buffer = new StringBuffer(256);
for ( int i = 0; i < contentTypes.length; i++ ) {
if ( i > 0 ) {
buffer.append(", ");
}
buffer.append(contentTypes[i]);
}
return buffer.toString();
}
}
1.4 +1 -1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/descriptor/ResourceValueDescriptor.java
Index: ResourceValueDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/descriptor/ResourceValueDescriptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResourceValueDescriptor.java 1 Jun 2004 07:49:54 -0000 1.3
+++ ResourceValueDescriptor.java 8 Jun 2004 09:04:06 -0000 1.4
@@ -1,7 +1,7 @@
package org.apache.slide.projector.descriptor;
+import org.apache.slide.projector.ContentType;
import org.apache.slide.projector.Context;
-import org.apache.slide.projector.engine.ContentType;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.value.ArrayValue;
import org.apache.slide.projector.value.NullValue;
1.2 +2 -1 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/StringValue.java
Index: StringValue.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/StringValue.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StringValue.java 1 Jun 2004 07:49:55 -0000 1.1
+++ StringValue.java 8 Jun 2004 09:04:06 -0000 1.2
@@ -3,7 +3,8 @@
import de.zeigermann.xml.XMLEncode;
import de.zeigermann.xml.XMLStringWriter;
import de.zeigermann.xml.XMLWriter;
-import org.apache.slide.projector.engine.ContentType;
+
+import org.apache.slide.projector.ContentType;
import java.io.ByteArrayInputStream;
import java.io.IOException;
1.2 +3 -0 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/DocumentValue.java
Index: DocumentValue.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/DocumentValue.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DocumentValue.java 1 Jun 2004 07:49:55 -0000 1.1
+++ DocumentValue.java 8 Jun 2004 09:04:06 -0000 1.2
@@ -12,6 +12,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.logging.Level;
import java.util.logging.Logger;
public class DocumentValue extends AbstractStreamableValue implements XMLValue {
@@ -69,9 +70,11 @@
try {
document = saxBuilder.build(inputStream);
} catch (JDOMException e) {
+ logger.log(Level.SEVERE, "Could not create XML document from given input stream", e);
// FIXME: Exception handling!
document = null;
} catch (IOException e) {
+ logger.log(Level.SEVERE, "Could not create XML document from given input stream", e);
document = null;
}
}
1.4 +1 -2 jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/xml/XPathQuery.java
Index: XPathQuery.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/xml/XPathQuery.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XPathQuery.java 2 Jun 2004 13:58:53 -0000 1.3
+++ XPathQuery.java 8 Jun 2004 09:04:06 -0000 1.4
@@ -4,7 +4,6 @@
import org.apache.slide.projector.descriptor.ParameterDescriptor;
import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
import org.apache.slide.projector.descriptor.StringValueDescriptor;
-import org.apache.slide.projector.engine.ContentType;
import org.apache.slide.projector.i18n.DefaultMessage;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.i18n.ParameterMessage;
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org