01: /*
02: * Copyright 2007 Paolo Spizzirri (paolo.spizzirri@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.romaframework.module.schedulerquartz.command;
18:
19: import org.quartz.Job;
20: import org.quartz.JobExecutionContext;
21: import org.quartz.JobExecutionException;
22: import org.romaframework.core.command.Command;
23: import org.romaframework.core.command.CommandContext;
24:
25: /**
26: *
27: * @author Paolo Spizzirri (paolo.spizzirri@assetdata.it)
28: *
29: */
30: public class CommandJobDelegate implements Job {
31:
32: private static CommandJobDelegate instance = new CommandJobDelegate();
33:
34: public static final String PAR_COMMAND = "command";
35:
36: public static final String PAR_CONTEXT = "jobExecutionContext";
37:
38: /**
39: * Delegates the execution to the Command implementation.
40: */
41: public void execute(JobExecutionContext iContext)
42: throws JobExecutionException {
43: Command command = (Command) iContext.getJobDetail()
44: .getJobDataMap().get(PAR_COMMAND);
45:
46: // SET QUARTZ CONTEXT AS PARAMETER TO BEING USED BY COMMAND
47: CommandContext ctx = (CommandContext) iContext.getJobDetail()
48: .getJobDataMap().get(PAR_CONTEXT);
49: if (ctx == null)
50: ctx = new CommandContext();
51: ctx.setParameter(PAR_CONTEXT, iContext);
52:
53: command.execute(ctx);
54: }
55:
56: /**
57: * Singleton
58: *
59: * @return Always the same CommandJobDelegate instance
60: */
61: public CommandJobDelegate getInstance() {
62: return instance;
63: }
64: }
|