You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/03/10 11:26:51 UTC

svn commit: r156931 [2/2] - in lenya/trunk/src/java/org/apache/lenya: cms/ac/workflow/ cms/ant/ cms/cocoon/acting/ cms/cocoon/components/modules/input/ cms/cocoon/flow/ cms/cocoon/transformation/ cms/publication/ cms/publication/task/ cms/site/usecases/ cms/task/ cms/workflow/ cms/workflow/usecases/ workflow/ workflow/impl/

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/WorkflowResolverImpl.java Thu Mar 10 02:26:24 2005
@@ -19,7 +19,6 @@
 import java.io.File;
 import java.util.Map;
 
-import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
@@ -31,44 +30,65 @@
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.Session;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
 import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.Identity;
 import org.apache.lenya.ac.Machine;
 import org.apache.lenya.ac.Role;
 import org.apache.lenya.ac.User;
 import org.apache.lenya.ac.impl.PolicyAuthorizer;
+import org.apache.lenya.cms.publication.DefaultDocument;
 import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentException;
 import org.apache.lenya.cms.publication.DocumentType;
-import org.apache.lenya.cms.publication.DocumentTypeBuildException;
 import org.apache.lenya.cms.publication.DocumentTypeResolver;
 import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
 import org.apache.lenya.cms.publication.PublicationFactory;
-import org.apache.lenya.cms.publication.util.LanguageVersions;
 import org.apache.lenya.workflow.Situation;
-import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
+import org.apache.lenya.workflow.Workflow;
 import org.apache.lenya.workflow.WorkflowException;
-import org.apache.lenya.workflow.WorkflowInstance;
-import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstancesImpl;
 import org.apache.lenya.workflow.impl.WorkflowBuilder;
 import org.apache.lenya.workflow.impl.WorkflowImpl;
 
 /**
  * Default implementation of the workflow resolver component.
  * 
- * @version $Id:$
+ * @version $Id$
  */
 public class WorkflowResolverImpl extends AbstractLogEnabled implements WorkflowResolver,
         Contextualizable, Serviceable {
 
     /**
-     * @see org.apache.lenya.cms.workflow.WorkflowResolver#getWorkflowInstance(org.apache.lenya.cms.publication.Document)
+     * @see org.apache.lenya.cms.workflow.WorkflowResolver#getWorkflowSchema(org.apache.lenya.cms.publication.Document)
      */
-    public WorkflowInstance getWorkflowInstance(Document document) throws WorkflowException {
-        WorkflowInstance instance = new WorkflowDocument(buildWorkflow(document), document);
-        ContainerUtil.enableLogging(instance, getLogger());
-        return instance;
+    public Workflow getWorkflowSchema(Document document) throws WorkflowException {
+        DocumentTypeResolver doctypeResolver = null;
+        WorkflowImpl workflow = null;
+
+        try {
+            doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
+            DocumentType doctype = doctypeResolver.resolve(document);
+
+            if (doctype.hasWorkflow()) {
+                String workflowFileName = doctype.getWorkflowFileName();
+
+                PublicationFactory factory = PublicationFactory.getInstance(getLogger());
+                Publication publication = factory.getPublication(this.objectModel);
+
+                File workflowDirectory = new File(publication.getDirectory(), WORKFLOW_DIRECTORY);
+                File workflowFile = new File(workflowDirectory, workflowFileName);
+                WorkflowBuilder builder = new WorkflowBuilder(getLogger());
+                workflow = builder.buildWorkflow(workflowFileName, workflowFile);
+            }
+        } catch (final Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (doctypeResolver != null) {
+                this.manager.release(doctypeResolver);
+            }
+        }
+
+        return workflow;
     }
 
     /**
@@ -123,59 +143,40 @@
      * @see org.apache.lenya.cms.workflow.WorkflowResolver#hasWorkflow(org.apache.lenya.cms.publication.Document)
      */
     public boolean hasWorkflow(Document document) {
-        try {
-            return getWorkflowInstance(document).getHistory().isInitialized();
-        } catch (WorkflowException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    protected static final String WORKFLOW_DIRECTORY = "config/workflow".replace('/',
-            File.separatorChar);
-
-    /**
-     * Builds a workflow for a given document.
-     * @param document The document.
-     * @return A workflow object or <code>null</code> if there is no workflow
-     *         assigned to the document's document type.
-     */
-    protected WorkflowImpl buildWorkflow(Document document) {
-
+        SourceResolver resolver = null;
         DocumentTypeResolver doctypeResolver = null;
-        WorkflowImpl workflow = null;
-
+        Source source = null;
+        boolean hasWorkflow = false;
         try {
-            doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
-            DocumentType doctype = doctypeResolver.resolve(document);
-
-            if (doctype.hasWorkflow()) {
-                String workflowFileName = doctype.getWorkflowFileName();
-
-                PublicationFactory factory = PublicationFactory.getInstance(getLogger());
-                Publication publication = factory.getPublication(this.objectModel);
-
-                File workflowDirectory = new File(publication.getDirectory(), WORKFLOW_DIRECTORY);
-                File workflowFile = new File(workflowDirectory, workflowFileName);
-                WorkflowBuilder builder = new WorkflowBuilder(getLogger());
-                workflow = builder.buildWorkflow(workflowFileName, workflowFile);
+            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+            String uri = ((DefaultDocument) document).getHistorySourceURI();
+            source = resolver.resolveURI(uri);
+            if (source.exists()) {
+                hasWorkflow = true;
+            } else {
+                doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
+                DocumentType doctype = doctypeResolver.resolve(document);
+                hasWorkflow = doctype.hasWorkflow();
             }
-        } catch (final ServiceException e) {
-            throw new RuntimeException(e);
-        } catch (final DocumentTypeBuildException e) {
-            throw new RuntimeException(e);
-        } catch (final PublicationException e) {
-            throw new RuntimeException(e);
-        } catch (final WorkflowException e) {
+        } catch (final Exception e) {
             throw new RuntimeException(e);
         } finally {
+            if (resolver != null) {
+                if (source != null) {
+                    resolver.release(source);
+                }
+                this.manager.release(resolver);
+            }
             if (doctypeResolver != null) {
                 this.manager.release(doctypeResolver);
             }
         }
-
-        return workflow;
+        return hasWorkflow;
     }
 
+    protected static final String WORKFLOW_DIRECTORY = "config/workflow".replace('/',
+            File.separatorChar);
+
     private ServiceManager manager;
 
     /**
@@ -185,28 +186,4 @@
         this.manager = _manager;
     }
 
-    /**
-     * @see org.apache.lenya.cms.workflow.WorkflowResolver#getSynchronizedInstance(org.apache.lenya.cms.publication.Document)
-     */
-    public SynchronizedWorkflowInstances getSynchronizedInstance(Document document)
-            throws WorkflowException {
-        assert document != null;
-        LanguageVersions versions;
-        try {
-            versions = new LanguageVersions(document);
-        } catch (DocumentException e) {
-            throw new WorkflowException(e);
-        }
-
-        Document[] documents = versions.getDocuments();
-        WorkflowInstance[] instances = new WorkflowInstance[documents.length];
-        for (int i = 0; i < documents.length; i++) {
-            instances[i] = getWorkflowInstance(documents[i]);
-        }
-
-        SynchronizedWorkflowInstances set = new SynchronizedWorkflowInstancesImpl(instances,
-                getWorkflowInstance(document));
-        ContainerUtil.enableLogging(set, getLogger());
-        return set;
-    }
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/History.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/History.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/History.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/usecases/History.java Thu Mar 10 02:26:24 2005
@@ -17,10 +17,7 @@
 package org.apache.lenya.cms.workflow.usecases;
 
 import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.workflow.CMSHistory;
-import org.apache.lenya.cms.workflow.WorkflowResolver;
-import org.apache.lenya.workflow.WorkflowInstance;
-import org.apache.lenya.workflow.impl.Version;
+import org.apache.lenya.workflow.Version;
 
 /**
  * Display the workflow history tab in the site area
@@ -36,19 +33,7 @@
     protected void initParameters() {
         super.initParameters();
 
-        WorkflowResolver resolver = null;
-        try {
-            resolver = (WorkflowResolver) this.manager.lookup(WorkflowResolver.ROLE);
-            WorkflowInstance instance = resolver.getWorkflowInstance(getSourceDocument());
-            CMSHistory history = (CMSHistory) instance.getHistory();
-            Version[] versions = history.getVersions();
-            setParameter("versions", versions);
-        } catch (final Exception e) {
-            throw new RuntimeException(e);
-        } finally {
-            if (resolver != null) {
-                this.manager.release(resolver);
-            }
-        }
+        Version[] versions = getSourceDocument().getVersions();
+        setParameter("versions", versions);
     }
 }

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/Action.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/Action.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/Action.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/Action.java Thu Mar 10 02:26:24 2005
@@ -27,8 +27,8 @@
 	
     /**
      * Executes this action for a given workflow instance.
-     * @param instance the workflow instance
+     * @param resultingVersion The resulting version.
      * @throws WorkflowException if the execution failed
      */
-    void execute(WorkflowInstance instance) throws WorkflowException;
+    void execute(Version resultingVersion) throws WorkflowException;
 }

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/Condition.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/Condition.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/Condition.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/Condition.java Thu Mar 10 02:26:24 2005
@@ -32,12 +32,13 @@
 
     /**
      * Returns if the condition is complied in a certain situation.
+     * @param workflow The workflow to use.
      * @param situation The situation to check.
-     * @param instance The workflow instance to check the condition on.
+     * @param workflowable The workflowable to check the condition on.
      * @return if the condition is complied.
      * @throws WorkflowException when the expression could not be evaluated.
      */
-    boolean isComplied(Situation situation, WorkflowInstance instance) throws WorkflowException;
+    boolean isComplied(Workflow workflow, Situation situation, Workflowable workflowable) throws WorkflowException;
 
     /** Sets the expression for this condition.
      * @param expression The expression.

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/Transition.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/Transition.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/Transition.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/Transition.java Thu Mar 10 02:26:24 2005
@@ -44,23 +44,29 @@
      * Returns the event of this transition.
      * @return the event
      */
-    Event getEvent();
+    String getEvent();
+    
+    /**
+     * @return The source state.
+     */
+    String getSource();
+    
+    /**
+     * @return The destination state.
+     */
+    String getDestination();
 
     /**
      * Returns the actions of this transition.
      * @return the actions
      */
     Action[] getActions();
-
+    
     /**
-     * Returns if the transition can fire in a certain situation.
-     * @param situation the situation for which the query is requested.
-     * @param instance The workflow instance to invoke the transition on.
-     * @return true if the transition can fire in the given situation.
-     * @throws WorkflowException when an error occurs.
+     * @return The conditions.
      */
-    boolean canFire(Situation situation, WorkflowInstance instance) throws WorkflowException;
-    
+    Condition[] getConditions();
+
     /**
      * Returns if this transition is synchronized.
      * @return A boolean value.

Added: lenya/trunk/src/java/org/apache/lenya/workflow/Version.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/Version.java?view=auto&rev=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/Version.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/Version.java Thu Mar 10 02:26:24 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright  1999-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.lenya.workflow;
+
+/**
+ * A version of the workflow history.
+ * 
+ * @version $Id:$
+ */
+public interface Version {
+    
+    /**
+     * Returns the event.
+     * @return An event.
+     */
+    String getEvent();
+
+    /**
+     * Returns the state.
+     * @return A state.
+     */
+    String getState();
+    
+    /**
+     * Returns the value of a variable.
+     * @param variableName The variable name.
+     * @return A boolean value.
+     */
+    boolean getValue(String variableName);
+
+    /**
+     * Sets a variable value.
+     * @param variableName The variable name.
+     * @param value The value.
+     */
+    void setValue(String variableName, boolean value);
+    
+}
\ No newline at end of file

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/Workflow.java Thu Mar 10 02:26:24 2005
@@ -44,15 +44,16 @@
      * Returns the initial state of this workflow.
      * @return The initial state
      */
-    State getInitialState();
+    String getInitialState();
 
     /**
      * Returns the transitions that leave a state.
      * This method is used, e.g., to disable menu items.
      * @param state A state.
      * @return The transitions that leave the state.
+     * @throws WorkflowException if the state is not contained.
      */
-    Transition[] getLeavingTransitions(State state);
+    Transition[] getLeavingTransitions(String state) throws WorkflowException;
     
     /**
      * Returns the variable names.
@@ -64,4 +65,16 @@
      * @return The name of this workflow.
      */
     String getName();
+    
+    /**
+     * @param variableName The variable name.
+     * @return The initial value of the variable.
+     * @throws WorkflowException if the variable does not exist.
+     */
+    boolean getInitialValue(String variableName) throws WorkflowException;
+    
+    /**
+     * @return The events.
+     */
+    String[] getEvents();
 }

Added: lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowEngine.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowEngine.java?view=auto&rev=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowEngine.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/WorkflowEngine.java Thu Mar 10 02:26:24 2005
@@ -0,0 +1,49 @@
+/*
+ * Copyright  1999-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.lenya.workflow;
+
+/**
+ * Workflow engine.
+ * 
+ * @version $Id:$
+ */
+public interface WorkflowEngine {
+
+    /**
+     * Checks if an event can be invoked.
+     * @param workflowable The workflowable.
+     * @param workflow The workflow schema.
+     * @param situation The situation.
+     * @param event The event.
+     * @return A boolean value.
+     * @throws WorkflowException if an error occurs.
+     */
+    boolean canInvoke(Workflowable workflowable, Workflow workflow, Situation situation, String event)
+            throws WorkflowException;
+
+    /**
+     * Invokes an event.
+     * @param workflowable The workflowable.
+     * @param workflow The workflow.
+     * @param situation The situation.
+     * @param event The event.
+     * @throws WorkflowException if an error occurs.
+     */
+    void invoke(Workflowable workflowable, Workflow workflow, Situation situation, String event)
+            throws WorkflowException;
+
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/workflow/Workflowable.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/Workflowable.java?view=auto&rev=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/Workflowable.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/Workflowable.java Thu Mar 10 02:26:24 2005
@@ -0,0 +1,44 @@
+/*
+ * Copyright  1999-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.lenya.workflow;
+
+/**
+ * Interface for objects which can be workflowed.
+ *
+ * @version $Id:$
+ */
+public interface Workflowable {
+
+    /**
+     * @return The versions in chronological order.
+     */
+    Version[] getVersions();
+    
+    /**
+     * @return The latest version.
+     */
+    Version getLatestVersion();
+    
+    /**
+     * Adds a new version.
+     * @param workflow The workflow.
+     * @param version The version.
+     * @param situation The situation in which the version was added.
+     */
+    void newVersion(Workflow workflow, Version version, Situation situation);
+    
+}

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/ActionImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/ActionImpl.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/ActionImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/ActionImpl.java Thu Mar 10 02:26:24 2005
@@ -20,14 +20,11 @@
 package org.apache.lenya.workflow.impl;
 
 import org.apache.lenya.workflow.Action;
-import org.apache.lenya.workflow.WorkflowException;
-import org.apache.lenya.workflow.WorkflowInstance;
-
 
 /**
  * Basic action implementation.
  */
-public class ActionImpl implements Action {
+public abstract class ActionImpl implements Action {
     
     /**
      * Creates a new instance of ActionImpl.
@@ -54,10 +51,4 @@
         return getId();
     }
 
-    /**
-     * @see org.apache.lenya.workflow.Action#execute(org.apache.lenya.workflow.WorkflowInstance)
-     */
-    public void execute(WorkflowInstance instance) throws WorkflowException {
-        // do nothing
-    }
 }

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableAssignmentImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableAssignmentImpl.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableAssignmentImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableAssignmentImpl.java Thu Mar 10 02:26:24 2005
@@ -20,9 +20,8 @@
 package org.apache.lenya.workflow.impl;
 
 import org.apache.lenya.workflow.BooleanVariableAssignment;
+import org.apache.lenya.workflow.Version;
 import org.apache.lenya.workflow.WorkflowException;
-import org.apache.lenya.workflow.WorkflowInstance;
-
 
 /**
  * Implementation of a boolean variable assignment.
@@ -31,23 +30,22 @@
     
     /**
      * Ctor.
-     * @param _variable The variable.
-     * @param _value The value.
+     * @param name The variable name.
+     * @param value The value.
      */
-    protected BooleanVariableAssignmentImpl(BooleanVariableImpl _variable, boolean _value) {
-        this.variable = _variable;
-        this.value = _value;
+    protected BooleanVariableAssignmentImpl(String name, boolean value) {
+        this.variable = name;
+        this.value = value;
     }
 
-    private BooleanVariableImpl variable;
+    private String variable;
     private boolean value;
 
     /**
-     * @see org.apache.lenya.workflow.BooleanVariableAssignment#execute(org.apache.lenya.workflow.WorkflowInstance instance)
+     * @see org.apache.lenya.workflow.Action#execute(org.apache.lenya.workflow.Version)
      */
-    public void execute(WorkflowInstance instance) throws WorkflowException {
-        WorkflowInstanceImpl impl = (WorkflowInstanceImpl) instance;
-        impl.getVariableInstance(getVariable()).setValue(getValue());
+    public void execute(Version resultingVersion) throws WorkflowException {
+        resultingVersion.setValue(getVariable(), getValue());
     }
 
     /**
@@ -62,7 +60,7 @@
      * Returns the variable of this assignment.
      * @return A variable.
      */
-    public BooleanVariableImpl getVariable() {
+    public String getVariable() {
         return this.variable;
     }
 }

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/BooleanVariableCondition.java Thu Mar 10 02:26:24 2005
@@ -20,14 +20,16 @@
 package org.apache.lenya.workflow.impl;
 
 import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.Version;
+import org.apache.lenya.workflow.Workflow;
 import org.apache.lenya.workflow.WorkflowException;
-import org.apache.lenya.workflow.WorkflowInstance;
+import org.apache.lenya.workflow.Workflowable;
 
 /**
  * Implementation of a boolean variable condition.
  */
 public class BooleanVariableCondition extends AbstractCondition {
-    
+
     private String variableName;
     private boolean value;
 
@@ -54,13 +56,13 @@
         super.setExpression(expression);
         String[] sides = expression.split("=");
         if (sides.length != 2) {
-            throw new WorkflowException(
-                "The expression '" + expression + "' must be of the form 'name = [true|false]'");
+            throw new WorkflowException("The expression '" + expression
+                    + "' must be of the form 'name = [true|false]'");
         }
-        
+
         this.variableName = sides[0].trim();
         this.value = Boolean.valueOf(sides[1].trim()).booleanValue();
-        
+
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Expression:    [" + sides[1].trim() + "]");
             getLogger().debug("Setting value: [" + this.value + "]");
@@ -68,15 +70,25 @@
     }
 
     /**
-     * @see org.apache.lenya.workflow.Condition#isComplied(org.apache.lenya.workflow.Situation, org.apache.lenya.workflow.WorkflowInstance)
+     * @see org.apache.lenya.workflow.Condition#isComplied(org.apache.lenya.workflow.Workflow,
+     *      org.apache.lenya.workflow.Situation,
+     *      org.apache.lenya.workflow.Workflowable)
      */
-    public boolean isComplied(Situation situation, WorkflowInstance instance) throws WorkflowException {
+public boolean isComplied(Workflow workflow, Situation situation, Workflowable workflowable) throws WorkflowException {
+        Version latestVersion = workflowable.getLatestVersion();
+        boolean value = false;
+        if (latestVersion == null) {
+            value = workflow.getInitialValue(getVariableName());
+        }
+        else {
+            value = latestVersion.getValue(getVariableName());
+        }
+        
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Checking boolean variable condition");
             getLogger().debug("    Condition value: [" + getValue() + "]");
-            getLogger().debug("    Variable value:  [" + instance.getValue(getVariableName()) + "]");
+            getLogger().debug("    Variable value:  [" + value + "]");
         }
-        return instance.getValue(getVariableName()) == getValue();
+        return value == getValue();
     }
-
-}
+}
\ No newline at end of file

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java Thu Mar 10 02:26:24 2005
@@ -22,28 +22,22 @@
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.lenya.workflow.Action;
 import org.apache.lenya.workflow.Condition;
-import org.apache.lenya.workflow.Event;
-import org.apache.lenya.workflow.Situation;
 import org.apache.lenya.workflow.Transition;
-import org.apache.lenya.workflow.WorkflowException;
-import org.apache.lenya.workflow.WorkflowInstance;
 
 import java.util.ArrayList;
 import java.util.List;
 
-
 /**
  * Implementation of a transition.
  */
 public class TransitionImpl extends AbstractLogEnabled implements Transition {
-    
-    
+
     /**
      * Ctor.
      * @param sourceState The source state.
      * @param destinationState The destination state.
      */
-    protected TransitionImpl(StateImpl sourceState, StateImpl destinationState) {
+    protected TransitionImpl(String sourceState, String destinationState) {
         this.source = sourceState;
         this.destination = destinationState;
     }
@@ -70,8 +64,7 @@
     private List conditions = new ArrayList();
 
     /**
-     * Returns the conditions which are assigned to this transition.
-     * @return An array of conditions.
+     * @see org.apache.lenya.workflow.Transition#getConditions()
      */
     public Condition[] getConditions() {
         return (Condition[]) this.conditions.toArray(new Condition[this.conditions.size()]);
@@ -85,13 +78,13 @@
         this.conditions.add(condition);
     }
 
-    private Event event;
+    private String event;
 
     /**
      * Returns the event which invokes this transition.
      * @return An event.
      */
-    public Event getEvent() {
+    public String getEvent() {
         return this.event;
     }
 
@@ -99,59 +92,34 @@
      * Sets the event to invoke this transition.
      * @param anEvent An event.
      */
-    public void setEvent(Event anEvent) {
+    public void setEvent(String anEvent) {
         this.event = anEvent;
     }
 
-    private StateImpl source;
+    private String source;
 
     /**
-     * Returns the source state of this transition.
-     * @return A state.
+     * @see org.apache.lenya.workflow.Transition#getSource()
      */
-    public StateImpl getSource() {
+    public String getSource() {
         return this.source;
     }
 
-    private StateImpl destination;
+    private String destination;
 
     /**
-     * Returns the destination state of this transition.
-     * @return A state.
+     * @see org.apache.lenya.workflow.Transition#getDestination()
      */
-    public StateImpl getDestination() {
+    public String getDestination() {
         return this.destination;
     }
 
-    /** 
-     * Returns if the transition can fire in a certain situation.
-     * @param situation The situation.
-     * @param instance The workflow instance.
-     * @throws WorkflowException when an error occurs.
-     * @return A boolean value.
-     */
-    public boolean canFire(Situation situation, WorkflowInstance instance) throws WorkflowException {
-        Condition[] _conditions = getConditions();
-        boolean canFire = true;
-
-        int i = 0;
-        while (canFire && i < _conditions.length) {
-            canFire = canFire && _conditions[i].isComplied(situation, instance);
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Condition [" + _conditions[i] + "] returns [" + canFire + "]");
-            }
-            i++;
-        }
-
-        return canFire;
-    }
-
     /**
      * @see java.lang.Object#toString()
      */
     public String toString() {
         StringBuffer buf = new StringBuffer();
-        buf.append(getEvent().getName() + " [");
+        buf.append(getEvent() + " [");
         Condition[] _conditions = getConditions();
 
         for (int i = 0; i < _conditions.length; i++) {
@@ -197,4 +165,4 @@
         this.isSynchronized = _isSynchronized;
     }
 
-}
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/workflow/impl/VersionImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/VersionImpl.java?view=auto&rev=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/VersionImpl.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/VersionImpl.java Thu Mar 10 02:26:24 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright  1999-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.
+ *
+ */
+
+/* $Id: Version.java 152682 2005-02-08 18:13:39Z gregor $  */
+
+package org.apache.lenya.workflow.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lenya.workflow.Version;
+
+/**
+ * A version of the workflow history.
+ */
+public class VersionImpl implements Version {
+
+    private String event;
+    private String state;
+    private Map variableValues = new HashMap();
+    
+    /**
+     * @see org.apache.lenya.workflow.Version#getEvent()
+     */
+    public String getEvent() {
+        return this.event;
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.Version#getState()
+     */
+    public String getState() {
+        return this.state;
+    }
+
+    /**
+     * Ctor.
+     * @param _event The event that caused the version change.
+     * @param _state The destination state.
+     */
+    public VersionImpl(String _event, String _state) {
+        this.event = _event;
+        this.state = _state;
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.Version#getValue(java.lang.String)
+     */
+    public boolean getValue(String variableName) {
+        Boolean value = (Boolean) this.variableValues.get(variableName);
+        return value.booleanValue();
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.Version#setValue(java.lang.String, boolean)
+     */
+    public void setValue(String variableName, boolean value) {
+        this.variableValues.put(variableName, new Boolean(value));
+    }
+
+}

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java Thu Mar 10 02:26:24 2005
@@ -20,15 +20,11 @@
 package org.apache.lenya.workflow.impl;
 
 import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.logger.Logger;
-import org.apache.lenya.workflow.Action;
 import org.apache.lenya.workflow.Condition;
-import org.apache.lenya.workflow.Event;
 import org.apache.lenya.workflow.Workflow;
 import org.apache.lenya.workflow.WorkflowException;
 import org.apache.lenya.xml.DocumentHelper;
@@ -80,20 +76,14 @@
     protected WorkflowImpl buildWorkflow(String name, Document document) throws WorkflowException {
 
         Element root = document.getDocumentElement();
-        StateImpl initialState = null;
-
-        Map states = new HashMap();
-        Map events = new HashMap();
-        Map variables = new HashMap();
+        String initialState = null;
 
         // load states
         NodeList stateElements = root.getElementsByTagNameNS(Workflow.NAMESPACE, STATE_ELEMENT);
 
         for (int i = 0; i < stateElements.getLength(); i++) {
             Element element = (Element) stateElements.item(i);
-            StateImpl state = buildState(element);
-            String id = state.getId();
-            states.put(id, state);
+            String state = buildState(element);
 
             if (isInitialStateElement(element)) {
                 initialState = state;
@@ -109,7 +99,6 @@
         for (int i = 0; i < variableElements.getLength(); i++) {
             Element element = (Element) variableElements.item(i);
             BooleanVariableImpl variable = buildVariable(element);
-            variables.put(variable.getName(), variable);
             workflow.addVariable(variable);
         }
 
@@ -117,9 +106,7 @@
         NodeList eventElements = root.getElementsByTagNameNS(Workflow.NAMESPACE, EVENT_ELEMENT);
 
         for (int i = 0; i < eventElements.getLength(); i++) {
-            EventImpl event = buildEvent((Element) eventElements.item(i));
-            String id = event.getName();
-            events.put(id, event);
+            String event = buildEvent((Element) eventElements.item(i));
             workflow.addEvent(event);
         }
 
@@ -128,10 +115,7 @@
                 TRANSITION_ELEMENT);
 
         for (int i = 0; i < transitionElements.getLength(); i++) {
-            TransitionImpl transition = buildTransition((Element) transitionElements.item(i),
-                    states,
-                    events,
-                    variables);
+            TransitionImpl transition = buildTransition((Element) transitionElements.item(i));
             workflow.addTransition(transition);
         }
 
@@ -172,34 +156,24 @@
      * @param element An XML element.
      * @return A state.
      */
-    protected StateImpl buildState(Element element) {
-        String id = element.getAttribute(ID_ATTRIBUTE);
-        StateImpl state = new StateImpl(id);
-
-        return state;
+    protected String buildState(Element element) {
+        return element.getAttribute(ID_ATTRIBUTE);
     }
 
     /**
      * Builds a transition from an XML element.
      * @param element An XML element.
-     * @param states A map from state IDs to states.
-     * @param events A map from event IDs to events.
-     * @param variables A map from variable names to variables.
      * @return A transition.
      * @throws WorkflowException when something went wrong.
      */
-    protected TransitionImpl buildTransition(Element element, Map states, Map events, Map variables)
-            throws WorkflowException {
+    protected TransitionImpl buildTransition(Element element) throws WorkflowException {
 
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Building transition");
         }
 
-        String sourceId = element.getAttribute(SOURCE_ATTRIBUTE);
-        String destinationId = element.getAttribute(DESTINATION_ATTRIBUTE);
-
-        StateImpl source = (StateImpl) states.get(sourceId);
-        StateImpl destination = (StateImpl) states.get(destinationId);
+        String source = element.getAttribute(SOURCE_ATTRIBUTE);
+        String destination = element.getAttribute(DESTINATION_ATTRIBUTE);
 
         TransitionImpl transition = new TransitionImpl(source, destination);
         ContainerUtil.enableLogging(transition, getLogger());
@@ -207,8 +181,7 @@
         // set event
         Element eventElement = (Element) element.getElementsByTagNameNS(Workflow.NAMESPACE,
                 EVENT_ELEMENT).item(0);
-        String id = eventElement.getAttribute(ID_ATTRIBUTE);
-        Event event = (Event) events.get(id);
+        String event = eventElement.getAttribute(ID_ATTRIBUTE);
         transition.setEvent(event);
 
         if (getLogger().isDebugEnabled()) {
@@ -229,19 +202,20 @@
                 ASSIGNMENT_ELEMENT);
 
         for (int i = 0; i < assignmentElements.getLength(); i++) {
-            BooleanVariableAssignmentImpl action = buildAssignment(variables,
-                    (Element) assignmentElements.item(i));
+            BooleanVariableAssignmentImpl action = buildAssignment((Element) assignmentElements
+                    .item(i));
             transition.addAction(action);
         }
 
         // load actions
-        NodeList actionElements = element
-                .getElementsByTagNameNS(Workflow.NAMESPACE, ACTION_ELEMENT);
-
-        for (int i = 0; i < actionElements.getLength(); i++) {
-            Action action = buildAction((Element) actionElements.item(i));
-            transition.addAction(action);
-        }
+        /*
+         * NodeList actionElements = element
+         * .getElementsByTagNameNS(Workflow.NAMESPACE, ACTION_ELEMENT);
+         * 
+         * for (int i = 0; i < actionElements.getLength(); i++) { Action action =
+         * buildAction((Element) actionElements.item(i));
+         * transition.addAction(action); }
+         */
 
         // set synchronization
         if (element.hasAttribute(SYNCHRONIZED_ATTRIBUTE)) {
@@ -257,11 +231,8 @@
      * @param element An XML element.
      * @return An event.
      */
-    protected EventImpl buildEvent(Element element) {
-        String id = element.getAttribute(ID_ATTRIBUTE);
-        EventImpl event = new EventImpl(id);
-
-        return event;
+    protected String buildEvent(Element element) {
+        return element.getAttribute(ID_ATTRIBUTE);
     }
 
     private ConditionFactory conditionFactory = null;
@@ -284,18 +255,6 @@
     }
 
     /**
-     * Builds an action from an XML element.
-     * @param element An XML element.
-     * @return An action.
-     */
-    protected Action buildAction(Element element) {
-        String id = element.getAttribute(ID_ATTRIBUTE);
-        Action action = new ActionImpl(id);
-
-        return action;
-    }
-
-    /**
      * Builds a boolean variable from an XML element.
      * @param element An XML element.
      * @return A boolean variable.
@@ -309,20 +268,17 @@
 
     /**
      * Builds an assignment object from an XML element.
-     * @param variables A map from variable names to variables.
      * @param element An XML element.
      * @return An assignment object.
      * @throws WorkflowException when something went wrong.
      */
-    protected BooleanVariableAssignmentImpl buildAssignment(Map variables, Element element)
+    protected BooleanVariableAssignmentImpl buildAssignment(Element element)
             throws WorkflowException {
         String variableName = element.getAttribute(VARIABLE_ATTRIBUTE);
 
         String valueString = element.getAttribute(VALUE_ATTRIBUTE);
         boolean value = Boolean.valueOf(valueString).booleanValue();
 
-        BooleanVariableImpl variable = (BooleanVariableImpl) variables.get(variableName);
-
-        return new BooleanVariableAssignmentImpl(variable, value);
+        return new BooleanVariableAssignmentImpl(variableName, value);
     }
 }

Added: lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowEngineImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowEngineImpl.java?view=auto&rev=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowEngineImpl.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowEngineImpl.java Thu Mar 10 02:26:24 2005
@@ -0,0 +1,162 @@
+/*
+ * Copyright  1999-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.lenya.workflow.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.lenya.workflow.Action;
+import org.apache.lenya.workflow.Condition;
+import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.Transition;
+import org.apache.lenya.workflow.Version;
+import org.apache.lenya.workflow.Workflow;
+import org.apache.lenya.workflow.WorkflowEngine;
+import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.Workflowable;
+
+/**
+ * Workflow engine implementation.
+ * 
+ * @version $Id:$
+ */
+public class WorkflowEngineImpl implements WorkflowEngine {
+
+    /**
+     * @see org.apache.lenya.workflow.WorkflowEngine#canInvoke(org.apache.lenya.workflow.Workflowable,
+     *      org.apache.lenya.workflow.Workflow, Situation, java.lang.String)
+     */
+    public boolean canInvoke(Workflowable workflowable, Workflow workflow, Situation situation,
+            String event) throws WorkflowException {
+        List firingTransitions = getFiringTransitions(workflowable, workflow, situation, event);
+        return firingTransitions.size() == 1;
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.WorkflowEngine#invoke(org.apache.lenya.workflow.Workflowable,
+     *      org.apache.lenya.workflow.Workflow, Situation, java.lang.String)
+     */
+    public void invoke(Workflowable workflowable, Workflow workflow, Situation situation,
+            String event) throws WorkflowException {
+
+        Transition firingTransition = null;
+        List firingTransitions = getFiringTransitions(workflowable, workflow, situation, event);
+
+        if (firingTransitions.size() == 0) {
+            throw new WorkflowException("No transition can fire!");
+        } else if (firingTransitions.size() > 1) {
+            throw new WorkflowException("More than one transitions can fire!");
+        } else {
+            firingTransition = (Transition) firingTransitions.get(0);
+        }
+
+        String destination = firingTransition.getDestination();
+
+        Version newVersion = createNewVersion(workflowable, workflow, event, destination);
+
+        Action[] actions = firingTransition.getActions();
+        for (int i = 0; i < actions.length; i++) {
+            actions[i].execute(newVersion);
+        }
+
+        workflowable.newVersion(workflow, newVersion, situation);
+    }
+
+    /**
+     * Creates a new version.
+     * @param workflowable The workflowable.
+     * @param workflow The workflow.
+     * @param event The event.
+     * @param destination The destination.
+     * @return A version.
+     * @throws WorkflowException if an error occurs.
+     */
+    protected Version createNewVersion(Workflowable workflowable, Workflow workflow, String event,
+            String destination) throws WorkflowException {
+        Version latestVersion = workflowable.getLatestVersion();
+        Version newVersion = new VersionImpl(event, destination);
+        String[] variableNames = workflow.getVariableNames();
+        for (int i = 0; i < variableNames.length; i++) {
+            String name = variableNames[i];
+            boolean value;
+            if (latestVersion == null) {
+                value = workflow.getInitialValue(name);
+            } else {
+                value = latestVersion.getValue(name);
+            }
+            newVersion.setValue(name, value);
+        }
+        return newVersion;
+    }
+
+    /**
+     * Returns the transitions that would fire in a certain situation.
+     * @param workflowable The workflowable.
+     * @param workflow The workflow.
+     * @param situation The situation.
+     * @param event The event.
+     * @return A list of transitions.
+     * @throws WorkflowException if an error occurs.
+     */
+    protected List getFiringTransitions(Workflowable workflowable, Workflow workflow,
+            Situation situation, String event) throws WorkflowException {
+        Version lastVersion = workflowable.getLatestVersion();
+        
+        String currentState;
+        if (lastVersion == null) {
+            currentState = workflow.getInitialState();
+        }
+        else {
+            currentState = lastVersion.getState();
+        }
+        
+        Transition[] transitions = workflow.getLeavingTransitions(currentState);
+        List firingTransitions = new ArrayList();
+
+        for (int i = 0; i < transitions.length; i++) {
+            if (transitions[i].getEvent().equals(event)
+                    && canFire(transitions[i], workflow, situation, workflowable)) {
+                firingTransitions.add(transitions[i]);
+            }
+        }
+        return firingTransitions;
+    }
+
+    /**
+     * Checks if a transition can fire.
+     * @param transition The transition.
+     * @param workflow The workflow.
+     * @param situation The situation.
+     * @param workflowable The workflowable.
+     * @return A boolean value.
+     * @throws WorkflowException if an error occurs.
+     */
+    public boolean canFire(Transition transition, Workflow workflow, Situation situation,
+            Workflowable workflowable) throws WorkflowException {
+        Condition[] _conditions = transition.getConditions();
+        boolean canFire = true;
+
+        int i = 0;
+        while (canFire && i < _conditions.length) {
+            canFire = canFire && _conditions[i].isComplied(workflow, situation, workflowable);
+            i++;
+        }
+
+        return canFire;
+    }
+
+}
\ No newline at end of file

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java?view=diff&r1=156930&r2=156931
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java Thu Mar 10 02:26:24 2005
@@ -24,7 +24,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.lenya.workflow.State;
 import org.apache.lenya.workflow.Transition;
 import org.apache.lenya.workflow.Workflow;
 import org.apache.lenya.workflow.WorkflowException;
@@ -39,13 +38,13 @@
      * @param _name The name.
      * @param _initialState the initial state of the workflow.
      */
-    protected WorkflowImpl(String _name, StateImpl _initialState) {
+    protected WorkflowImpl(String _name, String _initialState) {
         this.initialState = _initialState;
         this.name = _name;
         addState(_initialState);
     }
 
-    private State initialState;
+    private String initialState;
     private String name;
 
     /**
@@ -53,19 +52,19 @@
      * @return The initial state.
      *  
      */
-    public State getInitialState() {
+    public String getInitialState() {
         return this.initialState;
     }
 
     private Set transitions = new HashSet();
-    private Map states = new HashMap();
+    private Set states = new HashSet();
 
     /**
      * Adds a state.
      * @param state A state.
      */
-    private void addState(StateImpl state) {
-        this.states.put(state.getId(), state);
+    private void addState(String state) {
+        this.states.add(state);
     }
 
     /**
@@ -87,27 +86,13 @@
     }
 
     /**
-     * Returns the destination state of a transition.
-     * @param transition A transition.
-     * @return The destination state.
-     *  
-     */
-    protected State getDestination(Transition transition) {
-        return ((TransitionImpl) transition).getDestination();
-    }
-
-    /**
-     * Returns the transitions that leave a state.
-     * @param state A state.
-     * @return The transitions that leave the state.
-     *  
+     * @see org.apache.lenya.workflow.Workflow#getLeavingTransitions(java.lang.String)
      */
-    public Transition[] getLeavingTransitions(State state) {
+    public Transition[] getLeavingTransitions(String state) throws WorkflowException {
         Set leavingTransitions = new HashSet();
         TransitionImpl[] _transitions = getTransitions();
-
         for (int i = 0; i < _transitions.length; i++) {
-            if (_transitions[i].getSource() == state) {
+            if (_transitions[i].getSource().equals(state)) {
                 leavingTransitions.add(_transitions[i]);
             }
         }
@@ -121,54 +106,26 @@
      * @return <code>true</code> if the state is contained, <code>false</code>
      *         otherwise.
      */
-    protected boolean containsState(State state) {
-        return this.states.containsValue(state);
+    protected boolean containsState(String state) {
+        return this.states.contains(state);
     }
 
     /**
      * Returns the states.
      * @return An array of states.
      */
-    protected StateImpl[] getStates() {
-        return (StateImpl[]) this.states.values().toArray(new StateImpl[this.states.size()]);
+    protected String[] getStates() {
+        return (String[]) this.states.toArray(new String[this.states.size()]);
     }
 
-    /**
-     * Returns the state with a certain name.
-     * @param _name The state name.
-     * @return A state.
-     * @throws WorkflowException when the state does not exist.
-     */
-    protected StateImpl getState(String _name) throws WorkflowException {
-        if (!this.states.containsKey(_name)) {
-            throw new WorkflowException("Workflow does not contain the state '" + _name + "'!");
-        }
-
-        return (StateImpl) this.states.get(_name);
-    }
-
-    private Map events = new HashMap();
+    private Set events = new HashSet();
 
     /**
      * Adds an event.
      * @param event An event.
      */
-    protected void addEvent(EventImpl event) {
-        this.events.put(event.getName(), event);
-    }
-
-    /**
-     * Returns the event for a certain event name.
-     * @param _name A string.
-     * @return The event with this name.
-     * @throws WorkflowException when no event with the given name exists.
-     */
-    public EventImpl getEvent(String _name) throws WorkflowException {
-        if (!this.events.containsKey(_name)) {
-            throw new WorkflowException("Workflow does not contain the event '" + _name + "'!");
-        }
-
-        return (EventImpl) this.events.get(_name);
+    protected void addEvent(String event) {
+        this.events.add(event);
     }
 
     private Map variables = new HashMap();
@@ -221,5 +178,25 @@
      */
     public String getName() {
         return this.name;
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.Workflow#getInitialValue(java.lang.String)
+     */
+    public boolean getInitialValue(String variableName) throws WorkflowException {
+        BooleanVariableImpl[] variables = getVariables();
+        for (int i = 0; i < variables.length; i++) {
+            if (variables[i].getName().equals(variableName)) {
+                return variables[i].getInitialValue();
+            }
+        }
+        throw new WorkflowException("The variable [" + variableName + "] does not exist.");
+    }
+
+    /**
+     * @see org.apache.lenya.workflow.Workflow#getEvents()
+     */
+    public String[] getEvents() {
+        return (String[]) this.events.toArray(new String[this.events.size()]);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org