lenya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andr...@apache.org
Subject cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/workflow/impl WorkflowInstanceImpl.java
Date Wed, 28 May 2003 15:42:54 GMT
andreas     2003/05/28 08:42:54

  Modified:    src/java/org/apache/lenya/cms/workflow/impl
                        WorkflowInstanceImpl.java
  Log:
  decoupled workflow from publication
  added assertion for setCurrentState(State)
  
  Revision  Changes    Path
  1.3       +29 -35    cocoon-lenya/src/java/org/apache/lenya/cms/workflow/impl/WorkflowInstanceImpl.java
  
  Index: WorkflowInstanceImpl.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/workflow/impl/WorkflowInstanceImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WorkflowInstanceImpl.java	24 Apr 2003 13:53:00 -0000	1.2
  +++ WorkflowInstanceImpl.java	28 May 2003 15:42:54 -0000	1.3
  @@ -8,8 +8,6 @@
   
   import java.util.HashSet;
   import java.util.Set;
  -import org.apache.lenya.cms.ac.User;
  -import org.apache.lenya.cms.publication.Document;
   import org.apache.lenya.cms.workflow.Event;
   import org.apache.lenya.cms.workflow.Situation;
   import org.apache.lenya.cms.workflow.State;
  @@ -21,76 +19,72 @@
    *
    * @author  andreas
    */
  -public class WorkflowInstanceImpl
  -    implements WorkflowInstance {
  -    
  +public class WorkflowInstanceImpl implements WorkflowInstance {
  +
       /** Creates a new instance of WorkflowInstanceImpl */
  -    public WorkflowInstanceImpl(Document document) {
  -        assert document != null;
  -        this.document = document;
  +    public WorkflowInstanceImpl(Workflow workflow) {
  +        assert workflow != null;
  +        this.workflow = workflow;
           setCurrentState(getWorkflow().getInitialState());
       }
  -    
  -    private Document document;
  -    
  -    /** Returns the document of this WorkflowInstance.
  -     *
  +
  +    private Workflow workflow;
  +
  +    /**
  +     * @return
        */
  -    public Document getDocument() {
  -        return document;
  -    }    
  -    
       public Workflow getWorkflow() {
  -        return getDocument().getType().getWorkflow();
  +        return workflow;
       }
  -    
  +
       /** Returns the transitions that can fire for this user.
        *
        */
  -    public Transition[] getExecutableTransitions(User user) {
  -        Situation situation = new SituationImpl(getDocument(), user);
  -        Transition transitions[] = getWorkflow().getLeavingTransitions(getCurrentState());
  +    public Transition[] getExecutableTransitions(Situation situation) {
  +        Transition transitions[] =
  +            getWorkflow().getLeavingTransitions(getCurrentState());
           Set executableTransitions = new HashSet();
  -        
  +
           for (int i = 0; i < transitions.length; i++) {
               if (transitions[i].canFire(situation)) {
                   executableTransitions.add(transitions[i]);
               }
           }
  -        return (Transition[])
  -            executableTransitions.toArray(new Transition[executableTransitions.size()]);
  -    }    
  -    
  +        return (Transition[]) executableTransitions.toArray(
  +            new Transition[executableTransitions.size()]);
  +    }
  +
       /** Indicates that the user invoked an event.
        * @param user The user who invoked the event.
        * @param event The event that was invoked.
        *
        */
  -    public void invoke(User user, Event event) {
  -        Transition transitions[] = getExecutableTransitions(user);
  +    public void invoke(Situation situation, Event event) {
  +        Transition transitions[] = getExecutableTransitions(situation);
           for (int i = 0; i < transitions.length; i++) {
               if (transitions[i].getEvent().equals(event)) {
                   fire((TransitionImpl) transitions[i]);
               }
           }
       }
  -    
  +
       protected void fire(TransitionImpl transition) {
           setCurrentState(transition.getDestination());
       }
  -    
  +
       private State currentState;
  -    
  +
       public void setCurrentState(State state) {
  -        assert state != null;
  +        assert state != null
  +            && ((WorkflowImpl) getWorkflow()).containsState(state);
           this.currentState = state;
       }
  -    
  +
       /** Returns the current state of this WorkflowInstance.
        *
        */
       public State getCurrentState() {
           return currentState;
       }
  -    
  +
   }
  
  
  

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


Mime
View raw message