Update of /cvsroot/metamorphosis/krysalis-sandbox/workflow/src/java/org/krysalis/workflow/manager
In directory sc8-pr-cvs1:/tmp/cvs-serv11380/src/java/org/krysalis/workflow/manager
Modified Files:
DefaultWorkFlow.java DefaultWorkFlowManager.java
DefaultWorkFlowMapper.java workflow.roles
Log Message:
Managed the first running test case.
Add all avalon libs, which will be needed(incredible many!).
Index: DefaultWorkFlow.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-sandbox/workflow/src/java/org/krysalis/workflow/manager/DefaultWorkFlow.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DefaultWorkFlow.java 14 Mar 2003 09:17:27 -0000 1.1
--- DefaultWorkFlow.java 14 Mar 2003 15:06:08 -0000 1.2
***************
*** 23,212 ****
/**
! * Implementation of a determinitic automate.
*/
! public class DefaultWorkFlow extends AbstractLogEnabled implements
! WorkFlow, Configurable/*, Disposable*/ {
! /** Component manager */
! private ComponentManager manager = null;
! private String[] stateNames;
! // 1.Index:state 2.Index:event 3.Index:Index of component
! private int[][] transitions;
! private String[][] transitionEvents;
! private WorkFlowCondition[][] transitionConditions;
! private Parameters[][] transitionConditionParameters;
! private WorkFlowAction[][][] transitionActions;
! private Parameters[][][] transitionActionParameters;
! // Intial state
! private int initalState;
! /**
! * Pass the <code>ComponentManager</code> to the <code>composer</code>.
! * The <code>Composable</code> implementation should use the specified
! * <code>ComponentManager</code> to acquire the components it needs for
! * execution.
! *
! * @param componentManager The <code>ComponentManager</code> which this
! * <code>Composable</code> uses.
! * @throws ComponentException if an error occurs
! */
! public void compose(ComponentManager componentManager)
! throws ComponentException {
! this.manager = componentManager;
! }
! /**
! * Pass the <code>Configuration</code> to the <code>Configurable</code>
! * class. This method must always be called after the constructor
! * and before any other method.
! *
! * @param configuration the class configurations.
! * @throws ConfigurationException If an error occurs.
! */
! public void configure(Configuration configuration)
! throws ConfigurationException {
! Configuration[] states = configuration.getChildren("state");
! this.stateNames = new String[states.length];
! for(int i=0; i<states.length; i++)
! this.stateNames[i] = states[i].getAttribute("id");
! this.initalState = indexOfState(configuration.getAttribute("inital"));
! this.transitions = new int[states.length][];
! Configuration[] transitions, actions;
! Configuration condition;
! for(int state=0; state<states.length; state++) {
! transitions = states[state].getChildren("transition");
! this.transitions[state] = new int[transitions.length];
! for(int transition=0; transition<transitions.length; transition++) {
! this.transitions[state][transition] =
! indexOfState(transitions[transition].getAttribute("ref", stateNames[state]));
! if (transitions[transition].getAttribute("event")!=null)
! this.transitionEvents[state][transition] =
! transitions[transition].getAttribute("event");
! else
! throw new ConfigurationException("Transition of state '"+this.stateNames[state]+"' don't own an event");
! condition = transitions[state].getChild("condition", false);
! if (condition!=null) {
! this.transitionConditions[state][transition] =
! (WorkFlowCondition)this.manager.lookup(condition.getAttribute("name"));
! this.transitionConditionParameters[state][transition] =
! Parameters.fromConfiguration(condition);
! } else {
! this.transitionConditions[state][transition] = null;
! this.transitionConditionParameters[state][transition] = null;
! }
! actions = transitions[state].getChildren("action");
! for(int action=0; action<actions.length; action++) {
! this.transitionActions[state][transition][action] =
! (WorkFlowAction)this.manager.lookup(actions[action].getAttribute("name"));
! this.transitionActionParameters[state][transition][action] =
! Parameters.fromConfiguration(actions[action]);
! }
! }
}
- }
! private int indexOfState(String name) {
! for(int i=0; i<stateNames.length; i++)
! if(this.stateNames.equals(name))
! return i;
}
! private int indexOfTransition(int state, String event) {
! for(int i=0; i<this.transitionEvents.length; i++)
! if(this.transitionEvents[state].equals(event))
! return i;
! }
! public WorkFlowState process(WorkFlowState currentState, WorkFlowEvent event) {
! if (currentState==null) {
! // Add the initial state to the state
! currentState = new DefaultWorkFlowState(this.stateNames[this.initalState]);
! }
! int state = indexOfState(currentState.getState());
! int transition;
! if(event!=null) {
! transition = indexOfTransition(state, event.getName());
! if (transition<0)
! // If doesn't exist a transition ignore the event
! return null;
! // Execute transition
! if (transitionConditions[state][transition]!=null) {
! if (transitionConditions[state][transition].evaluate(
! currentState, event,
! transitionConditionParameters[state][transition])) {
! state = transitions[state][transition];
! currentState.setState(stateNames[state]);
! try {
! // Executes all actions
! for (int action=0; action<transitionActions[state][transition].length; action++)
! transitionActions[state][transition][action].perform(currentState, event,
! transitionActionParameters[state][transition][action]);
! } catch (Exception e) {
! getLogger().error("Could not perform actions", e);
! }
! }
! } else {
! state = transitions[state][transition];
! currentState.setState(stateNames[state]);
! try {
! // Executes all actions
! for (int action=0; action<transitionActions[state][transition].length; action++)
! transitionActions[state][transition][action].perform(currentState, event,
! transitionActionParameters[state][transition][action]);
! } catch (Exception e) {
! getLogger().error("Could not perform actions", e);
! }
! }
}
! boolean changed;
! do {
! changed = false;
! for(transition=0; transition<transitionConditions.length; transition++)
! if ((transitionEvents[state][transition]==null) &&
! transitionConditions[state][transition].evaluate(
! currentState, null,
! transitionConditionParameters[state][transition])) {
! state = transitions[state][transition];
! currentState.setState(stateNames[state]);
! try {
! // Executes all actions
! for (int action=0; action<transitionActions[state][transition].length; action++)
! transitionActions[state][transition][action].perform(currentState, null,
! transitionActionParameters[state][transition][action]);
! } catch (Exception e) {
! getLogger().error("Could not perform actions", e);
! }
! break;
! }
-
- } while (changed);
}
}
--- 23,288 ----
/**
! *
! *
! * @author <a href="mailto:[email protected]">Stephan Michels </a>
! * @version CVS $Id$
*/
! public class DefaultWorkFlow extends AbstractLogEnabled
! implements WorkFlow, Configurable /* , Disposable */
! {
! /** Component manager */
! private ComponentManager manager = null;
! private String[] stateNames;
! // 1.Index:state 2.Index:event 3.Index:Index of component
! private int[][] transitions;
! private String[][] transitionEvents;
! private WorkFlowCondition[][] transitionConditions;
! private Parameters[][] transitionConditionParameters;
! private WorkFlowAction[][][] transitionActions;
! private Parameters[][][] transitionActionParameters;
! // Intial state
! private int initalState;
! /**
! * Pass the <code>ComponentManager</code> to the <code>composer</code>.
! * The <code>Composable</code> implementation should use the specified
! * <code>ComponentManager</code> to acquire the components it needs for
! * execution.
! *
! * @param componentManager The <code>ComponentManager</code> which this
! * <code>Composable</code> uses.
! * @throws ComponentException if an error occurs
! */
! public void compose(ComponentManager componentManager)
! throws ComponentException
! {
! this.manager = componentManager;
! }
! /**
! * Pass the <code>Configuration</code> to the <code>Configurable</code>
! * class. This method must always be called after the constructor
! * and before any other method.
! *
! * @param configuration the class configurations.
! * @throws ConfigurationException If an error occurs.
! */
! public void configure(Configuration configuration)
! throws ConfigurationException
! {
! Configuration[] states = configuration.getChildren("state");
! this.stateNames = new String[states.length];
! for (int i = 0; i<states.length; i++)
! this.stateNames[i] = states[i].getAttribute("id");
! this.initalState = indexOfState(configuration.getAttribute("inital"));
! this.transitions = new int[states.length][];
! Configuration[] transitions, actions;
! Configuration condition;
! for (int state = 0; state<states.length; state++)
! {
! transitions = states[state].getChildren("transition");
! this.transitions[state] = new int[transitions.length];
! for (int transition = 0; transition<transitions.length; transition++)
! {
! this.transitions[state][transition] = indexOfState(transitions[transition].getAttribute("ref",
! stateNames[state]));
! if (transitions[transition].getAttribute("event")!=null)
! this.transitionEvents[state][transition] = transitions[transition].getAttribute("event");
! else
! throw new ConfigurationException("Transition of state '"+
! this.stateNames[state]+
! "' don't own an event");
!
! condition = transitions[state].getChild("condition", false);
! if (condition!=null)
! {
! try
! {
! this.transitionConditions[state][transition] = (WorkFlowCondition) this.manager.lookup(condition.getAttribute("name"));
! }
! catch (ComponentException ce)
! {
! throw new ConfigurationException("Could not retrieve condition '"+
! condition.getAttribute("name")+
! "'", ce);
! }
! this.transitionConditionParameters[state][transition] = Parameters.fromConfiguration(condition);
! }
! else
! {
! this.transitionConditions[state][transition] = null;
! this.transitionConditionParameters[state][transition] = null;
}
! actions = transitions[state].getChildren("action");
! for (int action = 0; action<actions.length; action++)
! {
! try
! {
! this.transitionActions[state][transition][action] = (WorkFlowAction) this.manager.lookup(actions[action].getAttribute("name"));
! }
! catch (ComponentException ce)
! {
! throw new ConfigurationException("Could not retrieve action '"+
! actions[action].getAttribute("name")+
! "'", ce);
! }
! this.transitionActionParameters[state][transition][action] = Parameters.fromConfiguration(actions[action]);
! }
! }
}
+ }
! /**
! *
! *
! * @param name
! *
! * @return
! */
! private int indexOfState(String name)
! {
! for (int i = 0; i<stateNames.length; i++)
! if (this.stateNames.equals(name))
! return i;
! return -1;
! }
! /**
! *
! *
! * @param state
! * @param event
! *
! * @return
! */
! private int indexOfTransition(int state, String event)
! {
! for (int i = 0; i<this.transitionEvents.length; i++)
! if (this.transitionEvents[state].equals(event))
! return i;
! return -1;
! }
! /**
! *
! *
! * @param currentState
! * @param event
! */
! public void process(WorkFlowState currentState, WorkFlowEvent event)
! {
! if (currentState==null)
! {
! // Add the initial state to the state
! currentState = new DefaultWorkFlowState(this.stateNames[this.initalState]);
! }
! int state = indexOfState(currentState.getState());
! int transition;
! if (event!=null)
! {
! transition = indexOfTransition(state, event.getName());
! if (transition<0)
! // If doesn't exist a transition ignore the event
! return;
! // Execute transition
! if (transitionConditions[state][transition]!=null)
! {
! if (transitionConditions[state][transition].evaluate(currentState,
! event, transitionConditionParameters[state][transition]))
! {
! state = transitions[state][transition];
! currentState.setState(stateNames[state]);
! try
! {
! // Executes all actions
! for (int action = 0;
! action<transitionActions[state][transition].length; action++)
! transitionActions[state][transition][action].perform(currentState,
! event,
! transitionActionParameters[state][transition][action]);
! }
! catch (Exception e)
! {
! getLogger().error("Could not perform actions", e);
! }
! }
! }
! else
! {
! state = transitions[state][transition];
! currentState.setState(stateNames[state]);
! try
! {
! // Executes all actions
! for (int action = 0;
! action<transitionActions[state][transition].length; action++)
! transitionActions[state][transition][action].perform(currentState,
! event, transitionActionParameters[state][transition][action]);
}
+ catch (Exception e)
+ {
+ getLogger().error("Could not perform actions", e);
+ }
+ }
! }
! boolean changed;
! do
! {
! changed = false;
! for (transition = 0; transition<transitionConditions.length;
! transition++)
! if ((transitionEvents[state][transition]==null) &&
! transitionConditions[state][transition].evaluate(currentState,
! null, transitionConditionParameters[state][transition]))
! {
! state = transitions[state][transition];
! currentState.setState(stateNames[state]);
! try
! {
! // Executes all actions
! for (int action = 0;
! action<transitionActions[state][transition].length; action++)
! transitionActions[state][transition][action].perform(currentState,
! null,
! transitionActionParameters[state][transition][action]);
! }
! catch (Exception e)
! {
! getLogger().error("Could not perform actions", e);
! }
!
! break;
! }
}
+ while (changed);
+ }
}
***************
*** 215,219 ****
Copyright (c) 2002 Nicola Ken Barozzi. All rights reserved.
! This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
--- 291,295 ----
Copyright (c) 2002 Nicola Ken Barozzi. All rights reserved.
! This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
***************
*** 233,237 ****
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
! "This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
--- 309,313 ----
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
! "This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
***************
*** 242,251 ****
derived from this software without prior written permission. For
written permission, please contact [email protected].
!
5. Products derived from this software may not be called "Krysalis",
"Krysalis Metamorphosis", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.
! 6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in
respect of this licence.
--- 318,327 ----
derived from this software without prior written permission. For
written permission, please contact [email protected].
!
5. Products derived from this software may not be called "Krysalis",
"Krysalis Metamorphosis", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.
! 6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in
respect of this licence.
Index: DefaultWorkFlowManager.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-sandbox/workflow/src/java/org/krysalis/workflow/manager/DefaultWorkFlowManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DefaultWorkFlowManager.java 14 Mar 2003 09:17:27 -0000 1.1
--- DefaultWorkFlowManager.java 14 Mar 2003 15:06:08 -0000 1.2
***************
*** 16,19 ****
--- 16,20 ----
import org.apache.avalon.framework.activity.Disposable;
+ import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
***************
*** 25,28 ****
--- 26,31 ----
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
+ import org.apache.avalon.framework.context.Context;
+ import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
***************
*** 39,48 ****
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
! public class DefaultWorkFlowManager extends AbstractLogEnabled
! implements WorkFlowManager, Configurable, LogKitManageable
{
private ComponentManager pcm;
private ComponentManager cm;
private LogKitManager lkm;
private String file;
--- 42,60 ----
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+ import org.xml.sax.SAXParseException;
! /**
! *
! *
! * @author <a href="mailto:[email protected]">Stephan Michels </a>
! * @version CVS $Id$
! */
! public class DefaultWorkFlowManager extends AbstractLogEnabled
! implements WorkFlowManager, Configurable, Composable, Contextualizable,
! LogKitManageable, Initializable
{
private ComponentManager pcm;
private ComponentManager cm;
+ private Context context;
private LogKitManager lkm;
private String file;
***************
*** 59,65 ****
*/
public void compose(ComponentManager componentManager)
! throws ComponentException
{
! this.pcm = componentManager;
}
--- 71,77 ----
*/
public void compose(ComponentManager componentManager)
! throws ComponentException
{
! pcm = componentManager;
}
***************
*** 73,83 ****
*/
public void configure(Configuration configuration)
! throws ConfigurationException
{
! this.file = configuration.getAttribute("file", "WEB-INF/workflow.xconf");
}
/**
* Configure the LogKitManager
*/
public void setLogKitManager(LogKitManager logkit)
--- 85,106 ----
*/
public void configure(Configuration configuration)
! throws ConfigurationException
{
! this.file = configuration.getAttribute("file", "WEB-INF/workflow.xconf");
! }
!
! /** Set up the Component's Context.
! *
! * @param context
! */
! public void contextualize(final Context context)
! {
! this.context = context;
}
/**
* Configure the LogKitManager
+ *
+ * @param logkit
*/
public void setLogKitManager(LogKitManager logkit)
***************
*** 91,95 ****
* components lifecycle.
*/
! public void initialize() throws Exception
{
SourceResolver resolver = null;
--- 114,118 ----
* components lifecycle.
*/
! public void initialize() throws Exception
{
SourceResolver resolver = null;
***************
*** 99,103 ****
Configuration configuration = null;
! try
{
resolver = (SourceResolver) pcm.lookup(SourceResolver.ROLE);
--- 122,126 ----
Configuration configuration = null;
! try
{
resolver = (SourceResolver) pcm.lookup(SourceResolver.ROLE);
***************
*** 106,136 ****
SAXConfigurationHandler confighandler = new SAXConfigurationHandler();
! source = resolver.resolveURI("resource://org/krysalis/workflow/workflow.roles");
! parser.parse(new InputSource(source.getInputStream()),
! confighandler);
! roleConfig = confighandler.getConfiguration();
source = resolver.resolveURI(this.file);
! parser.parse(new InputSource(source.getInputStream()),
! confighandler);
configuration = confighandler.getConfiguration();
! }
! catch (Exception e)
{
getLogger().error("Could not load workflow configuration file", e);
return;
! }
! finally
{
! if (source!=null)
resolver.release(source);
! if (parser!=null)
pcm.release((Component) parser);
! if (resolver!=null)
pcm.release(resolver);
}
DefaultRoleManager rm = new DefaultRoleManager();
rm.enableLogging(getLogger());
rm.configure(roleConfig);
--- 129,170 ----
SAXConfigurationHandler confighandler = new SAXConfigurationHandler();
! source = resolver.resolveURI("resource://org/krysalis/workflow/manager/workflow.roles");
! InputSource in = new InputSource(source.getInputStream());
!
! in.setSystemId(source.getURI());
! parser.parse(in, confighandler);
! roleConfig = confighandler.getConfiguration();
source = resolver.resolveURI(this.file);
! in = new InputSource(source.getInputStream());
! in.setSystemId(source.getURI());
! parser.parse(in, confighandler);
configuration = confighandler.getConfiguration();
! }
! catch (SAXParseException saxpe)
! {
! getLogger().error("Configuration file "+saxpe.getSystemId()+
! " include error at line "+saxpe.getLineNumber()+
! " and column "+saxpe.getColumnNumber(), saxpe);
! return;
! }
! catch (Exception e)
{
getLogger().error("Could not load workflow configuration file", e);
return;
! }
! finally
{
! if (source!=null)
resolver.release(source);
! if (parser!=null)
pcm.release((Component) parser);
! if (resolver!=null)
pcm.release(resolver);
}
DefaultRoleManager rm = new DefaultRoleManager();
+
rm.enableLogging(getLogger());
rm.configure(roleConfig);
***************
*** 138,150 ****
cm = new ExcaliburComponentManager();
if (cm instanceof LogEnabled)
! ((LogEnabled)cm).enableLogging(getLogger());
if (cm instanceof RoleManageable)
! ((RoleManageable)cm).setRoleManager(rm);
if (cm instanceof LogKitManageable)
! ((LogKitManageable)cm).setLogKitManager(lkm);
if (cm instanceof Configurable)
! ((Configurable)cm).configure(configuration);
}
public void process(String resource, WorkFlowEvent event)
{
--- 172,192 ----
cm = new ExcaliburComponentManager();
if (cm instanceof LogEnabled)
! ((LogEnabled) cm).enableLogging(getLogger());
if (cm instanceof RoleManageable)
! ((RoleManageable) cm).setRoleManager(rm);
! if (cm instanceof Contextualizable)
! ((Contextualizable) cm).contextualize(context);
if (cm instanceof LogKitManageable)
! ((LogKitManageable) cm).setLogKitManager(lkm);
if (cm instanceof Configurable)
! ((Configurable) cm).configure(configuration);
}
+ /**
+ *
+ *
+ * @param resource
+ * @param event
+ */
public void process(String resource, WorkFlowEvent event)
{
***************
*** 153,164 ****
WorkFlow workflow = null;
WorkFlowState state = lookup(resource);
try
{
! mapper = (WorkFlowMapper)cm.lookup(WorkFlowMapper.ROLE);
! workflowselector = (ComponentSelector)cm.lookup(WorkFlow.ROLE+"Selector");
workflow = (WorkFlow) workflowselector.select(mapper.getWorkFlow(resource));
! state = workflow.process(state, event);
}
catch (Exception e)
--- 195,208 ----
WorkFlow workflow = null;
WorkFlowState state = lookup(resource);
+
try
{
! mapper = (WorkFlowMapper) cm.lookup(WorkFlowMapper.ROLE);
! workflowselector = (ComponentSelector) cm.lookup(WorkFlow.ROLE+
! "Selector");
workflow = (WorkFlow) workflowselector.select(mapper.getWorkFlow(resource));
! workflow.process(state, event);
}
catch (Exception e)
***************
*** 180,183 ****
--- 224,234 ----
}
+ /**
+ *
+ *
+ * @param resource
+ *
+ * @return
+ */
public WorkFlowState lookup(String resource)
{
***************
*** 186,196 ****
WorkFlowStore store = null;
WorkFlowState state = null;
try
{
! mapper = (WorkFlowMapper)cm.lookup(WorkFlowMapper.ROLE);
! storeselector = (ComponentSelector)cm.lookup(WorkFlowStore.ROLE+"Selector");
store = (WorkFlowStore) storeselector.select(mapper.getWorkFlowStore(resource));
!
state = store.lookup(resource);
}
--- 237,249 ----
WorkFlowStore store = null;
WorkFlowState state = null;
+
try
{
! mapper = (WorkFlowMapper) cm.lookup(WorkFlowMapper.ROLE);
! storeselector = (ComponentSelector) cm.lookup(WorkFlowStore.ROLE+
! "Selector");
store = (WorkFlowStore) storeselector.select(mapper.getWorkFlowStore(resource));
!
state = store.lookup(resource);
}
***************
*** 212,215 ****
--- 265,273 ----
}
+ /**
+ *
+ *
+ * @param state
+ */
public void release(WorkFlowState state)
{
***************
*** 217,225 ****
ComponentSelector storeselector = null;
WorkFlowStore store = null;
try
{
! mapper = (WorkFlowMapper)cm.lookup(WorkFlowMapper.ROLE);
! storeselector = (ComponentSelector)cm.lookup(WorkFlowStore.ROLE+"Selector");
store = (WorkFlowStore) storeselector.select(mapper.getWorkFlowStore(state.getResource()));
--- 275,285 ----
ComponentSelector storeselector = null;
WorkFlowStore store = null;
+
try
{
! mapper = (WorkFlowMapper) cm.lookup(WorkFlowMapper.ROLE);
! storeselector = (ComponentSelector) cm.lookup(WorkFlowStore.ROLE+
! "Selector");
store = (WorkFlowStore) storeselector.select(mapper.getWorkFlowStore(state.getResource()));
***************
*** 242,243 ****
--- 302,356 ----
}
}
+ /*
+ The Krysalis Patchy Software License, Version 1.1_01
+ Copyright (c) 2002 Nicola Ken Barozzi. All rights reserved.
+
+ This Licence is compatible with the BSD licence as described and
+ approved by http://www.opensource.org/, and is based on the
+ Apache Software Licence Version 1.1.
+
+ 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 acknowledgment:
+ "This product includes software developed for project
+ Krysalis (http://www.krysalis.org/)."
+ Alternately, this acknowledgment may appear in the software itself,
+ if and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Krysalis" and "Nicola Ken Barozzi" and
+ "Krysalis Metamorphosis" must not be used to endorse or promote products
+ derived from this software without prior written permission. For
+ written permission, please contact [email protected].
+
+ 5. Products derived from this software may not be called "Krysalis",
+ "Krysalis Metamorphosis", nor may "Krysalis" appear in their name,
+ without prior written permission of Nicola Ken Barozzi.
+
+ 6. This software may contain voluntary contributions made by many
+ individuals, who decided to donate the code to this project in
+ respect of this licence.
+
+ 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 KRYSALIS PROJECT 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.
+ ====================================================================*/
Index: DefaultWorkFlowMapper.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-sandbox/workflow/src/java/org/krysalis/workflow/manager/DefaultWorkFlowMapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DefaultWorkFlowMapper.java 14 Mar 2003 09:17:27 -0000 1.1
--- DefaultWorkFlowMapper.java 14 Mar 2003 15:06:09 -0000 1.2
***************
*** 20,35 ****
import org.apache.avalon.framework.thread.ThreadSafe;
import org.krysalis.workflow.*;
! public class DefaultWorkFlowMapper implements WorkFlowMapper
{
public String getWorkFlow(String resource)
{
return null;
}
public String getWorkFlowStore(String resource)
{
return null;
}
}
--- 20,192 ----
import org.apache.avalon.framework.thread.ThreadSafe;
+ import org.apache.regexp.RE;
+ import org.apache.regexp.RECompiler;
+ import org.apache.regexp.REProgram;
+ import org.apache.regexp.RESyntaxException;
+
import org.krysalis.workflow.*;
! /**
! *
! *
! * @author <a href="mailto:[email protected]">Stephan Michels </a>
! * @version CVS $Id$
! */
! public class DefaultWorkFlowMapper implements WorkFlowMapper, Configurable
{
+ private RE[] pattern;
+ private String[] workflow;
+ private String[] store;
+
+ /**
+ * Pass the <code>Configuration</code> to the <code>Configurable</code>
+ * class. This method must always be called after the constructor
+ * and before any other method.
+ *
+ * @param configuration the class configurations.
+ * @throws ConfigurationException If an error occurs.
+ */
+ public void configure(Configuration configuration)
+ throws ConfigurationException
+ {
+ Configuration[] assigns = configuration.getChildren("assign");
+
+ pattern = new RE[assigns.length];
+ workflow = new String[assigns.length];
+ store = new String[assigns.length];
+
+ RECompiler compiler = new RECompiler();
+
+ for (int i = 0; i<assigns.length; i++)
+ {
+ try
+ {
+ pattern[i] = new RE(compiler.compile(createRegex(assigns[i].getAttribute("pattern"))));
+ }
+ catch (RESyntaxException rese)
+ {
+ throw new ConfigurationException("Could not create regular expression of the pattern",
+ rese);
+ }
+ workflow[i] = assigns[i].getAttribute("workflow");
+ store[i] = assigns[i].getAttribute("store");
+ }
+ }
+
+ /**
+ *
+ *
+ * @param resource
+ *
+ * @return
+ */
public String getWorkFlow(String resource)
{
+ for (int i = 0; i<pattern.length; i++)
+ if (pattern[i].match(resource))
+ return workflow[i];
return null;
}
+ /**
+ *
+ *
+ * @param resource
+ *
+ * @return
+ */
public String getWorkFlowStore(String resource)
{
+ for (int i = 0; i<pattern.length; i++)
+ if (pattern[i].match(resource))
+ return store[i];
return null;
}
+
+ /**
+ *
+ *
+ * @param pattern
+ *
+ * @return
+ */
+ private String createRegex(String pattern)
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append("^");
+ for (int i = 0; i<pattern.length(); i++)
+ {
+ if (pattern.charAt(i)=='*')
+ {
+ if ((i+1<pattern.length()) && (pattern.charAt(i+1)=='*'))
+ {
+ buffer.append("[^/]*(/[^/]*)+");
+ i++;
+ }
+ else
+ buffer.append("[^/]*");
+ }
+ else
+ buffer.append(pattern.charAt(i));
+ }
+ buffer.append("$");
+
+ System.out.println("pattern: '"+pattern+"' regex: '"+buffer.toString()+
+ "'");
+ return buffer.toString();
+ }
}
+ /*
+ The Krysalis Patchy Software License, Version 1.1_01
+ Copyright (c) 2002 Nicola Ken Barozzi. All rights reserved.
+
+ This Licence is compatible with the BSD licence as described and
+ approved by http://www.opensource.org/, and is based on the
+ Apache Software Licence Version 1.1.
+
+ 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 acknowledgment:
+ "This product includes software developed for project
+ Krysalis (http://www.krysalis.org/)."
+ Alternately, this acknowledgment may appear in the software itself,
+ if and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Krysalis" and "Nicola Ken Barozzi" and
+ "Krysalis Metamorphosis" must not be used to endorse or promote products
+ derived from this software without prior written permission. For
+ written permission, please contact [email protected].
+
+ 5. Products derived from this software may not be called "Krysalis",
+ "Krysalis Metamorphosis", nor may "Krysalis" appear in their name,
+ without prior written permission of Nicola Ken Barozzi.
+
+ 6. This software may contain voluntary contributions made by many
+ individuals, who decided to donate the code to this project in
+ respect of this licence.
+
+ 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 KRYSALIS PROJECT 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.
+ ====================================================================*/
Index: workflow.roles
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-sandbox/workflow/src/java/org/krysalis/workflow/manager/workflow.roles,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** workflow.roles 14 Mar 2003 09:17:27 -0000 1.1
--- workflow.roles 14 Mar 2003 15:06:09 -0000 1.2
***************
*** 48,57 ****
shorthand="workflows"
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
! <hint shorthand="workflow" class="org.krysalis.workflow.impl.SimpleWorkFlow"/>
</role>
<role name="org.krysalis.workflow.WorkFlowMapper"
shorthand="map"
! default-class="org.krysalis.workflow.impl.WorkFlowMapper"/>
</role-list>
--- 48,57 ----
shorthand="workflows"
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
! <hint shorthand="workflow" class="org.krysalis.workflow.manager.DefaultWorkFlow"/>
</role>
<role name="org.krysalis.workflow.WorkFlowMapper"
shorthand="map"
! default-class="org.krysalis.workflow.manager.DefaultWorkFlowMapper"/>
</role-list>
-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open!
Get cracking and register here for some mind boggling fun and
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.