You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Carsten Ziegeler <cz...@apache.org> on 2005/04/15 16:07:15 UTC

[RT] Sitemap Listeners

I while ago we briefly discussed the idea of sitemap listeners that are
invoked each time a sitemap is entered/left.

Our 2.2 code base contains a first implementation which can be seen as a
very simple base for this feature. I think it's time now to discuss this
further.

1. Configuration

You can define listeners in the map:components section in a sitemap with:
<map:listeners>
  <map:listener role="Some Avalon role"/>
  <map:listener class="A class"/>
</map:listeners>

So you can either use a configured component or define a class and then
an instance of this class is created (using the per sitemap
classloader). In both cases the listener must be thread safe.

2. Listeners and Events

Currently there are two listener types defined (in o.a.c.sitemap):

public interface EnterSitemapEventListener extends SitemapListener {

    void enteredSitemap(EnterSitemapEvent event);
}
public interface LeaveSitemapEventListener extends SitemapListener {

    void leftSitemap(LeaveSitemapEvent event);
}

the events currently only contain the Processor (= Sitemap) and the
current Environment.

3. Listener Invocation

Each EnterSitemapEventListener is invoked for each request entering a
sitemap and of course the LeaveSitemapEventListener each time a request
leaves a sitemap. There is no distinction between internal and external
processing yet: in the case of internal processing, the listeners are
invoked during the construction phase.


The listener interfaces need some more information, like if a request
was handled by this sitemap, if an error occured etc. and we should
define when the listeners are invoked, especially for internal requests.

WDYT?

BTW, I'm using the listeners in the spring-app block to store the
current application context (the per sitemap context) in a request
attribute.

Carsten

-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: [RT] Sitemap Listeners

Posted by Ralph Goers <Ra...@dslextreme.com>.
Carsten Ziegeler wrote:

>2. Listeners and Events
>
>Currently there are two listener types defined (in o.a.c.sitemap):
>
>public interface EnterSitemapEventListener extends SitemapListener {
>
>    void enteredSitemap(EnterSitemapEvent event);
>}
>public interface LeaveSitemapEventListener extends SitemapListener {
>
>    void leftSitemap(LeaveSitemapEvent event);
>}
>
>the events currently only contain the Processor (= Sitemap) and the
>current Environment.
>  
>
This looks really good!  One other listener that might be handy is an 
exception listener.  I know there is already the handle-errors, but this 
could be useful just for auditing purposes.

Ralph


Re: [RT] Sitemap Listeners

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Carsten Ziegeler wrote:
> Tony Collen wrote:
> 
>>Carsten Ziegeler wrote:
>>
>>
>>
>>>Yes, it is fired after the processing - when the serializer/reader is
>>>finished. I'm not sure what you mean with your second sentence?
>>>
>>
>>
>>Carsten, check out:
>>
>>http://www.hibernate.org/43.html
>>
> 
> Thanks Tony. so I assume Leszek wants to close the session in the
> listener (and not open), right?
> 
exactly

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
Project Manager                                    MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Re: [RT] Sitemap Listeners

Posted by Carsten Ziegeler <cz...@apache.org>.
Tony Collen wrote:
> Carsten Ziegeler wrote:
> 
> 
>>Yes, it is fired after the processing - when the serializer/reader is
>>finished. I'm not sure what you mean with your second sentence?
>>
> 
> 
> Carsten, check out:
> 
> http://www.hibernate.org/43.html
> 
Thanks Tony. so I assume Leszek wants to close the session in the
listener (and not open), right?

-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: [RT] Sitemap Listeners

Posted by Tony Collen <co...@umn.edu>.
Carsten Ziegeler wrote:

> 
> Yes, it is fired after the processing - when the serializer/reader is
> finished. I'm not sure what you mean with your second sentence?
> 

Carsten, check out:

http://www.hibernate.org/43.html

Tony

> Carsten
> 


Re: [RT] Sitemap Listeners

Posted by Carsten Ziegeler <cz...@apache.org>.
Leszek Gawron wrote:
> Carsten Ziegeler wrote:
> 
>>I while ago we briefly discussed the idea of sitemap listeners that are
>>invoked each time a sitemap is entered/left.
>>
>>Our 2.2 code base contains a first implementation which can be seen as a
>>very simple base for this feature. I think it's time now to discuss this
>>further.
>>
>>1. Configuration
>>
>>You can define listeners in the map:components section in a sitemap with:
>><map:listeners>
>>  <map:listener role="Some Avalon role"/>
>>  <map:listener class="A class"/>
>></map:listeners>
>>
>>So you can either use a configured component or define a class and then
>>an instance of this class is created (using the per sitemap
>>classloader). In both cases the listener must be thread safe.
>>
>>2. Listeners and Events
>>
>>Currently there are two listener types defined (in o.a.c.sitemap):
>>
>>public interface EnterSitemapEventListener extends SitemapListener {
>>
>>    void enteredSitemap(EnterSitemapEvent event);
>>}
>>public interface LeaveSitemapEventListener extends SitemapListener {
>>
>>    void leftSitemap(LeaveSitemapEvent event);
>>}
> 
> is left sitemap fired after the request has been processed? I mean can I 
> implement open session in view pattern using your listener?
> 
Yes, it is fired after the processing - when the serializer/reader is
finished. I'm not sure what you mean with your second sentence?

Carsten

-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: [RT] Sitemap Listeners

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Carsten Ziegeler wrote:
> I while ago we briefly discussed the idea of sitemap listeners that are
> invoked each time a sitemap is entered/left.
> 
> Our 2.2 code base contains a first implementation which can be seen as a
> very simple base for this feature. I think it's time now to discuss this
> further.
> 
> 1. Configuration
> 
> You can define listeners in the map:components section in a sitemap with:
> <map:listeners>
>   <map:listener role="Some Avalon role"/>
>   <map:listener class="A class"/>
> </map:listeners>
> 
> So you can either use a configured component or define a class and then
> an instance of this class is created (using the per sitemap
> classloader). In both cases the listener must be thread safe.
> 
> 2. Listeners and Events
> 
> Currently there are two listener types defined (in o.a.c.sitemap):
> 
> public interface EnterSitemapEventListener extends SitemapListener {
> 
>     void enteredSitemap(EnterSitemapEvent event);
> }
> public interface LeaveSitemapEventListener extends SitemapListener {
> 
>     void leftSitemap(LeaveSitemapEvent event);
> }
is left sitemap fired after the request has been processed? I mean can I 
implement open session in view pattern using your listener?

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Re: [RT] Sitemap Listeners

Posted by Ralph Goers <Ra...@dslextreme.com>.
Carsten Ziegeler wrote:

>Giacomo Pati wrote:
>
>  
>
>>Why two separate interfaces?
>>
>>    
>>
>We have two different events and someone might only be interested in one
>of the two events. If your component needs both it can simply implement
>both interfaces.
>Separating the interfaces makes it a little bit easier to add new events
>later on: a new event is then an additional interface. If we would use
>one interface, adding a new event would require to change the interface
>which is incompatible then.
>I know we could solve such problems with abstract classes as well. So
>it's a matter of like/dislike of one particular solution. I personally
>don't care how we do it. I like the separate interface approach more,
>but we can have one single interface as well.
>
>Carsten
>  
>
FWIW, I prefer how you implemented it.  It makes maintaining binary 
compatibility easier.

Ralph


Re: [RT] Sitemap Listeners

Posted by Carsten Ziegeler <cz...@apache.org>.
Giacomo Pati wrote:

> 
> Why two separate interfaces?
> 
We have two different events and someone might only be interested in one
of the two events. If your component needs both it can simply implement
both interfaces.
Separating the interfaces makes it a little bit easier to add new events
later on: a new event is then an additional interface. If we would use
one interface, adding a new event would require to change the interface
which is incompatible then.
I know we could solve such problems with abstract classes as well. So
it's a matter of like/dislike of one particular solution. I personally
don't care how we do it. I like the separate interface approach more,
but we can have one single interface as well.

Carsten

-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: [RT] Sitemap Listeners

Posted by Giacomo Pati <gi...@apache.org>.
On Fri, Apr 15, 2005 at 04:07:15PM +0200, Carsten Ziegeler wrote:
> I while ago we briefly discussed the idea of sitemap listeners that are
> invoked each time a sitemap is entered/left.
> 
> Our 2.2 code base contains a first implementation which can be seen as a
> very simple base for this feature. I think it's time now to discuss this
> further.
> 
> 1. Configuration
> 
> You can define listeners in the map:components section in a sitemap with:
> <map:listeners>
>   <map:listener role="Some Avalon role"/>
>   <map:listener class="A class"/>
> </map:listeners>
> 
> So you can either use a configured component or define a class and then
> an instance of this class is created (using the per sitemap
> classloader). In both cases the listener must be thread safe.
> 
> 2. Listeners and Events
> 
> Currently there are two listener types defined (in o.a.c.sitemap):
> 
> public interface EnterSitemapEventListener extends SitemapListener {
> 
>     void enteredSitemap(EnterSitemapEvent event);
> }
> public interface LeaveSitemapEventListener extends SitemapListener {
> 
>     void leftSitemap(LeaveSitemapEvent event);
> }

Why two separate interfaces?

Ciao
 
-- 
Giacomo Pati
Otego AG, Switzerland - http://www.otego.com
Orixo, the XML business alliance - http://www.orixo.com

Re: [RT] Sitemap Listeners

Posted by Thorsten Scherler <th...@apache.org>.
On Fri, 2005-04-15 at 16:07 +0200, Carsten Ziegeler wrote:
> I while ago we briefly discussed the idea of sitemap listeners that are
> invoked each time a sitemap is entered/left.
> 
> Our 2.2 code base contains a first implementation which can be seen as a
> very simple base for this feature. I think it's time now to discuss this
> further.
> 
> 1. Configuration
> 
> You can define listeners in the map:components section in a sitemap with:
> <map:listeners>
>   <map:listener role="Some Avalon role"/>
>   <map:listener class="A class"/>
> </map:listeners>

> WDYT?

Maybe this is a stupid question but could this be extended to <map:match
pattern=""/>.

Ok, one could implement it via the implementation of 
public interface EnterSitemapEventListener extends SitemapListener {

    void enteredSitemap(EnterSitemapEvent event);
}

...but this would lead to extract the requests in the java classes but
IMO that is not an elegant solution.

The idea would be 
<map:match pattern="prepare.include.**" listener="viewListener.class">
 <map:generate src="cocoon:/prepare.view.{1}"/>
 <map:transform src="resources/stylesheets/prepare.include.xsl">
   <map:parameter name="config-file" value="{project:skinconf}"/>
 </map:transform>
 <map:serialize type="xml"/>
</map:match>

With
public interface EnterMapEventListener extends MapListener {

    void enteredSitemap(EnterSitemapEvent event);
}

WDYT?

salu2
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)