Good idea. I tried this, but failed.

When my component is looked up, I try to fetch the objectModel (to get the
context as you suggested). Therefore I implement Contextualizable:

public void contextualize(Context context) {
        Map objectModel = ContextHelper.getObjectModel(context);
        HttpContext cocoonContext = (HttpContext)
ObjectModelHelper.getContext(objectModel);
        cocoonContext.setAttribute("AdaptationManager", this);
    }

This leads to the following exception:

org.apache.avalon.framework.CascadingRuntimeException: Unable to get the
object model from the context.
        at
org.apache.cocoon.components.ContextHelper.getObjectModel(ContextHelper.java
:91)
...

Caused by: org.apache.avalon.framework.context.ContextException: Unable to
locate object-model (No environment available)
        at
org.apache.cocoon.components.ComponentContext.get(ComponentContext.java:95)
        at
org.apache.cocoon.components.ContextHelper.getObjectModel(ContextHelper.java
:89)


Stefan

| -----Ursprüngliche Nachricht-----
| Von: Jean-Baptiste Quenot [mailto:[EMAIL PROTECTED]
| Gesendet: Mittwoch, 14. Dezember 2005 12:44
| An: [email protected]
| Betreff: Re: How to connect Avalon Component and SessionListener
| 
| * Stefan Pietschmann:
| 
| > I want to notify my Avalon component when a session is created or
| destroyed.
| 
| In your listener, you have access to the servlet context, in which
| you can set and get attributes:
| 
|         public void sessionCreated(HttpSessionEvent event) {
| 
| ((MyComponent)event.getSession().getServletContext().getAttribute("MyCompo
| nent")).someMethod()
|         }
| 
| And in your component:
| 
|         HttpContext context = (HttpContext)
| ObjectModelHelper.getContext(objectModel);
|         context.setAttribute("MyComponent", this);
| 
| Best regards,
| --
| Jean-Baptiste Quenot
| Systèmes d'Information
| ANYWARE TECHNOLOGIES
| Tel : +33 (0)5 61 00 52 90
| Fax : +33 (0)5 61 00 51 46
| http://www.anyware-tech.com/