You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Owen Tallman <ow...@gmail.com> on 2005/08/02 19:04:48 UTC

Accessing App Context from a CronJob

Hello,

>From a CronJob componentI need to access our ApplicationContext object
which gets initialized by a ServletContextListener before Cocoon
starts. If this were a sitemap component, it would have a setup method
that got called with an ObjectModel map, so I could call

ObjectModelHelper.getContext(objectModel);

The class I defined has this derivation:

public class FakeJob extends ServiceableCronJob
                         implements Configurable, ConfigurableCronJob { ...


it has a setup() method which takes  parameters and a map, but if I
don't initialize the job entry with them, they don't have any values. 
How can I access the context from a component like this?

Thanks in advance for any suggestions,

Owen

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Accessing App Context from a CronJob

Posted by footh <fo...@yahoo.com>.
no problem, I spent many hours over the last week
poring over documents and code to figure out something
very similar.  The least I could do was spare someone
else the headache (although I did learn alot).

--- Owen Tallman <ow...@gmail.com> wrote:

> Excellent! I don't know how long I would have had to
> grope around to
> figure that out. Thanks!
> 
> For the record, here's a code snippet of the working
> result, after
> adding the Contextualizable interface:
> 
>         // org.apache.cocoon.environment.Context
> (not Avalon context)
>         private Context cocoonContext = null;
>    
>         /**
>          * Let the container pass me the Avalon
> context
>          */
>         public void
>
contextualize(org.apache.avalon.framework.context.Context
> context) {
> 
>             Map objectModel =
> ContextHelper.getObjectModel(context);
>             this.cocoonContext =
> ObjectModelHelper.getContext(objectModel);
>             logger.info("contextualize()
> completed");
>         }
> 
> On 8/2/05, footh <fo...@yahoo.com> wrote:
> > Try implementing the Contextualizable interface
> which
> > will give you the Avalon context.
> > 
> > Then call the "getObjectModel" static method of
> the
> > ContextHelper class and pass in the Avalon
> context.
> > 
> > From there you can use your ObjectModelHelper, or
> just
> > retrieve the object returned in the Map that is
> under
> > the "context" key.
> > 
> > --- Owen Tallman <ow...@gmail.com> wrote:
> > 
> > > Hello,
> > >
> > > From a CronJob componentI need to access our
> > > ApplicationContext object
> > > which gets initialized by a
> ServletContextListener
> > > before Cocoon
> > > starts. If this were a sitemap component, it
> would
> > > have a setup method
> > > that got called with an ObjectModel map, so I
> could
> > > call
> > >
> > > ObjectModelHelper.getContext(objectModel);
> > >
> > > The class I defined has this derivation:
> > >
> > > public class FakeJob extends ServiceableCronJob
> > >                          implements
> Configurable,
> > > ConfigurableCronJob { ...
> > >
> > >
> > > it has a setup() method which takes  parameters
> and
> > > a map, but if I
> > > don't initialize the job entry with them, they
> don't
> > > have any values.
> > > How can I access the context from a component
> like
> > > this?
> > >
> > > Thanks in advance for any suggestions,
> > >
> > > Owen
> > >
> > >
> >
>
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > > users-unsubscribe@cocoon.apache.org
> > > For additional commands, e-mail:
> > > users-help@cocoon.apache.org
> > >
> > >
> > 
> > 
> > 
> > 
> > __________________________________
> > Yahoo! Mail for Mobile
> > Take Yahoo! Mail with you! Check email on your
> mobile phone.
> > http://mobile.yahoo.com/learn/mail
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail:
> users-help@cocoon.apache.org
> > 
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail:
> users-help@cocoon.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Accessing App Context from a CronJob

Posted by Owen Tallman <ow...@gmail.com>.
Excellent! I don't know how long I would have had to grope around to
figure that out. Thanks!

For the record, here's a code snippet of the working result, after
adding the Contextualizable interface:

        // org.apache.cocoon.environment.Context (not Avalon context)
        private Context cocoonContext = null;
   
        /**
         * Let the container pass me the Avalon context
         */
        public void
contextualize(org.apache.avalon.framework.context.Context context) {

            Map objectModel = ContextHelper.getObjectModel(context);
            this.cocoonContext = ObjectModelHelper.getContext(objectModel);
            logger.info("contextualize() completed");
        }

On 8/2/05, footh <fo...@yahoo.com> wrote:
> Try implementing the Contextualizable interface which
> will give you the Avalon context.
> 
> Then call the "getObjectModel" static method of the
> ContextHelper class and pass in the Avalon context.
> 
> From there you can use your ObjectModelHelper, or just
> retrieve the object returned in the Map that is under
> the "context" key.
> 
> --- Owen Tallman <ow...@gmail.com> wrote:
> 
> > Hello,
> >
> > From a CronJob componentI need to access our
> > ApplicationContext object
> > which gets initialized by a ServletContextListener
> > before Cocoon
> > starts. If this were a sitemap component, it would
> > have a setup method
> > that got called with an ObjectModel map, so I could
> > call
> >
> > ObjectModelHelper.getContext(objectModel);
> >
> > The class I defined has this derivation:
> >
> > public class FakeJob extends ServiceableCronJob
> >                          implements Configurable,
> > ConfigurableCronJob { ...
> >
> >
> > it has a setup() method which takes  parameters and
> > a map, but if I
> > don't initialize the job entry with them, they don't
> > have any values.
> > How can I access the context from a component like
> > this?
> >
> > Thanks in advance for any suggestions,
> >
> > Owen
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail:
> > users-help@cocoon.apache.org
> >
> >
> 
> 
> 
> 
> __________________________________
> Yahoo! Mail for Mobile
> Take Yahoo! Mail with you! Check email on your mobile phone.
> http://mobile.yahoo.com/learn/mail
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Accessing App Context from a CronJob

Posted by footh <fo...@yahoo.com>.
Try implementing the Contextualizable interface which
will give you the Avalon context.

Then call the "getObjectModel" static method of the
ContextHelper class and pass in the Avalon context.

>From there you can use your ObjectModelHelper, or just
retrieve the object returned in the Map that is under
the "context" key.

--- Owen Tallman <ow...@gmail.com> wrote:

> Hello,
> 
> From a CronJob componentI need to access our
> ApplicationContext object
> which gets initialized by a ServletContextListener
> before Cocoon
> starts. If this were a sitemap component, it would
> have a setup method
> that got called with an ObjectModel map, so I could
> call
> 
> ObjectModelHelper.getContext(objectModel);
> 
> The class I defined has this derivation:
> 
> public class FakeJob extends ServiceableCronJob
>                          implements Configurable,
> ConfigurableCronJob { ...
> 
> 
> it has a setup() method which takes  parameters and
> a map, but if I
> don't initialize the job entry with them, they don't
> have any values. 
> How can I access the context from a component like
> this?
> 
> Thanks in advance for any suggestions,
> 
> Owen
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail:
> users-help@cocoon.apache.org
> 
> 



		
__________________________________ 
Yahoo! Mail for Mobile 
Take Yahoo! Mail with you! Check email on your mobile phone. 
http://mobile.yahoo.com/learn/mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org