%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.quartz.CronTriggerTag |
|
|
1 | package org.apache.commons.jelly.tags.quartz; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2002,2004 The Apache Software Foundation. |
|
5 | * |
|
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
7 | * you may not use this file except in compliance with the License. |
|
8 | * You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
17 | */ |
|
18 | ||
19 | import java.text.ParseException; |
|
20 | ||
21 | import org.apache.commons.jelly.JellyTagException; |
|
22 | import org.apache.commons.jelly.XMLOutput; |
|
23 | import org.apache.commons.jelly.MissingAttributeException; |
|
24 | ||
25 | import org.quartz.CronTrigger; |
|
26 | import org.quartz.Scheduler; |
|
27 | import org.quartz.SchedulerException; |
|
28 | ||
29 | import java.util.Date; |
|
30 | ||
31 | /** Define a trigger using a cron time spec. |
|
32 | * |
|
33 | * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> |
|
34 | */ |
|
35 | public class CronTriggerTag extends QuartzTagSupport |
|
36 | { |
|
37 | // ------------------------------------------------------------ |
|
38 | // Instance members |
|
39 | // ------------------------------------------------------------ |
|
40 | ||
41 | /** Cron time spec. */ |
|
42 | private String spec; |
|
43 | ||
44 | /** Trigger name. */ |
|
45 | private String name; |
|
46 | ||
47 | /** Trigger group. */ |
|
48 | private String group; |
|
49 | ||
50 | /** Job name. */ |
|
51 | private String jobName; |
|
52 | ||
53 | /** Job group. */ |
|
54 | private String jobGroup; |
|
55 | ||
56 | // ------------------------------------------------------------ |
|
57 | // COnstructors |
|
58 | // ------------------------------------------------------------ |
|
59 | ||
60 | /** Construct. |
|
61 | */ |
|
62 | public CronTriggerTag() |
|
63 | 0 | { |
64 | // intentionally left blank. |
|
65 | 0 | } |
66 | ||
67 | // ------------------------------------------------------------ |
|
68 | // ------------------------------------------------------------ |
|
69 | ||
70 | /** Set the name. |
|
71 | * |
|
72 | * @param name. |
|
73 | */ |
|
74 | public void setName(String name) |
|
75 | { |
|
76 | 0 | this.name = name; |
77 | 0 | } |
78 | ||
79 | /** Retrieve the name. |
|
80 | * |
|
81 | * @return The name. |
|
82 | */ |
|
83 | public String getName() |
|
84 | { |
|
85 | 0 | return this.name; |
86 | } |
|
87 | ||
88 | /** Set the group |
|
89 | * |
|
90 | * @param group The group |
|
91 | */ |
|
92 | public void setGroup(String group) |
|
93 | { |
|
94 | 0 | this.group = group; |
95 | 0 | } |
96 | ||
97 | /** Retrieve the group. |
|
98 | * |
|
99 | * @return The group. |
|
100 | */ |
|
101 | public String getGroup() |
|
102 | { |
|
103 | 0 | return this.group; |
104 | } |
|
105 | ||
106 | /** Set the cron time spec. |
|
107 | * |
|
108 | * @param spec The cron time spec. |
|
109 | */ |
|
110 | public void setSpec(String spec) |
|
111 | { |
|
112 | 0 | this.spec = spec; |
113 | 0 | } |
114 | ||
115 | /** Retrieve the cron time spec. |
|
116 | * |
|
117 | * @param spec The cron time spec. |
|
118 | */ |
|
119 | public String getSpec() |
|
120 | { |
|
121 | 0 | return this.spec; |
122 | } |
|
123 | ||
124 | /** Set the job name. |
|
125 | * |
|
126 | * @param jobName The job name. |
|
127 | */ |
|
128 | public void setJobName(String jobName) |
|
129 | { |
|
130 | 0 | this.jobName = jobName; |
131 | 0 | } |
132 | ||
133 | /** Retrieve the job name. |
|
134 | * |
|
135 | * @return The job name. |
|
136 | */ |
|
137 | public String getJobName() |
|
138 | { |
|
139 | 0 | return this.jobName; |
140 | } |
|
141 | ||
142 | /** Set the job group. |
|
143 | * |
|
144 | * @param jobGroup The job group. |
|
145 | */ |
|
146 | public void setJobGroup(String jobGroup) |
|
147 | { |
|
148 | 0 | this.jobGroup = jobGroup; |
149 | 0 | } |
150 | ||
151 | /** Retrieve the job group. |
|
152 | * |
|
153 | * @return The job group. |
|
154 | */ |
|
155 | public String getJobGroup() |
|
156 | { |
|
157 | 0 | return this.jobGroup; |
158 | } |
|
159 | ||
160 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
161 | // org.apache.commons.jelly.Tag |
|
162 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
163 | ||
164 | /** Perform this tag. |
|
165 | * |
|
166 | * @param output Output sink. |
|
167 | * |
|
168 | * @throws Exception If an error occurs. |
|
169 | */ |
|
170 | public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException |
|
171 | { |
|
172 | 0 | if ( getSpec() == null ) |
173 | { |
|
174 | 0 | throw new MissingAttributeException( "spec" ); |
175 | } |
|
176 | ||
177 | 0 | if ( getName() == null ) |
178 | { |
|
179 | 0 | throw new MissingAttributeException( "name" ); |
180 | } |
|
181 | ||
182 | 0 | if ( getGroup() == null ) |
183 | { |
|
184 | 0 | throw new MissingAttributeException( "group" ); |
185 | } |
|
186 | ||
187 | 0 | if ( getJobName() == null ) |
188 | { |
|
189 | 0 | throw new MissingAttributeException( "jobName" ); |
190 | } |
|
191 | ||
192 | 0 | if ( getJobGroup() == null ) |
193 | { |
|
194 | 0 | throw new MissingAttributeException( "jobGroup" ); |
195 | } |
|
196 | ||
197 | 0 | CronTrigger trigger = new CronTrigger( getName(), |
198 | getGroup() ); |
|
199 | try { |
|
200 | 0 | trigger.setCronExpression( getSpec() ); |
201 | 0 | } |
202 | catch (ParseException e) { |
|
203 | 0 | throw new JellyTagException(e); |
204 | } |
|
205 | 0 | trigger.setJobName( getJobName() ); |
206 | 0 | trigger.setJobGroup( getJobGroup() ); |
207 | 0 | trigger.setStartTime( new Date() ); |
208 | ||
209 | try { |
|
210 | 0 | Scheduler sched = getScheduler(); |
211 | 0 | sched.scheduleJob( trigger ); |
212 | 0 | } |
213 | catch (SchedulerException e) { |
|
214 | 0 | throw new JellyTagException(e); |
215 | } |
|
216 | 0 | } |
217 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |