commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig McClanahan <craig...@gmail.com>
Subject Re: [chain] dispatch via lookup
Date Fri, 03 Dec 2004 22:19:29 GMT
On Fri, 03 Dec 2004 15:30:59 -0600, Vic <vin@friendvu.com> wrote:
> Craig McClanahan wrote:
> > How about this?
> >
> >     Context context = ...; // Commons Chain context for this command
> 
> Just a Map in my case.
> 
> >     String catalogName = ...; // Name of catalog containing the command you want
> >     String commandName = ...; // Name of command you want (from this catalog)
> >     Catalog catalog = CatalogFactory.getInstance().getCatalog(catalogName);
> 
> How does above catalog know to read my Xml catlog file, when it does not
> know the url to my xml file where the catalog is defined. Is there a
> certian place it looks at?
> 

Simplest thing is to use org.apache.commons.chain.web.ChainListener. 
Configure it is a <listener> in web.xml and it will load up the
specified config files (see the Javadocs for this class to see how to
tell it which resources to read) at webapp startup.

My favorite feature of this class is if you have a JAR file (in
WEB-INF/lib) that has a "META-INF/chain-config.xml" resource in it,
this will get loaded automatically, without being explicitly listed in
web.xml.  That way, you can package up a bunch of commands and chains
in a JAR, with a configuration resource, and it gets automatically
registered.

> 
> >     Command command = catalog.getCommand(commandName);
> 
> Since I do not think it read the catalog of commands from my xml, it
> won't get the command. But if the catalog could read it, I see how this
> would work.
> How to read a catalog from XML?
> 

See above.

> 
> >     command.execute(context);
> >
> > Note that it uses a static method, so you don't have to carry around
> > references to a catalog in your method signatures
> 
> This is what my implementation does, but I'd like to upgrade, there are
> some deprecated chain methods now.
> 
> Of course ... I had to extend catalog to have a way of
> populating/initilzing self from XML.
> 
> .V
> 
> 
> 
> 
> ... just figure out
> > what catalog and command you want, and go.
> >
> > Craig
> >
> >
> >
> > On Fri, 03 Dec 2004 11:23:40 -0600, Vic <vin@friendvu.com> wrote:
> >
> >>Craig wrote quote in a struts dev thread on chain "
> >>
> >>In your standard processing chain, do something like this:
> >>
> >>     <command className="org.apache.commons.chain.generic.LookupCommand
> >>                   catalogName="foo"
> >>                          name="bar"
> >>                      optional="true"/>
> >>
> >>What this does, in English, is:
> >>* Look up a command named "bar" in a catalog named "foo".
> >>* If such a command exists, delegate control to it
> >>   (and do all the right stuff about filters if this is a chain)
> >>* If such a command does not exist, silently continue
> >>
> >>" end quote.
> >>
> >>I do not understand how to do above.  Is that the declaration done in
> >>chain.xml?
> >>This assumes that I hard code the name of command I want to go to.
> >>(if I knew command at decleration I would just name it then, not look up).
> >>
> >>Is there a built in way of dispatching dynamicaly?
> >>
> >>for example: lookUpAndExecute("foo");
> >>
> >>Hint?
> >>
> >>tia,
> >>.V
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >>
> >>
> 
> 
> ---------------------------------------------------------------------
> 
> 
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message