To allow for Spring configuration, I have added the following three
files (see attachment)... Maybe this can help you for further
releases... :.)

And my Spring configuration file contains the following:

        <bean id="passwordProtectionStateMachine"
class="filter.passwordprotection.StateMachineFactoryBean">
                <property name="startState">
                        <util:constant
static-field="filter.passwordprotection.PasswordProtection.PASSWORD_AUTH
ENTICATION" />
                </property>
                <property name="stateMachineImpl">
                        <bean
class="filter.passwordprotection.PasswordProtection" />
                </property>
                <property name="transitionAnnotation"
value="org.apache.mina.statemachine.annotation.IoFilterTransition" />
        </bean>
        
        <bean id="passwordProtectionIoFilterStateMachine"
class="filter.passwordprotection.IoFilterStateMachineProxyFactoryBean">
                <property name="ignoreStateContextLookupFailure"
value="true" />
                <property name="ignoreUnhandledEvents" value="true" />
                <property name="stateContextLookup"
ref="ioSessionStateContextLookup" />
                <property name="stateMachine"
ref="passwordProtectionStateMachine" />
        </bean>
        
        <bean id="ioSessionStateContextLookup"
        
class="org.apache.mina.statemachine.context.IoSessionStateContextLookup"
>
                <constructor-arg index="0">
                        <bean
class="filter.passwordprotection.PasswordProtectionStateContextFactory"
/>
                </constructor-arg>
                <constructor-arg index="1"
value="passwordProtectionContext" />
        </bean>

I used simple factory bean but maybe I could have used proxy factory
bean to do the job since the state machine makes use of proxy...
Unfortunately I don't know enough about proxy factory bean for now so I
went to a simpler solution that works! :.)


Simon 
-----Original Message-----
From: Niklas Therning [mailto:[EMAIL PROTECTED] 
Sent: April-17-08 3:06 PM
To: [email protected]
Subject: Re: Mina statemachine and Spring

Simon Trudeau wrote:
> I am trying to configure an IoFilter Chain using Mina and Spring. My 
> FilterChain contains a StateMachine IoFilter. I would like to know how

> to write an applicationContext.xml file to configure such a 
> StateMachine IoFilter.
>  
> Programmatically, I would do the following:
>  
> StateMachine sm =
> StateMachineFactory.getInstance(IoFilterTransition.class).create(Passw
> or dProtection.PASSWORD_AUTHENTICATION, new PasswordProtection());
>
>  
>
>         IoSessionStateContextLookup stateContextLookup = new 
> IoSessionStateContextLookup(new StateContextFactory()
>
>         {
>
>             public StateContext create()
>
>             {
>
>                 return new
> PasswordProtection.PasswordProtectionContext();
>
>             }
>
>         }, "passwordProtectionContext");
>
>             
>
>         StateMachineProxyBuilder proxyBuilder = new 
> StateMachineProxyBuilder();
>
>         proxyBuilder.setStateContextLookup(stateContextLookup);
>
>         proxyBuilder.setIgnoreUnhandledEvents(true);
>
>         proxyBuilder.setIgnoreStateContextLookupFailure(true);
>
>         IoFilter stateMachineIofilter = 
> proxyBuilder.create(IoFilter.class, sm);
>
>  
>
> So how should I go about configuring that in a Spring 
> applicationContext.xml file? I have looked at the chat example in mina

> 2.0 but it doesn't help much for such a particular case.
>
>  
>
> Your help is greatly appreciated,
>
>  
> Simon
>  
>
>   
I think it is doable but will be quite complex. In my project I'm using
a custom factory instead. In your case the factory would contain the
code above. Then you would call the static factory method from your
Spring config file to create the IoHandler or IoFilter implementation.

HTH

--
Niklas Therning
www.spamdrain.net

Reply via email to