KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > cron > CocoonQuartzJobExecutor


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.cron;
17
18 import java.net.MalformedURLException JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.avalon.framework.component.WrapperComponentManager;
22 import org.apache.avalon.framework.context.ContextException;
23 import org.apache.avalon.framework.parameters.Parameters;
24 import org.apache.avalon.framework.service.ServiceException;
25 import org.apache.cocoon.Constants;
26 import org.apache.cocoon.Processor;
27 import org.apache.cocoon.components.CocoonComponentManager;
28 import org.apache.cocoon.environment.ObjectModelHelper;
29 import org.apache.cocoon.environment.Request;
30 import org.apache.cocoon.environment.background.BackgroundEnvironment;
31 import org.quartz.JobDataMap;
32 import org.quartz.JobExecutionException;
33
34 /**
35  * This component is resposible to launch a {@link CronJob}s in a Quart Scheduler.
36  *
37  * @author <a HREF="mailto:giacomo@apache.org">Giacomo Pati</a>
38  * @version CVS $Id: CocoonQuartzJobExecutor.java 291649 2005-09-26 16:05:33Z sylvain $
39  *
40  * @since 2.1.1
41  */

42 public class CocoonQuartzJobExecutor extends QuartzJobExecutor {
43
44     private Object JavaDoc m_key;
45     private BackgroundEnvironment m_env;
46     private Processor m_processor;
47
48     protected void setup(JobDataMap data) throws JobExecutionException {
49         super.setup(data);
50         org.apache.cocoon.environment.Context envContext;
51         try {
52             envContext =
53                 (org.apache.cocoon.environment.Context) m_context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
54         } catch (ContextException e) {
55             throw new JobExecutionException(e);
56         }
57         
58         try {
59             m_env = new BackgroundEnvironment(m_logger, envContext);
60         } catch (MalformedURLException JavaDoc e) {
61             // Unlikely to happen
62
throw new JobExecutionException(e);
63         }
64
65         Request req = ObjectModelHelper.getRequest(m_env.getObjectModel());
66         Map JavaDoc objects = (Map JavaDoc)data.get(QuartzJobScheduler.DATA_MAP_OBJECTMAP);
67         if (objects != null) {
68             req.setAttribute("cron-objectmap", objects);
69         }
70
71         Parameters params = (Parameters)data.get(QuartzJobScheduler.DATA_MAP_PARAMETERS);
72         if (params != null) {
73             req.setAttribute("cron-parameters", params);
74         }
75         
76         try {
77             m_processor = (Processor) m_manager.lookup(Processor.ROLE);
78         } catch (ServiceException e) {
79             throw new JobExecutionException(e);
80         }
81
82         m_key = CocoonComponentManager.startProcessing(m_env);
83         CocoonComponentManager.enterEnvironment(m_env, new WrapperComponentManager(m_manager), m_processor);
84     }
85
86     protected void release(JobDataMap data) {
87         super.release(data);
88         CocoonComponentManager.leaveEnvironment();
89         CocoonComponentManager.endProcessing(m_env, m_key);
90         if (m_manager != null) {
91             m_manager.release(m_processor);
92         }
93     }
94
95 }
96
Popular Tags