[EMAIL PROTECTED] wrote:

Thanks very much - you were extremely thorough. I'll process your comments now.


Actually I neglected to mention one of Merlin's more eosteric context management features. If you want to change the contextualization interface that is applied to a component - well - you can. For example, lets imagine you want to do something like:



public void contextualize( MyContext context ) { File dir = context.getDirectory(); // look dad - no casting }


All you need to do is to write the interface, declare the context strategy dependency, provide a context handler extension, and your done. There is a tutorial on this subject in CVS under merlin/merlin-platform/tutorials/contextualization. Assuming you have built both avalon-sandbox/meta and avalon-sandbox/merlin, all you need to do to run the demo is:


 $ cd merlin/merlin-platform/tutorials/contextualization
 $ maven validate

Stephen.


Thanks, Alex





From: Stephen McConnell <[EMAIL PROTECTED]> Date: 2003/08/18 Mon PM 01:02:29 EDT To: Avalon framework users <[EMAIL PROTECTED]> Subject: Re: Questions regarding the Context interface




[EMAIL PROTECTED] wrote:



Hello,

My questions regard the use of the Context interface. I have used the less portable means for getting a context object from the contextualize method

in

the past when using phoenix for my components - namely the following form:

public void contextualize( Context context ) throws ContextException { BlockContext tContext = ( BlockContext ) context; }

As you can see the BlockContext is from phoenix. I found myself doing this because I could get a path to the base phoenix directory via the getBaseDirectory() method. I would like to use the recommended portable mechanism now that LDAPd is going to use more than one container. The question is how do I make the container add the appropriate Context entry.

I

would image that would be container implementation specific. So how would

I

add this entry using say Merlin and Fortress:

<entry key="avalon:work" type="java.io.File"/>




If you declare the following <entry/> declaration in a type descriptor (manually or via an @avalon.entry) then Merlin will take care of this for you. This declaration is based on the meta-info model declarations which means its as close as you can get to an Avalon standard.


<context> <entry key="urn:avalon:home" type="java.io.File"/> </context>

Please note that the following two file related keys are available (which is slighlty different to what you described above):

"urn:avalon:work" - a transient directory that will be desoyed following decommissioning of the component "urn:avalon:home" - persistent directory for the component




to be able to get

File workDirectory = ( File ) context.get( "avalon:work" ) ;

as is the recommended way in the javadocs page for the Context interface

here:




http://avalon.apache.org/framework/api/org/apache/avalon/framework/context/Context.html


If you want to use a friendly castable context interface then you need to declare this under the @avalon.context type="MyContextInterface" tag which generates the following:


<context type="MyContextInterface"> <!-- plus any entries --> </context>

In your code you can safely case the supplied context to the declared interface just like you do in Phoenix. This is also covered by the meta-info model but Merlin is probably the only container to provide support for this capability at this time.

public void contextualize( Context context ) { MyContextInterface myContext = (MyContextInterface) context; File file = myContext.getMyFile(); }

There is also a working demonstration of this in the merlin tutorial content.

$ cd merlin-platform\tutorials\context_casting $ maven $ merlin -execute target\classes

[INFO ] (tutorial.hello): listing values resolved from domain specific context [INFO ] (tutorial.hello): supplied context class: tutorial.DemoContextProvider [INFO ] (tutorial.hello): name: hello [INFO ] (tutorial.hello): partition: /tutorial/ [INFO ] (tutorial.hello): home: [you-directory]\home\tutorial\hello [INFO ] (tutorial.hello): temp: C:\TEMP\tutorial\hello

Stephen.




Thanks much, Alex




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








--


Stephen J. McConnell mailto:[EMAIL PROTECTED] http://www.osm.net

Sent via James running under Merlin as an NT service. http://avalon.apache.org/sandbox/merlin




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







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






--


Stephen J. McConnell
mailto:[EMAIL PROTECTED]
http://www.osm.net

Sent via James running under Merlin as an NT service.
http://avalon.apache.org/sandbox/merlin




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



Reply via email to