Update of /cvsroot/metamorphosis/krysalis-sandbox/workflow/src/java/org/krysalis/workflow/impl
In directory sc8-pr-cvs1:/tmp/cvs-serv19495/src/java/org/krysalis/workflow/impl
Added Files:
DefaultWorkFlowState.java SimpleWorkFlow.java
Removed Files:
AbstractState.java DFA.java DefaultState.java
DefaultWorkFlowManager.java IntegerSet.java
MemoryStateStore.java NFA.java
Log Message:
Made class names more consistent.
Installed ant build system.
Using the proposal of the Lenya project for the first
implementation.
--- NEW FILE: DefaultWorkFlowState.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Patchy *
* Software License version 1.1_01, a copy of which has been included *
* at the bottom of this file. *
*****************************************************************************/
package org.krysalis.workflow.impl;
/**
* Reference implementation of a state.
*
* @author <a href="mailto:[email protected]">Stephan Michels</a>
*/
public class DefaultWorkFlowState implements WorkFlowState {
private String resource;
private String state;
private HashMap attributes;
public void DefaultWorkFlowState(String resource, String state)
{
this.resource = resource;
this.state = state;
}
public String getResource()
{
return resource;
}
public void setState(String state)
{
this.state = state;
}
public String getState()
{
return state;
}
public void setAttribute(String name, Object value)
{
attributes.put(name, value);
}
public Object getAttribute(String name)
{
return attrbutes.get(name);
}
public Map getAttributes()
{
return attributes;
}
}
/*
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.
====================================================================*/
--- NEW FILE: SimpleWorkFlow.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Patchy *
* Software License version 1.1_01, a copy of which has been included *
* at the bottom of this file. *
*****************************************************************************/
package org.krysalis.workflow.impl;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.krysalis.workflow.*;
/**
* Implementation of a determinitic automate.
*/
public class SimpleWorkFlow 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);
}
}
/*
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.
====================================================================*/
--- AbstractState.java DELETED ---
--- DFA.java DELETED ---
--- DefaultState.java DELETED ---
--- DefaultWorkFlowManager.java DELETED ---
--- IntegerSet.java DELETED ---
--- MemoryStateStore.java DELETED ---
--- NFA.java DELETED ---
-------------------------------------------------------
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.