avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Sutic" <leo.su...@inspireinfrastructure.com>
Subject RE: MutableConfiguration
Date Thu, 05 Feb 2004 09:44:49 GMT

> From: Stephen McConnell [mailto:mcconnell@apache.org] 
>    public interface Graph
>    {
>        // contains all of the stuff in Configuration
>    }
>    public interface Configuration extends Graph{}
>    public interface GraphMutator implements Graph
>    {
>         // contains the setter operations
>         Configuration getConfiguration();
>    }
> What this gives you is the assurance that a Configuration is not 
> castable to something that is modifiable.

No it doesn't. DefaultConfiguration will implement both Graph
and GraphMutator. Either that, or you have to create a Proxy
object, which was my plan (2):

>  2. Provide a ConfigurationProxy class that wraps a Configuration
>     and only implements Configuration. The container should wrap
>     any DefaultConfiguration passed to the client in this class.

The problem is this: If the object passed to the component implements
MutableConfiguration, then it can be cast to it (unless the classloader
separation stops this).

So if you have:

    public class DefaultConfiguration 
           implements Configuration, MutableConfiguration { ... }

And the component receives an instance of DefaultConfiguration in its
configure() method:

    public void configure (
        Configuration config /* is really a DefaultConfiguration */ ) {

        // ...


Then the component can do this:

    MutableConfiguration mutable = (MutableConfiguration) config;

Simply put, any interface hierarchy you may have will fail to prevent
the cast from Configuration to MutableConfiguration, if the object
actually passed to the cast:er implements both.

There is really only one way to prevent it:

    Make sure that the object passed to the component doesn't 
    implement MutableConfiguration.

This can be done in two ways:

 1. By wrapping the DefaultConfiguration in a proxy that only
    implements the Configuration interface and which doesn't
    have any mutators.

 2. By not having MutableConfiguration in a classloader that
    is common to the client and the container. This means that
    MutableConfiguration.class for the client won't be equal to
    MutableConfiguration.class for the container, and the cast
    will fail. In a sense, as far as the client is concerned, 
    DefaultConfiguration doesn't implement MutableConfiguration,
    since it implements the container's MutableConfiguration, and
    not the client's.


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

View raw message