directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nik...@apache.org
Subject svn commit: r472911 [1/2] - in /directory/sandbox/niklas/mina-sm: ./ src/main/java/org/apache/mina/sm/ src/main/java/org/apache/mina/sm/annotation/ src/main/java/org/apache/mina/sm/context/ src/main/java/org/apache/mina/sm/event/ src/main/java/org/apac...
Date Thu, 09 Nov 2006 14:25:38 GMT
Author: niklas
Date: Thu Nov  9 06:25:36 2006
New Revision: 472911

URL: http://svn.apache.org/viewvc?view=rev&rev=472911
Log: (empty)

Added:
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndContinueException.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndGotoException.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/NoSuchStateException.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateControl.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachine.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineCreationException.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineFactory.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handler.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handlers.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/State.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/DefaultEventFactory.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/DefaultEventFactory.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/Event.java   (contents, props changed)
      - copied, changed from r466971, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/Event.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventArgumentsInterceptor.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventArgumentsInterceptor.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventFactory.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventFactory.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/UnhandledEventException.java   (contents, props changed)
      - copied, changed from r466971, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/UnhandledEventException.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/mina/Events.java   (with props)
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AbstractTransition.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AbstractTransition.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AmbiguousMethodException.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AmbiguousMethodException.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodInvocationException.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodInvocationException.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodTransition.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodTransition.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoSuchMethodException.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoSuchMethodException.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoopTransition.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoopTransition.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/Transition.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/Transition.java
    directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/StateMachineFactoryTest.java   (with props)
    directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/StateMachineTest.java   (with props)
    directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/StateTest.java   (with props)
    directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/transition/
    directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/transition/MethodTransitionTest.java   (contents, props changed)
      - copied, changed from r466955, directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/finite/MethodTransitionTest.java
Removed:
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/AbstractState.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/DefaultEventFactory.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/Event.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventArgumentsInterceptor.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventFactory.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/UnhandledEventException.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AbstractTransition.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AmbiguousMethodException.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/FsmState.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodInvocationException.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodTransition.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoSuchMethodException.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoopTransition.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/Transition.java
    directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/AbstractStateTest.java
    directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/finite/FsmStateTest.java
    directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/finite/MethodTransitionTest.java
Modified:
    directory/sandbox/niklas/mina-sm/pom.xml
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/State.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineProxyFactory.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/AbstractStateContext.java
    directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/StateContext.java
    directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/StateMachineProxyFactoryTest.java

Modified: directory/sandbox/niklas/mina-sm/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/pom.xml?view=diff&rev=472911&r1=472910&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/pom.xml (original)
+++ directory/sandbox/niklas/mina-sm/pom.xml Thu Nov  9 06:25:36 2006
@@ -9,6 +9,7 @@
   </parent>
   <artifactId>mina-sm</artifactId>
   <name>Apache MINA State Machine Module</name>
+  <version>0.0.1-SNAPSHOT</version>
   <inceptionYear>2006</inceptionYear>
 
   <url>http://directory.apache.org/projects/mina/</url>
@@ -18,7 +19,7 @@
     <dependency>
       <groupId>org.apache.mina</groupId>
       <artifactId>mina-core</artifactId>
-      <version>${pom.version}</version>
+      <version>1.0.0</version>
     </dependency>
 
     <dependency>
@@ -49,8 +50,8 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <source>1.4</source>
-          <target>1.4</target>
+          <source>1.5</source>
+          <target>1.5</target>
           <debug>true</debug>
           <optimize>true</optimize>
           <showDeprecations>true</showDeprecations>

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndContinueException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndContinueException.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndContinueException.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndContinueException.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,29 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm;
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class BreakAndContinueException extends RuntimeException
+{
+    
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndContinueException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndGotoException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndGotoException.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndGotoException.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndGotoException.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,52 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm;
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class BreakAndGotoException extends RuntimeException
+{
+    private final String stateId;
+    private final boolean now;
+
+    public BreakAndGotoException( String stateId, boolean now )
+    {
+        if( stateId == null )
+        {
+            throw new NullPointerException( "stateId" );
+        }
+        this.stateId = stateId;
+        this.now = now;
+    }
+
+    public boolean isNow()
+    {
+        return now;
+    }
+
+    public String getStateId()
+    {
+        return stateId;
+    }
+    
+    
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/BreakAndGotoException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/NoSuchStateException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/NoSuchStateException.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/NoSuchStateException.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/NoSuchStateException.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,34 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm;
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class NoSuchStateException extends RuntimeException
+{
+
+    public NoSuchStateException( String stateId )
+    {
+        super( stateId );
+    }
+    
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/NoSuchStateException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/State.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/State.java?view=diff&rev=472911&r1=472910&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/State.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/State.java Thu Nov  9 06:25:36 2006
@@ -18,15 +18,90 @@
  */
 package org.apache.mina.sm;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.mina.sm.transition.Transition;
+
 /**
  * 
  *
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public interface State {
-    String getName();
-    void handle(Event event);
-    void enter(Event event);
-    void exit(Event event);
+public class State {
+    private final String id;
+    private final State parent;
+    private ArrayList<TransitionHolder> transitionHolders = 
+        new ArrayList<TransitionHolder>();
+    private List<Transition> transitions = Collections.emptyList();
+    
+    public State( String id )
+    {
+        this( id, null );
+    }
+
+    public State( String id, State parent )
+    {
+        this.id = id;
+        this.parent = parent;
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public State getParent()
+    {
+        return parent;
+    }
+
+    public List<Transition> getTransitions()
+    {
+        return Collections.unmodifiableList( transitions );
+    }
+
+    private void updateTransitions() {
+        transitions = new ArrayList<Transition>(transitionHolders.size());
+        for( TransitionHolder holder: transitionHolders )
+        {
+            transitions.add( holder.transition );
+        }        
+    }
+    
+    public State addTransition(Transition transition) {
+        return addTransition(transition, 0);
+    }
+    
+    public State addTransition( Transition transition, int weight )
+    {
+        if( transition == null )
+        {
+            throw new NullPointerException( "transition" );
+        }
+        
+        transitionHolders.add( new TransitionHolder( transition, weight ) );
+        Collections.sort( transitionHolders );
+        updateTransitions();
+        return this;
+    }
+    
+    private static class TransitionHolder implements Comparable<TransitionHolder>
+    {
+        Transition transition;
+        int weight;
+
+        TransitionHolder( Transition transition, int weight )
+        {
+            this.transition = transition;
+            this.weight = weight;
+        }
+
+        public int compareTo( TransitionHolder o )
+        {
+            return (weight > o.weight) ? 1 : (weight < o.weight ? -1 : 0);
+        }
+    }
 }

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateControl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateControl.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateControl.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateControl.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,44 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm;
+
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class StateControl
+{
+
+    public static void breakAndContinue()
+    {
+        throw new BreakAndContinueException();
+    }
+    
+    public static void breakAndGotoNow( String state )
+    {
+        throw new BreakAndGotoException( state, true );
+    }
+    
+    public static void breakAndGotoNext( String state )
+    {
+        throw new BreakAndGotoException( state, false );
+    }
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateControl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachine.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachine.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachine.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,238 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.apache.mina.sm.context.StateContext;
+import org.apache.mina.sm.event.Event;
+import org.apache.mina.sm.event.UnhandledEventException;
+import org.apache.mina.sm.transition.Transition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class StateMachine
+{
+    private static final Logger log = LoggerFactory.getLogger( StateMachine.class );
+
+    private final State startState;
+    private final Map<String, State> states;
+    
+    private final ThreadLocal<Boolean> processingThreadLocal = new ThreadLocal<Boolean>()
+    {
+        protected Boolean initialValue()
+        {
+            return Boolean.FALSE;
+        }
+    };
+
+    private final ThreadLocal<LinkedList<Event>> eventQueueThreadLocal = new ThreadLocal<LinkedList<Event>>()
+    {
+        protected LinkedList<Event> initialValue()
+        {
+            return new LinkedList<Event>();
+        }
+    };
+    
+    public StateMachine( State[] states, String startStateId )
+    {
+        this.states = new HashMap<String, State>();
+        for( State s: states )
+        {
+            this.states.put( s.getId(), s );
+        }
+        this.startState = getState( startStateId );
+    }
+    
+    public StateMachine( Collection<State> states, String startStateId )
+    {
+        this( states.toArray( new State[0] ), startStateId );
+    }
+    
+    public State getState( String id )
+    {
+        State state = states.get( id );
+        if( state == null )
+        {
+            throw new NoSuchStateException( id );
+        }
+        return state;
+    }
+    
+    public Collection<State> getStates()
+    {
+        return Collections.unmodifiableCollection( states.values() );
+    }
+    
+    public void handle( Event event )
+    {
+        StateContext context = event.getContext();
+        
+        synchronized ( context )
+        {
+            LinkedList<Event> eventQueue = eventQueueThreadLocal.get();
+            eventQueue.addLast( event );
+            
+            if ( processingThreadLocal.get() )
+            {
+                /*
+                 * This thread is already processing an event. Queue this 
+                 * event.
+                 */
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "State machine called recursively. "
+                             + "Queuing event " + event 
+                             + " for later processing." );
+                }
+            }
+            else
+            {
+                processingThreadLocal.set( true );
+                try
+                {
+                    if ( context.getCurrentState() == null )
+                    {
+                        context.setCurrentState( startState );
+                    }
+                    processEvents( eventQueue );
+                }
+                finally
+                {
+                    processingThreadLocal.set( false );
+                }
+            }
+        }
+        
+    }
+
+    private void processEvents( LinkedList<Event> eventQueue )
+    {
+        while ( ! eventQueue.isEmpty() )
+        {
+            Event event = ( Event ) eventQueue.removeFirst();
+            StateContext context = event.getContext();
+            handle( context.getCurrentState(), event );
+        }
+    }
+    
+    private void handle( State state, Event event )
+    {
+        StateContext context = event.getContext();
+
+        for( Transition t: state.getTransitions() )
+        {
+            if( log.isDebugEnabled() )
+            {
+                log.debug( "Trying transition " + t );
+            }
+            
+            try
+            {
+                if( t.execute( event ) )
+                {
+                    if( log.isDebugEnabled() )
+                    {
+                        log.debug( "Transition " + t + " executed successfully.");
+                    }
+                    setCurrentState( context, t.getNextState() );
+
+                    return;                    
+                }
+            }
+            catch( BreakAndContinueException bace )
+            {
+                if( log.isDebugEnabled() )
+                {
+                    log.debug( "BreakAndContinueException thrown in "
+                            + "transition " + t 
+                            + ". Continuing with next transition." );
+                }
+            }
+            catch( BreakAndGotoException bage )
+            {
+                State newState = getState( bage.getStateId() );
+                
+                if( bage.isNow() )
+                {
+                    if( log.isDebugEnabled() )
+                    {
+                        log.debug( "BreakAndGotoException thrown in "
+                                + "transition " + t 
+                                + ". Moving to state " + newState.getId() 
+                                + " now." );
+                    }
+                    handle( newState, event );
+                }
+                else
+                {
+                    if( log.isDebugEnabled() )
+                    {
+                        log.debug( "BreakAndGotoException thrown in "
+                                + "transition " + t 
+                                + ". Moving to state " + newState.getId() 
+                                + " next." );
+                    }
+                    setCurrentState( context, newState );
+                }
+                return;
+            }
+        }
+
+        /*
+         * No transition could handle the event. Try with the parent state if
+         * there is one.
+         */ 
+        
+        if( state.getParent() != null )
+        {
+            handle( state.getParent(), event );
+        }
+        else
+        {
+            throw new UnhandledEventException( "Unhandled event: " + event );
+        }   
+    }
+
+    private void setCurrentState( StateContext context, State newState )
+    {
+        if( newState != null )
+        {
+            if( log.isDebugEnabled() )
+            {
+                if( newState != context.getCurrentState() )
+                {
+                    log.debug( "Leaving state " + context.getCurrentState().getId() );
+                    log.debug( "Entering state " + newState.getId() );
+                }
+            }
+            context.setCurrentState( newState );
+        }
+    }
+    
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachine.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineCreationException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineCreationException.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineCreationException.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineCreationException.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,62 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.sm;
+
+/**
+ * 
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class StateMachineCreationException extends RuntimeException {
+
+    /**
+     * 
+     */
+    public StateMachineCreationException() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param message
+     */
+    public StateMachineCreationException(String message) {
+        super(message);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public StateMachineCreationException(String message, Throwable cause) {
+        super(message, cause);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param cause
+     */
+    public StateMachineCreationException(Throwable cause) {
+        super(cause);
+        // TODO Auto-generated constructor stub
+    }
+
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineCreationException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineFactory.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineFactory.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineFactory.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,254 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.mina.sm.annotation.Handler;
+import org.apache.mina.sm.annotation.Handlers;
+import org.apache.mina.sm.transition.MethodTransition;
+import org.apache.mina.sm.transition.Transition;
+
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class StateMachineFactory
+{
+
+    public static StateMachine create( Object handler )
+    {
+        return create( handler.getClass(), handler );
+    }
+    
+    public static StateMachine create( String start, Object handler )
+    {
+        return create( start, handler.getClass(), handler );
+    }
+    
+    public static StateMachine create( Object handler, Object... handlers )
+    {
+        return create( "start", handler.getClass(), handler, handlers );
+    }
+    
+    public static StateMachine create( String start, Object handler, Object... handlers )
+    {
+        return create( start, handler.getClass(), handler, handlers );
+    }
+    
+    public static StateMachine create( Class clazz, Object handler, Object... handlers )
+    {
+        return create( "start", clazz, handler, handlers );
+    }
+    
+    public static StateMachine create( String start, Class clazz, Object handler, Object... handlers )
+    {
+        HashMap<String, State> states = new HashMap<String, State>();
+        for( State state: createStates( clazz ) )
+        {
+            states.put( state.getId(), state );
+        }
+        
+        if( !states.containsKey( start ) )
+        {
+            throw new StateMachineCreationException( "Start state '" + start + "' not found." );
+        }
+        
+        ArrayList<Object> handlersList = new ArrayList<Object>();
+        handlersList.add( handler );
+        handlersList.addAll( Arrays.asList( handlers ) );
+        setupTransitions( states, handlersList );
+        
+        return new StateMachine( states.values(), start );
+    }
+
+    private static void setupTransitions( Map<String, State> states, List<Object> handlers )
+    {
+        for( Object handler : handlers )
+        {
+            setupTransitions( states, handler );
+        }
+    }
+
+    private static void setupTransitions( Map<String, State> states, Object handler )
+    {
+        Method[] methods = handler.getClass().getDeclaredMethods();
+        Arrays.sort( methods, new Comparator<Method>()
+        {
+            public int compare( Method m1, Method m2 )
+            {
+                return m1.toString().compareTo( m2.toString() );
+            }
+        } );
+        
+        for( Method m : methods )
+        {
+            List<Handler> handlerAnnotations = new ArrayList<Handler>();
+            if( m.isAnnotationPresent( Handler.class ) )
+            {
+                handlerAnnotations.add( m.getAnnotation( Handler.class ) );
+            }
+            if( m.isAnnotationPresent( Handlers.class ) )
+            {
+                handlerAnnotations.addAll( Arrays.asList( m.getAnnotation( Handlers.class ).value() ) );
+            }
+            
+            if( handlerAnnotations.isEmpty() )
+            {
+                continue;
+            }
+            
+            for( Handler annotation : handlerAnnotations)
+            {
+                String[] eventIds = annotation.on();
+                if( eventIds.length == 0 )
+                {
+                    throw new StateMachineCreationException( "Error encountered "
+                            + "when processing method " + m 
+                            + ". No event ids specified." );
+                }
+                if( annotation.in().length == 0 )
+                {
+                    throw new StateMachineCreationException( "Error encountered "
+                            + "when processing method " + m 
+                            + ". No states specified." );
+                }
+                
+                State next = null;
+                if( !annotation.next().equals( Handler.SELF ) )
+                {
+                    next = states.get( annotation.next() );
+                    if( next == null )
+                    {
+                        throw new StateMachineCreationException( "Error encountered "
+                                + "when processing method " + m 
+                                + ". Unknown next state: " 
+                                + annotation.next() + "." );
+                    }
+                }
+                
+                for( String event : eventIds )
+                {
+                    for( String in : annotation.in() )
+                    {
+                        State state = states.get( in );
+                        if( state == null )
+                        {
+                            throw new StateMachineCreationException( "Error encountered "
+                                    + "when processing method " + m 
+                                    + ". Unknown state: " + in + "." );
+                        }
+                        
+                        Transition t = new MethodTransition( event, next, m, handler );
+                        state.addTransition( t, annotation.weight() );
+                    }
+                }
+            }
+        }
+    }
+
+    static State[] createStates( Class clazz )
+    {
+        LinkedList<Field> fields = new LinkedList<Field>();
+        
+        for( Field f : clazz.getDeclaredFields() )
+        {
+            if( !f.isAnnotationPresent( org.apache.mina.sm.annotation.State.class ) )
+            {
+                continue;
+            }
+            
+            if( ( f.getModifiers() & Modifier.STATIC ) == 0
+                    || ( f.getModifiers() & Modifier.FINAL ) == 0
+                    || !f.getType().equals( String.class ) )
+            {
+                throw new StateMachineCreationException( "Error encountered when "
+                        + "processing field " + f + ". Only static final "
+                        + "String fields can be used with the @State "
+                        + "annotation." );
+            }
+            
+            if( !f.isAccessible() )
+            {
+                f.setAccessible( true );
+            }
+            
+            fields.add( f );
+        }
+        
+        int maxIterations = fields.size();
+        LinkedHashMap<String, State> states = new LinkedHashMap<String, State>();
+        for( int i = 0; i < maxIterations && !fields.isEmpty(); i++ )
+        {
+            Field f = fields.removeFirst();
+            
+            String value = null;
+            try
+            {
+                value = ( String ) f.get( null );
+            }
+            catch( IllegalAccessException iae )
+            {
+                throw new StateMachineCreationException(
+                        "Error encountered when " + "processing field "
+                                + f + ".", iae );
+            }
+            
+            org.apache.mina.sm.annotation.State stateAnnotation = f.getAnnotation( org.apache.mina.sm.annotation.State.class );
+            if( stateAnnotation.value().equals( org.apache.mina.sm.annotation.State.ROOT ) )
+            {
+                states.put( value, new State( value ) );
+            }
+            else if( states.containsKey( stateAnnotation.value() ) )
+            {
+                states.put( value, new State( value, states.get( stateAnnotation.value() ) ) );
+            }
+            else
+            {
+                // Move to the back of the list of fields for later processing
+                fields.addLast( f );
+            }
+        }
+        
+        // The list of fields should be empty by now. If not it means that at
+        // least one field specifies a non-existent parent.
+        if( !fields.isEmpty() )
+        {
+            throw new StateMachineCreationException( "Error encountered while creating "
+                    + "FSM. The following fields specify non-existing "
+                    + "parent states: " + fields );
+        }
+        
+
+        return states.values().toArray( new State[ 0 ] );
+    }
+    
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineProxyFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineProxyFactory.java?view=diff&rev=472911&r1=472910&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineProxyFactory.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/StateMachineProxyFactory.java Thu Nov  9 06:25:36 2006
@@ -21,11 +21,14 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.LinkedList;
 
 import org.apache.mina.sm.context.SingletonStateContextLookup;
 import org.apache.mina.sm.context.StateContext;
 import org.apache.mina.sm.context.StateContextLookup;
+import org.apache.mina.sm.event.DefaultEventFactory;
+import org.apache.mina.sm.event.Event;
+import org.apache.mina.sm.event.EventArgumentsInterceptor;
+import org.apache.mina.sm.event.EventFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,74 +47,66 @@
     private StateMachineProxyFactory() {
     }
 
-    public static Object create(Class iface, State startState) {
-        return create(new Class[] {iface}, startState);
+    public static Object create(Class iface, StateMachine sm) {
+        return create(new Class[] {iface}, sm);
     }
     
-    public static Object create(Class iface, State startState, 
+    public static Object create(Class iface, StateMachine sm, 
                                 StateContextLookup contextLookup) {
-        return create(new Class[] {iface}, startState, contextLookup);
+        return create(new Class[] {iface}, sm, contextLookup);
     }
     
-    public static Object create(Class iface, State startState, 
+    public static Object create(Class iface, StateMachine sm, 
                                 StateContextLookup contextLookup,
                                 EventArgumentsInterceptor interceptor) {
-        return create( new Class[] {iface}, startState, contextLookup, interceptor, 
+        return create( new Class[] {iface}, sm, contextLookup, interceptor, 
                        new DefaultEventFactory() );
     }
 
-    public static Object create( Class iface, State startState, 
+    public static Object create( Class iface, StateMachine sm, 
                                  StateContextLookup contextLookup,
                                  EventArgumentsInterceptor interceptor, 
                                  EventFactory eventFactory )
     {
-        return create( new Class[] {iface}, startState, contextLookup, interceptor, eventFactory );
+        return create( new Class[] {iface}, sm, contextLookup, interceptor, eventFactory );
 }
     
-    public static Object create(Class[] ifaces, State startState) {
-        return create(ifaces, startState, new SingletonStateContextLookup());
+    public static Object create(Class[] ifaces, StateMachine sm) {
+        return create(ifaces, sm, new SingletonStateContextLookup());
     }
     
-    public static Object create(Class[] ifaces, State startState, 
+    public static Object create(Class[] ifaces, StateMachine sm, 
                                 StateContextLookup contextLookup) {
 
-        return create( ifaces, startState, contextLookup, null, new DefaultEventFactory() );
+        return create( ifaces, sm, contextLookup, null, new DefaultEventFactory() );
     }
     
-    public static Object create(Class[] ifaces, State startState, 
+    public static Object create(Class[] ifaces, StateMachine sm, 
                                 StateContextLookup contextLookup, 
                                 EventArgumentsInterceptor interceptor,
                                 EventFactory eventFactory) {
 
         ClassLoader cl = StateMachineProxyFactory.class.getClassLoader();
         InvocationHandler handler = 
-            new MethodInvocationHandler(startState, contextLookup, interceptor, 
+            new MethodInvocationHandler(sm, contextLookup, interceptor, 
                                         eventFactory);
 
         return Proxy.newProxyInstance(cl, ifaces, handler);
     }
     
     private static class MethodInvocationHandler implements InvocationHandler {
-        private final State startState;
+        private final StateMachine sm;
         private final StateContextLookup contextLookup;
         private final EventArgumentsInterceptor interceptor;
         private final EventFactory eventFactory;
-        private final ThreadLocal processingThreadLocal = new ThreadLocal();
-        private final ThreadLocal eventQueueThreadLocal = new ThreadLocal()
-        {
-            protected Object initialValue()
-            {
-                return new LinkedList();
-            }
-        };
         
-        public MethodInvocationHandler( State startState, 
+        public MethodInvocationHandler( StateMachine sm, 
                                        StateContextLookup contextLookup, 
                                        EventArgumentsInterceptor interceptor,
                                        EventFactory eventFactory )
         {
             this.contextLookup = contextLookup;
-            this.startState = startState;
+            this.sm = sm;
             this.interceptor = interceptor;
             this.eventFactory = eventFactory;
         }
@@ -153,53 +148,9 @@
             
             Event event = eventFactory.create(context, method, args);
             
-            synchronized ( context )
-            {
-                LinkedList eventQueue = ( LinkedList ) eventQueueThreadLocal.get();
-                eventQueue.addLast( event );
-                
-                if ( processingThreadLocal.get() != null )
-                {
-                    /*
-                     * This thread is already processing an event. Queue this 
-                     * event.
-                     */
-                    if ( log.isDebugEnabled() )
-                    {
-                        log.debug( "State machine proxy called recursively. "
-                                 + "Queuing event " + event 
-                                 + " for later processing." );
-                    }
-                }
-                else
-                {
-                    processingThreadLocal.set( Boolean.TRUE );
-                    try
-                    {
-                        if ( context.getCurrentState() == null )
-                        {
-                            context.setCurrentState( startState );
-                        }
-                        processEvents( eventQueue );
-                    }
-                    finally
-                    {
-                        processingThreadLocal.set( null );
-                    }
-                }
-            }
+            sm.handle( event );
             
             return null;
-        }
-
-        private void processEvents( LinkedList eventQueue )
-        {
-            while ( ! eventQueue.isEmpty() )
-            {
-                Event event = ( Event ) eventQueue.removeFirst();
-                StateContext context = event.getContext();
-                context.getCurrentState().handle( event );
-            }
         }
     }
 }

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handler.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handler.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handler.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,43 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.mina.sm.event.Event;
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Handler
+{
+    public static final String SELF = "__self__";
+    
+    String[] on() default Event.WILDCARD_EVENT_ID;
+    String[] in();
+    String next() default SELF;
+    int weight() default 0;
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handlers.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handlers.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handlers.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handlers.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,36 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Handlers
+{
+    Handler[] value();
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/Handlers.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/State.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/State.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/State.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/State.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,38 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface State
+{
+    public static final String ROOT = "__root__";
+    
+    String value() default ROOT;
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/annotation/State.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/AbstractStateContext.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/AbstractStateContext.java?view=diff&rev=472911&r1=472910&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/AbstractStateContext.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/AbstractStateContext.java Thu Nov  9 06:25:36 2006
@@ -21,6 +21,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.mina.sm.State;
 
 /**
@@ -31,7 +32,7 @@
  */
 public abstract class AbstractStateContext implements StateContext {
     private State currentState = null;
-    private Map attributes = null;
+    private Map<Object, Object> attributes = null;
 
     public Object getAttribute( Object key )
     {
@@ -53,11 +54,19 @@
         currentState = state;
     }
 
-    public Map getAttributes() 
+    protected Map<Object, Object> getAttributes() 
     {
         if ( attributes == null ) {
-            attributes = new HashMap();
+            attributes = new HashMap<Object, Object>();
         }
         return attributes;
     }
+    
+    public String toString()
+    {
+        return new ToStringBuilder( this )
+            .append( "currentState", currentState )
+            .append( "attributes", attributes )
+            .toString();
+    }    
 }

Modified: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/StateContext.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/StateContext.java?view=diff&rev=472911&r1=472910&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/StateContext.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/context/StateContext.java Thu Nov  9 06:25:36 2006
@@ -18,8 +18,6 @@
  */
 package org.apache.mina.sm.context;
 
-import java.util.Map;
-
 import org.apache.mina.sm.State;
 
 /**
@@ -33,5 +31,4 @@
     void setCurrentState(State state);
     Object getAttribute( Object key );
     void setAttribute( Object key, Object value );
-    Map getAttributes();
 }

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/DefaultEventFactory.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/DefaultEventFactory.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/DefaultEventFactory.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/DefaultEventFactory.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/DefaultEventFactory.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/DefaultEventFactory.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/DefaultEventFactory.java Thu Nov  9 06:25:36 2006
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm;
+package org.apache.mina.sm.event;
 
 import java.lang.reflect.Method;
 

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/DefaultEventFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/Event.java (from r466971, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/Event.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/Event.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/Event.java&r1=466971&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/Event.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/Event.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/Event.java Thu Nov  9 06:25:36 2006
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm;
+package org.apache.mina.sm.event;
 
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.mina.sm.context.StateContext;
@@ -30,6 +30,8 @@
  */
 public class Event
 {
+    public static final String WILDCARD_EVENT_ID = "*";
+    
     private final Object id;
     private final StateContext context;
     private final Object[] arguments;

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/Event.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventArgumentsInterceptor.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventArgumentsInterceptor.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventArgumentsInterceptor.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventArgumentsInterceptor.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventArgumentsInterceptor.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventArgumentsInterceptor.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventArgumentsInterceptor.java Thu Nov  9 06:25:36 2006
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm;
+package org.apache.mina.sm.event;
 
 /**
  * 

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventArgumentsInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventFactory.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventFactory.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventFactory.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventFactory.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventFactory.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/EventFactory.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventFactory.java Thu Nov  9 06:25:36 2006
@@ -16,10 +16,11 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm;
+package org.apache.mina.sm.event;
 
 import java.lang.reflect.Method;
 
+import org.apache.mina.sm.StateMachineProxyFactory;
 import org.apache.mina.sm.context.StateContext;
 
 /**

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/EventFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/UnhandledEventException.java (from r466971, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/UnhandledEventException.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/UnhandledEventException.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/UnhandledEventException.java&r1=466971&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/UnhandledEventException.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/UnhandledEventException.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/UnhandledEventException.java Thu Nov  9 06:25:36 2006
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm;
+package org.apache.mina.sm.event;
 
 /**
  * Thrown when an {@link Event} passed to a state machine couldn't be handled.

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/event/UnhandledEventException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/mina/Events.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/mina/Events.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/mina/Events.java (added)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/mina/Events.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,42 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm.mina;
+
+import org.apache.mina.common.IoHandler;
+
+/**
+ * Defines all possible MINA {@link IoHandler} events.
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public final class Events
+{
+    public static final String SESSION_CREATED = "sessionCreated";
+    public static final String SESSION_OPENED = "sessionOpened";
+    public static final String SESSION_CLOSED = "sessionClosed";
+    public static final String SESSION_IDLE = "sessionIdle";
+    public static final String MESSAGE_RECEIVED = "messageReceived";
+    public static final String MESSAGE_SENT = "messageSent";
+    public static final String EXCEPTION_CAUGHT = "exceptionCaught";
+    
+    private Events()
+    {
+    }
+}

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/mina/Events.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AbstractTransition.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AbstractTransition.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AbstractTransition.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AbstractTransition.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AbstractTransition.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AbstractTransition.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AbstractTransition.java Thu Nov  9 06:25:36 2006
@@ -16,10 +16,13 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm.finite;
+package org.apache.mina.sm.transition;
 
-import org.apache.mina.sm.Event;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.mina.sm.State;
+import org.apache.mina.sm.event.Event;
 
 /**
  * 
@@ -27,34 +30,75 @@
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public abstract class AbstractTransition implements Transition {
-    public static final String WILDCARD_EVENT_ID = "*";
-    
+public abstract class AbstractTransition implements Transition
+{
     private final Object eventId; 
     private final State nextState;
 
-    public AbstractTransition(Object eventId) {
-        this(eventId, null);
+    public AbstractTransition( Object eventId )
+    {
+        this( eventId, null );
     }
-    
-    public AbstractTransition(Object eventId, State nextState) {
+
+    public AbstractTransition( Object eventId, State nextState )
+    {
         this.eventId = eventId;
         this.nextState = nextState;
     }
     
-    public boolean execute(Event event) {
-        if (!eventId.equals(WILDCARD_EVENT_ID) && !eventId.equals(event.getId())) {
+    public Object getEventId()
+    {
+        return eventId;
+    }
+
+    public State getNextState()
+    {
+        return nextState;
+    }
+
+    public boolean execute( Event event )
+    {
+        if( !eventId.equals( Event.WILDCARD_EVENT_ID )
+                && !eventId.equals( event.getId() ) )
+        {
             return false;
         }
-        
-        if (doExecute(event)) {
-            if (nextState != null) {
-                event.getContext().setCurrentState(nextState);
-            }
-            return true;
-        }
-        return false;
+
+        return doExecute( event );
     }
 
     protected abstract boolean doExecute(Event event);
+    
+    public boolean equals( Object o )
+    {
+        if( ! ( o instanceof AbstractTransition ) )
+        {
+            return false;
+        }
+        if ( o == this )
+        {
+            return true;
+        }
+        AbstractTransition that = ( AbstractTransition ) o;
+        return new EqualsBuilder()
+            .append( eventId, that.eventId )
+            .append( nextState, that.nextState )
+            .isEquals();
+    }
+    
+    public int hashCode()
+    {
+        return new HashCodeBuilder( 11, 31 )
+            .append( eventId )
+            .append( nextState )
+            .toHashCode();
+    }
+    
+    public String toString()
+    {
+        return new ToStringBuilder( this )
+                .append( "eventId", eventId )
+                .append( "nextState", nextState )
+                .toString();
+    }
 }

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AbstractTransition.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AmbiguousMethodException.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AmbiguousMethodException.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AmbiguousMethodException.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AmbiguousMethodException.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AmbiguousMethodException.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/AmbiguousMethodException.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AmbiguousMethodException.java Thu Nov  9 06:25:36 2006
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm.finite;
+package org.apache.mina.sm.transition;
 
 /**
  * 

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/AmbiguousMethodException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodInvocationException.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodInvocationException.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodInvocationException.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodInvocationException.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodInvocationException.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodInvocationException.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodInvocationException.java Thu Nov  9 06:25:36 2006
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm.finite;
+package org.apache.mina.sm.transition;
 
 /**
  * 

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodInvocationException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodTransition.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodTransition.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodTransition.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodTransition.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodTransition.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/MethodTransition.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodTransition.java Thu Nov  9 06:25:36 2006
@@ -16,14 +16,20 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm.finite;
+package org.apache.mina.sm.transition;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.Arrays;
 
-import org.apache.mina.sm.Event;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.mina.sm.State;
 import org.apache.mina.sm.context.StateContext;
+import org.apache.mina.sm.event.Event;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * 
@@ -32,6 +38,7 @@
  * @version $Rev$, $Date$
  */
 public class MethodTransition extends AbstractTransition {
+    private static final Logger log = LoggerFactory.getLogger( MethodTransition.class );
     private static final Object[] EMPTY_ARGUMENTS = new Object[0];
     
     private final Method method;
@@ -84,6 +91,16 @@
         this.method = result;
     }
     
+    public Method getMethod()
+    {
+        return method;
+    }
+
+    public Object getTarget()
+    {
+        return target;
+    }
+
     public boolean doExecute(Event event) {
         Class[] types = method.getParameterTypes();
         
@@ -154,6 +171,11 @@
 
     private void invokeMethod(Object[] arguments) {
         try {
+            if( log.isDebugEnabled() )
+            {
+                log.debug( "Executing method " + method + " with arguments " 
+                        + Arrays.asList( arguments ));
+            }
             method.invoke(target, arguments);
         } catch (InvocationTargetException ite) {
             if (ite.getCause() instanceof RuntimeException) {
@@ -163,5 +185,41 @@
         } catch (IllegalAccessException iae) {
             throw new MethodInvocationException(iae);
         }
+    }
+    
+    public boolean equals( Object o )
+    {
+        if( ! ( o instanceof MethodTransition ) )
+        {
+            return false;
+        }
+        if ( o == this )
+        {
+            return true;
+        }
+        MethodTransition that = ( MethodTransition ) o;
+        return new EqualsBuilder()
+            .appendSuper( super.equals( that ) )
+            .append( method, that.method )
+            .append( target, that.target )
+            .isEquals();
+    }
+    
+    public int hashCode()
+    {
+        return new HashCodeBuilder( 13, 33 )
+            .appendSuper( super.hashCode() )
+            .append( method )
+            .append( target )
+            .toHashCode();
+    }
+    
+    public String toString()
+    {
+        return new ToStringBuilder( this )
+                .appendSuper( super.toString() )
+                .append( "method", method )
+                .append( "target", target )
+                .toString();
     }
 }

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/MethodTransition.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoSuchMethodException.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoSuchMethodException.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoSuchMethodException.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoSuchMethodException.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoSuchMethodException.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoSuchMethodException.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoSuchMethodException.java Thu Nov  9 06:25:36 2006
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm.finite;
+package org.apache.mina.sm.transition;
 
 /**
  * 

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoSuchMethodException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoopTransition.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoopTransition.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoopTransition.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoopTransition.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoopTransition.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/NoopTransition.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoopTransition.java Thu Nov  9 06:25:36 2006
@@ -16,10 +16,10 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm.finite;
+package org.apache.mina.sm.transition;
 
-import org.apache.mina.sm.Event;
 import org.apache.mina.sm.State;
+import org.apache.mina.sm.event.Event;
 
 /**
  * {@link Transition} implementation which does nothing but change the state.
@@ -40,4 +40,5 @@
     protected boolean doExecute(Event event) {
         return true;
     }
+    
 }

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/NoopTransition.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/Transition.java (from r466955, directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/Transition.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/Transition.java?view=diff&rev=472911&p1=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/Transition.java&r1=466955&p2=directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/Transition.java&r2=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/finite/Transition.java (original)
+++ directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/Transition.java Thu Nov  9 06:25:36 2006
@@ -16,9 +16,10 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.sm.finite;
+package org.apache.mina.sm.transition;
 
-import org.apache.mina.sm.Event;
+import org.apache.mina.sm.State;
+import org.apache.mina.sm.event.Event;
 
 /**
  * 
@@ -28,4 +29,6 @@
  */
 public interface Transition {
     boolean execute(Event event);
+    Object getEventId();
+    State getNextState();
 }

Propchange: directory/sandbox/niklas/mina-sm/src/main/java/org/apache/mina/sm/transition/Transition.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/StateMachineFactoryTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/StateMachineFactoryTest.java?view=auto&rev=472911
==============================================================================
--- directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/StateMachineFactoryTest.java (added)
+++ directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/StateMachineFactoryTest.java Thu Nov  9 06:25:36 2006
@@ -0,0 +1,173 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 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.mina.sm;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.sm.StateMachineCreationException;
+import org.apache.mina.sm.StateMachineFactory;
+import org.apache.mina.sm.State;
+import org.apache.mina.sm.annotation.Handler;
+import org.apache.mina.sm.annotation.Handlers;
+import org.apache.mina.sm.transition.MethodTransition;
+import org.apache.mina.sm.transition.Transition;
+
+/**
+ * Tests {@link StateMachineFactory}.
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class StateMachineFactoryTest extends TestCase
+{
+    Method barInA;
+    Method error;
+    Method fooInA;
+    Method fooInB;
+    Method barInC;
+    Method fooOrBarInCOrFooInD;
+    
+    protected void setUp() throws Exception
+    {
+        barInA = States.class.getDeclaredMethod( "barInA", new Class[ 0 ] );
+        error = States.class.getDeclaredMethod( "error", new Class[ 0 ] );
+        fooInA = States.class.getDeclaredMethod( "fooInA", new Class[ 0 ] );
+        fooInB = States.class.getDeclaredMethod( "fooInB", new Class[ 0 ] );
+        barInC = States.class.getDeclaredMethod( "barInC", new Class[ 0 ] );
+        fooOrBarInCOrFooInD = States.class.getDeclaredMethod( "fooOrBarInCOrFooInD", new Class[ 0 ] );
+    }
+
+    public void testCreate() throws Exception
+    {
+        States states = new States();
+        StateMachine sm = StateMachineFactory.create( States.A, states );
+        
+        State a = sm.getState( States.A );
+        State b = sm.getState( States.B );
+        State c = sm.getState( States.C );
+        State d = sm.getState( States.D );
+        
+        assertEquals( States.A, a.getId() );
+        assertNull( a.getParent() );
+        assertEquals( States.B, b.getId() );
+        assertSame( a, b.getParent() );
+        assertEquals( States.C, c.getId() );
+        assertSame( b, c.getParent() );
+        assertEquals( States.D, d.getId() );
+        assertSame( a, d.getParent() );
+        
+        List<Transition> trans = null;
+        
+        trans = a.getTransitions();
+        assertEquals( 3, trans.size() );
+        assertEquals( new MethodTransition( "bar", barInA, states ), trans.get( 0 ) );
+        assertEquals( new MethodTransition( "*", error, states ), trans.get( 1 ) );
+        assertEquals( new MethodTransition( "foo", b, fooInA, states ), trans.get( 2 ) );
+        
+        trans = b.getTransitions();
+        assertEquals( 1, trans.size() );
+        assertEquals( new MethodTransition( "foo", c, fooInB, states ), trans.get( 0 ) );
+        
+        trans = c.getTransitions();
+        assertEquals( 3, trans.size() );
+        assertEquals( new MethodTransition( "bar", a, barInC, states ), trans.get( 0 ) );
+        assertEquals( new MethodTransition( "foo", d, fooOrBarInCOrFooInD, states ), trans.get( 1 ) );
+        assertEquals( new MethodTransition( "bar", d, fooOrBarInCOrFooInD, states ), trans.get( 2 ) );
+
+        trans = d.getTransitions();
+        assertEquals( 1, trans.size() );
+        assertEquals( new MethodTransition( "foo", fooOrBarInCOrFooInD, states ), trans.get( 0 ) );
+    }
+    
+    public void testCreateStates() throws Exception
+    {
+        State[] states = StateMachineFactory.createStates( States.class );
+        assertEquals( States.A, states[ 0 ].getId() );
+        assertNull( states[ 0 ].getParent() );
+        assertEquals( States.B, states[ 1 ].getId() );
+        assertEquals( states[ 0 ], states[ 1 ].getParent() );
+        assertEquals( States.C, states[ 2 ].getId() );
+        assertEquals( states[ 1 ], states[ 2 ].getParent() );
+        assertEquals( States.D, states[ 3 ].getId() );
+        assertEquals( states[ 0 ], states[ 3 ].getParent() );
+    }
+    
+    public void testCreateStatesMissingParents() throws Exception
+    {
+        try
+        {
+            StateMachineFactory.createStates( StatesWithMissingParents.class );
+            fail( "Missing parents. FsmCreationException expected." );
+        }
+        catch( StateMachineCreationException fce )
+        {
+        }
+    }
+    
+    public static class States
+    {
+        @org.apache.mina.sm.annotation.State protected static final String A = "a";
+        @org.apache.mina.sm.annotation.State( A ) protected static final String B = "b";
+        @org.apache.mina.sm.annotation.State( B ) protected static final String C = "c";
+        @org.apache.mina.sm.annotation.State( A ) protected static final String D = "d";
+        
+        @Handler( on = "bar", in = A )
+        protected void barInA()
+        {
+        }
+        
+        @Handler( on = "bar", in = C, next = A )
+        protected void barInC()
+        {
+        }
+        
+        @Handler( in = A )
+        protected void error()
+        {
+        }
+        
+        @Handler( on = "foo", in = A, next = B )
+        protected void fooInA()
+        {
+        }
+        
+        @Handler( on = "foo", in = B, next = C )
+        protected void fooInB()
+        {
+        }
+        
+        @Handlers( { @Handler( on = { "foo", "bar" }, in = C, next = D ),
+                     @Handler( on = "foo", in = D ) } )
+        protected void fooOrBarInCOrFooInD()
+        {
+        }
+      
+    }
+    
+    public static class StatesWithMissingParents
+    {
+        @org.apache.mina.sm.annotation.State( "b" ) public static final String A = "a";
+        @org.apache.mina.sm.annotation.State( "c" ) public static final String B = "b";
+        @org.apache.mina.sm.annotation.State( "d" ) public static final String C = "c";
+        @org.apache.mina.sm.annotation.State( "e" ) public static final String D = "d";
+    }
+}

Propchange: directory/sandbox/niklas/mina-sm/src/test/java/org/apache/mina/sm/StateMachineFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message