In summary, when you provide a custom context to fortress, it is used as
a "parent" context for all contexts actually passed down to components.
This means you cannot cast a context object in your clients to a more
specific version, and it means that the fortress implementation is still
free to override one or more of the context values you pass in (but it
doesn't IIRC).

Your questions:

* why?
* so how do I get custom context info to my components?

The answer to the "why?" question is similar to the answer to the
question "why the proxies?": components should just use the Context
interface, and not be dependent on any subinterface of Context. In
particular, in creating components, this:

  public void contextualize( Context c )
  {
    public SpecificContext c2 = (SpecificContext)c;
  }

is something we wanted to avoid. However, more importantly, creating a
new context instance for each and every component can help avoid thread
safety issues (but I don't think it does atm).

The "how?" question...answer: don't use a specific interface, but put
your context info in a DefaultContext (well, any Context implementation,
but you usually can just use the default one); feed that to fortress:

  public DefaultContext c = new DefaultContext();
  c.put( "key", "value" );
  c.makeReadOnly();
  fortressConfig.setContext( c ); // I forgot how this works exactly

in your components, this will work:

  public void contextualize( Context c )
  {
    String value = (String)c.get( "key" );
    if( value != "value" )
      throw new ContextException( "value is not what we expected!" );
           // this exception won't get thrown
  }

Is there a way around this? Yes, but I really don't recommend you use
it. Create a new ComponentFactory implementation that passes on the
context directly instead of as a parent, find the locations where
fortress uses them (I believe only in AbstractContainer), and override
those methods in your DefaultContainer subclass to use your custom
implementation.

hope that clears a few things up!

cheers,

- LSD

PS: again, please add useful answers to the wiki



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

Reply via email to