ComponentMonitorStrategy Interface Problem + Pico Scripting

View: New views
2 Messages — Rating Filter:   Alert me  

ComponentMonitorStrategy Interface Problem + Pico Scripting

by Michael Rimov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all.  I hit a problem with the new DefaultClassLoadingPicoContainer.  The
culprit code is invoked when parent.createChildContainer() is called:

    protected DefaultClassLoadingPicoContainer createChildContainer() {
        MutablePicoContainer child = getDelegate().makeChildContainer();
        DefaultClassLoadingPicoContainer container = new
DefaultClassLoadingPicoContainer(getComponentClassLoader(), child);
        container.changeMonitor(currentMonitor());
        return container;
    }

    public void changeMonitor(ComponentMonitor monitor) {
        ((ComponentMonitorStrategy) getDelegate()).changeMonitor(monitor);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    }


If the delegate happens to be a DefaultClassLoadingPicoContainer, then the
result is a class cast exception, which happens a little more often than not
because there's only a few containers that implement ComponentMonitorStrategy,
and AbstractDelegatingPicoContainer is not one of them.

So, do we have MutablePicoContainer implement ComponentMonitorStrategy, or do we
just more defensively program changeMonitor()?  Or is there another option?

Thanks,
                                                        -Mike


                               




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: ComponentMonitorStrategy Interface Problem + Pico Scripting

by Mauro Talevi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Michael Rimov wrote:

> Hi all.  I hit a problem with the new DefaultClassLoadingPicoContainer.  The
> culprit code is invoked when parent.createChildContainer() is called:
>
>     protected DefaultClassLoadingPicoContainer createChildContainer() {
>         MutablePicoContainer child = getDelegate().makeChildContainer();
>         DefaultClassLoadingPicoContainer container = new
> DefaultClassLoadingPicoContainer(getComponentClassLoader(), child);
>         container.changeMonitor(currentMonitor());
>         return container;
>     }
>
>     public void changeMonitor(ComponentMonitor monitor) {
>         ((ComponentMonitorStrategy) getDelegate()).changeMonitor(monitor);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     }
>
>
> If the delegate happens to be a DefaultClassLoadingPicoContainer, then the
> result is a class cast exception, which happens a little more often than not
> because there's only a few containers that implement ComponentMonitorStrategy,
> and AbstractDelegatingPicoContainer is not one of them.
>
> So, do we have MutablePicoContainer implement ComponentMonitorStrategy, or do we
> just more defensively program changeMonitor()?  Or is there another option?
>

IMO the second option:  we need to check the instance of the delegate
before casting to component monitor stratege.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


LightInTheBox - Buy quality products at wholesale price