You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by tm...@nitwit.de on 2005/03/13 17:43:40 UTC

[chain] fixed, one-way chains, only?

Hi!

I yet only had an quick look at Commons Chains. Am I right that a GoF/Commons 
chain does have a fixed one-way flow, only? I want to use the lib in order to 
parse the iTunesDB which looks like this 
(http://www.ipodlinux.org/ITunesDB#iTunesDB_file):

<mhbd> - This is a database
  <mhsd> - This is a list holder, which holds either a mhlt or an mhlp
    <mhlt> - This holds a list of all the songs on the iPod
      <mhit> - This describes a particular song
        <mhod>... - These hold strings associated with a song
        <mhod>... - Things like Artist, Song Title, Album, etc.
      <mhit> - This is another song. And so on.
        <mhod>...
        <mhod>...
      ...
  <mhsd> - Here's the list holder again.. This time, it's holding an mhlp
    <mhlp> - This holds a bunch of playlists. In fact, all the playlists.
      <mhyp> - This is a playlist.
        <mhod>... - These mhods hold info about the playlists like the name of 
the list.
        <mhip>... - This mhip holds a reference to a particular song on the 
iPod.
        ...
      <mhyp> - This is another playlist. And so on.
        <mhod>... - Note that the mhods also hold other things for smart 
playlists
        <mhip>...
        ...
      ...

As you can see, it's not mhdb -> mhsd -> mhlt but the flow may also be mhbd -> 
mhsd -> mhlp. And esp. mhod is used everywhere. So, what I need is something 
like the struts config. This cannot be done with Commons Chain, can it?

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


Re: [chain] fixed, one-way chains, only?

Posted by Craig McClanahan <cr...@gmail.com>.
On Tue, 15 Mar 2005 21:54:29 +0100, tmp@nitwit.de <tm...@nitwit.de> wrote:
> It does perfectly match my requirement. The only problem it that the chain is
> fixed hierarchical and does not implement any logic which element to be the
> next to be able to handle the object properly.
> 
> So, it's
> 
>         A -> B -> C
> 
> rather than
> 
>    +- B
>    |
> A -+ (logic)
>    |
>    +- C
> 

Building a Command implementation that says "execute command B if
condition X is true, or command C otherwise" is trivially simple to
write.  It isn't really amenable to a generic implementation, however,
because the conditional test is application specific (as is the number
of potential branches).

Not also that either B or C can actually be a chain itself, because a
Chain is-a Command.

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] fixed, one-way chains, only?

Posted by tm...@nitwit.de.
On Tuesday 15 March 2005 00:33, Martin Cooper wrote:
> I think you may want to read some more on the Chain of Responsibility
> pattern. It has no relationship to trees, so I think perhaps you're
> confusing it with a different pattern. From the GoF book:

Well, if you carefully read the book you'll read as well that the pattern are 
only ideas and not perfect :) That's why you will only find code snippets in 
the original GoF. 

BTW The GoF chain also does not have a state as Commons Chain does have. 

I think the GoF would agree that struts did actually understand the idea 
behind Chain of Reponsibility.

> Chain of Responsibility
> Avoid coupling the sender of a request to its receiver by giving more
> than one object a chance to handle the request. Chain the receiving
> objects and pass the request along the chain until an object handles
> it.
>
> This doesn't seem to me to be related to the problem you are trying to
> solve.

It does perfectly match my requirement. The only problem it that the chain is 
fixed hierarchical and does not implement any logic which element to be the 
next to be able to handle the object properly. 

So, it's

	A -> B -> C

rather than

   +- B
   |
A -+ (logic)
   |
   +- C
 

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


Re: [chain] fixed, one-way chains, only?

Posted by Martin Cooper <mf...@gmail.com>.
On Mon, 14 Mar 2005 19:50:25 +0100, tmp@nitwit.de <tm...@nitwit.de> wrote:
> On Monday 14 March 2005 06:02, Craig McClanahan wrote:
> > Commons Chain isn't about parsing documents, it is about executing
> > commands.  If you are after converting your XML document into some
> 
> It a pattern. It about what I want to use it for.
> 
> > sort of data structure, you probably want to look at Commons Digester
> > instead.
> 
> No, I'm not after parsing XML I'm about parsing a file format that has some
> kind of a tree structure and which a chain would perfectly match - if I had
> the possibility to buidl the chain in a tree structure as well. I also think
> that this would be a smart extension of the pattern.

I think you may want to read some more on the Chain of Responsibility
pattern. It has no relationship to trees, so I think perhaps you're
confusing it with a different pattern. From the GoF book:

Chain of Responsibility
Avoid coupling the sender of a request to its receiver by giving more
than one object a chance to handle the request. Chain the receiving
objects and pass the request along the chain until an object handles
it.

This doesn't seem to me to be related to the problem you are trying to solve.

--
Martin Cooper


> 
> ---------------------------------------------------------------------
> 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] fixed, one-way chains, only?

Posted by tm...@nitwit.de.
On Monday 14 March 2005 06:02, Craig McClanahan wrote:
> Commons Chain isn't about parsing documents, it is about executing
> commands.  If you are after converting your XML document into some

It a pattern. It about what I want to use it for. 

> sort of data structure, you probably want to look at Commons Digester
> instead.

No, I'm not after parsing XML I'm about parsing a file format that has some 
kind of a tree structure and which a chain would perfectly match - if I had 
the possibility to buidl the chain in a tree structure as well. I also think 
that this would be a smart extension of the pattern.

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


Re: [chain] fixed, one-way chains, only?

Posted by Craig McClanahan <cr...@gmail.com>.
Commons Chain isn't about parsing documents, it is about executing
commands.  If you are after converting your XML document into some
sort of data structure, you probably want to look at Commons Digester
instead.

Craig


On Sun, 13 Mar 2005 17:43:40 +0100, tmp@nitwit.de <tm...@nitwit.de> wrote:
> Hi!
> 
> I yet only had an quick look at Commons Chains. Am I right that a GoF/Commons
> chain does have a fixed one-way flow, only? I want to use the lib in order to
> parse the iTunesDB which looks like this
> (http://www.ipodlinux.org/ITunesDB#iTunesDB_file):
> 
> <mhbd> - This is a database
>   <mhsd> - This is a list holder, which holds either a mhlt or an mhlp
>     <mhlt> - This holds a list of all the songs on the iPod
>       <mhit> - This describes a particular song
>         <mhod>... - These hold strings associated with a song
>         <mhod>... - Things like Artist, Song Title, Album, etc.
>       <mhit> - This is another song. And so on.
>         <mhod>...
>         <mhod>...
>       ...
>   <mhsd> - Here's the list holder again.. This time, it's holding an mhlp
>     <mhlp> - This holds a bunch of playlists. In fact, all the playlists.
>       <mhyp> - This is a playlist.
>         <mhod>... - These mhods hold info about the playlists like the name of
> the list.
>         <mhip>... - This mhip holds a reference to a particular song on the
> iPod.
>         ...
>       <mhyp> - This is another playlist. And so on.
>         <mhod>... - Note that the mhods also hold other things for smart
> playlists
>         <mhip>...
>         ...
>       ...
> 
> As you can see, it's not mhdb -> mhsd -> mhlt but the flow may also be mhbd ->
> mhsd -> mhlp. And esp. mhod is used everywhere. So, what I need is something
> like the struts config. This cannot be done with Commons Chain, can it?
> 
> ---------------------------------------------------------------------
> 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