1 16 package org.apache.cocoon.components.cron; 17 18 import java.net.MalformedURLException ; 19 import java.util.Map ; 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 42 public class CocoonQuartzJobExecutor extends QuartzJobExecutor { 43 44 private Object 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 e) { 61 throw new JobExecutionException(e); 63 } 64 65 Request req = ObjectModelHelper.getRequest(m_env.getObjectModel()); 66 Map objects = (Map )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 |