You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Vic <vi...@friendvu.com> on 2004/12/03 18:23:40 UTC
[chain] dispatch via lookup
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
Re: [chain] dispatch via lookup
Posted by Craig McClanahan <cr...@gmail.com>.
In a nonweb world, it's pretty easy to load up a chain config file:
import org.apache.commons.chain.config.ConfigParser;
ConfigParser parser = new ConfigParser();
URL url = ...; // URL of your config resource, could be file: or
http: or whatever
parser.parse(url);
Craig
On Fri, 03 Dec 2004 16:24:40 -0600, Vic <vi...@friendvu.com> wrote:
> Sorry for so many questions. One more.
>
>
>
>
> Craig McClanahan wrote:
> > On Fri, 03 Dec 2004 15:30:59 -0600, Vic <vi...@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.
> >
>
> Some of the time, I do not have a container. For example I do cron
> trigered async processing. They to use a chain.
> So if this is the only way... I will use my catalog extension that reads
> an xml file via digester. If there is something else, plz let me know.
>
> THANKS AGAIN!
>
> .V
>
>
>
>
> > 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
> >>>
> >>>
>
>
> ---------------------------------------------------------------------
>
>
> 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
Re: [chain] dispatch via lookup
Posted by Vic <vi...@friendvu.com>.
Sorry for so many questions. One more.
Craig McClanahan wrote:
> On Fri, 03 Dec 2004 15:30:59 -0600, Vic <vi...@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.
>
Some of the time, I do not have a container. For example I do cron
trigered async processing. They to use a chain.
So if this is the only way... I will use my catalog extension that reads
an xml file via digester. If there is something else, plz let me know.
THANKS AGAIN!
.V
> 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
>>>
>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [chain] dispatch via lookup
Posted by Craig McClanahan <cr...@gmail.com>.
On Fri, 03 Dec 2004 15:30:59 -0600, Vic <vi...@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 <vi...@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
Re: [chain] dispatch via lookup
Posted by Vic <vi...@friendvu.com>.
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?
> 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?
> 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 <vi...@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
Re: [chain] dispatch via lookup
Posted by Craig McClanahan <cr...@gmail.com>.
How about this?
Context context = ...; // Commons Chain context for this command
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);
Command command = catalog.getCommand(commandName);
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 ... just figure out
what catalog and command you want, and go.
Craig
On Fri, 03 Dec 2004 11:23:40 -0600, Vic <vi...@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