avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Mouat <rob...@mouat.net>
Subject Re: roles and assembly
Date Sat, 22 Jun 2002 00:25:34 GMT
Robert Mouat wrote:

> <thinking-out-loud>

    <aim>to get a grasp of this lookup() thing</aim>


> e.g.
>   public void compose( ComponentResolver cr, ComponentFetcher cf )
>   {
>     String id = cr.resolve( "A-role" );
>     Object component = cf.fetch( id );
>   }

I'd like to add a few more thoughts to this regarding hints.  It seems
that given the above splitting of the lookup into locate and manage, it is
now possible to perform custom lookups...

e.g. to borrow from someone else's example

  String address = "someone@domain.tld"
  Resolver msr = (Resolver) cf.fetch( cr.resolve( "mail-server-resolver" ) );
  String id = msr.resolve( address );
  Object component = cf.fetch( id );

Where the mail-server-resolver could look like:

  class MailServerResolver implements Composable, Resolver
    String m_specialMailServerId;
    String m_defaultMailServerId;

    public void compose( ComponentResolver cr, ComponentFetcher cf )
      m_specialMailServerId = cr.resolve( "special-mail-server" );
      m_defaultMailServerId = cr.resolve( "default-mail-server" );

    public String resolve( Object hint )
      if ( isSpecialEmailAddress( hint ) )
        return m_specialMailServerId;
        return m_defaultMailServerId;

    // ...


a potential problem with this approach is that with the cr.resolve()
method, the container had the opportunity to verify that the return id
matched a component that satisified the dependancy metadata, this has now
been bypassed... one solution might be to add another method to the
ComponentResolver, e.g. replace the above with:

  String id = cr.resolve( "mail-server-resolver", address );
  Object component = cf.fetch( id );

hmmmm... looking at what I've written a little more carefully, it seems
that if you turn this back into a 1-step process (the 'id' bit was just a
conceptual thing anyway) -- the first example looks a lot like
ComponentSelector, and the second like lookup(role, hint)...

maybe I should go back to lurking...

> </thinking-out-loud>


To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>

View raw message