directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <elecha...@gmail.com>
Subject Re: [LDAP] Removing LdapMessageHandler interface
Date Wed, 14 Mar 2007 17:21:19 GMT
Enrique Rodriguez a écrit :

> Hi, Directory developers,
>
> Every handler in the LDAP protocol provider implements
> LdapMessageHandler.  The sole purpose of LdapMessageHandler is to
> init() the handler with config.  Turns out, config is only ever
> actually used by the SearchHandler.  Also, in the new world of MINA,
> config is typically set in the IoSession as attributes.  I suspect
> this is a relic from before MINA, since you can add config as
> attributes to the IoSession.  Any objections to removing this
> interface?
>
> Enrique
>
I bet that would not be a good idea to remove LdapMessageHandler : it's 
use to initialize MINA. We iterate through all the declared handler in 
LdapProtocolProvider and initialize each handler using reflection. 
Having an interface allow this class to be agnostic about each specific 
handler :

...
        Iterator requestTypes = DEFAULT_HANDLERS.keySet().iterator();

        while ( requestTypes.hasNext() )
        {
            LdapMessageHandler handler = null;
            String type = ( String ) requestTypes.next();
            Class clazz = null;

            if ( copy.containsKey( type ) )
            {
                try
                {
                    clazz = Class.forName( ( String ) copy.get( type ) );
                }
                catch ( ClassNotFoundException e )
                {
                    ...
                }
            }
            else
            {
                clazz = ( Class ) DEFAULT_HANDLERS.get( type );
            }

            try
            {
                Class typeClass = Class.forName( type );
                handler = ( LdapMessageHandler ) clazz.newInstance();
                handler.init( cfg );
                this.handler.addMessageHandler( typeClass, handler );
            }
...

I don't mean that the way it's done in the LdapProtocolProvider is the 
best ever, but removing the interface is not as simple as it seems.

So far, my point is that the interface don't harm a lot. May be we can 
simply remove the init() method from it. Otherwise, "don't fix something 
that works if there is not a valuable improvment doing so ..."

2cts.
Emmanuel

Mime
View raw message