avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <blorit...@apache.org>
Subject Re: [Excalibur] ExcaliburComponentSelector.hasComponent() query
Date Tue, 31 Jul 2001 12:47:06 GMT
Stuart Roebuck wrote:
> 
> I'm trying to pin down a problem with components in Cocoon 2 at the moment
> and was trying to get to grips with Avalon.  I ran across the following
> code which didn't look like what I was expecting...
> 
> "hasComponent()" which seems like a benign test, has the side-effect of
> 'releasing' a component and appears to rely on "release()" not raising an
> exception as the basis for determining the component's existence:

It relies on the select() or lookup() function to not throw an exception.  It
could be rewritten to take advantage of the internal structure, but this approach
is both future proof (it does not break if you reimplement the lookup() or
select() functions) and correct.  There is the possibility of trying to
embed Objects that are not Components--which effectively removes the ability
to get the Component.

> 
> ExcaliburComponentSelector.java:
> >     /**
> >      * Tests for existence of a component.
> >      */
> >     public boolean hasComponent( final Object hint )
> >     {
> >         if ( ! m_initialized ) return false;
> >         if ( m_disposed ) return false;
> >
> >         boolean exists = false;
> >
> >         try
> >         {
> >             this.release( this.select( hint ) );
> >             exists = true;
> >         }
> >         catch ( Throwable t )
> >         {
> >             // We can safely ignore all exceptions
> >         }
> >
> >         return exists;
> >     }
> 
> Apologies in advance if I'm being particularly stupid today! :-)
> 
> Stuart.
> 
> -------------------------------------------------------------------------
> Stuart Roebuck                                  stuart.roebuck@adolos.com
> Lead Developer                               Java, XML, MacOS X, XP, etc.
> ADOLOS                                           <http://www.adolos.com/>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org

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


Mime
View raw message