> There is currently *not* consensus that a component should be able to
> specify any interface that it should be able to cast the context to. That
> is, for every class/interface T,
>
>      public void contextualize (Context context) {
>          T myContext = (T) context;
>      }
>
> the component should be able to declare that it expects to cast the
context
> to a T. (For a less abstract example, replace T with BlockContext.)

I understand that this usage pattern is in-grained in Avalon 4, and probably
cannot be changed until Avalon 5 so as not to break existing applications.
Just pointing out an issue I have with this coding pattern.

I really dislike the use of separately maintained meta-data disjoint from
code to describe a mandatory contract.  If the meta-data isn't kept in synch
with the source code, the contract is corrupted.  In this case, the
container doesn't know what type of context is expected, and cannot be told
by the component.

Since there is no guarantee that the context is castable to a T, the
component probably should do something like:

      protected T myContext;

      public void contextualize (Context context)
             throws ContextException
      {
            try
          {
              myContext = (T) context;
          }
          catch(ClassCastException cce)
          {
              log("I'm sorry, but the context I got isn't what I need.
Please check the meta-data.");
              throw new ContextException(...);
          }
      }

in order to be safe.

Wrong?  Right?  Indifferent?  :-)

        --- Noel


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to