1 package org.apache.commons.jelly.tags.quartz;
2
3 /*
4 * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/quartz/CronTriggerTag.java,v 1.1 2002/07/25 01:51:20 werken Exp $
5 * $Revision: 1.1 $
6 * $Date: 2002/07/25 01:51:20 $
7 *
8 * ====================================================================
9 *
10 * The Apache Software License, Version 1.1
11 *
12 * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
13 * reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 *
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 *
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in
24 * the documentation and/or other materials provided with the
25 * distribution.
26 *
27 * 3. The end-user documentation included with the redistribution, if
28 * any, must include the following acknowlegement:
29 * "This product includes software developed by the
30 * Apache Software Foundation (http://www.apache.org/)."
31 * Alternately, this acknowlegement may appear in the software itself,
32 * if and wherever such third-party acknowlegements normally appear.
33 *
34 * 4. The names "The Jakarta Project", "Commons", and "Apache Software
35 * Foundation" must not be used to endorse or promote products derived
36 * from this software without prior written permission. For written
37 * permission, please contact apache@apache.org.
38 *
39 * 5. Products derived from this software may not be called "Apache"
40 * nor may "Apache" appear in their names without prior written
41 * permission of the Apache Group.
42 *
43 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
44 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
45 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
47 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
50 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
51 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
52 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 * ====================================================================
56 *
57 * This software consists of voluntary contributions made by many
58 * individuals on behalf of the Apache Software Foundation. For more
59 * information on the Apache Software Foundation, please see
60 * <http://www.apache.org/>.
61 *
62 */
63
64 import org.apache.commons.jelly.XMLOutput;
65 import org.apache.commons.jelly.MissingAttributeException;
66
67 import org.quartz.CronTrigger;
68 import org.quartz.Scheduler;
69
70 import java.util.Date;
71
72 /*** Define a trigger using a cron time spec.
73 *
74 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
75 */
76 public class CronTriggerTag extends QuartzTagSupport
77 {
78 // ------------------------------------------------------------
79 // Instance members
80 // ------------------------------------------------------------
81
82 /*** Cron time spec. */
83 private String spec;
84
85 /*** Trigger name. */
86 private String name;
87
88 /*** Trigger group. */
89 private String group;
90
91 /*** Job name. */
92 private String jobName;
93
94 /*** Job group. */
95 private String jobGroup;
96
97 // ------------------------------------------------------------
98 // COnstructors
99 // ------------------------------------------------------------
100
101 /*** Construct.
102 */
103 public CronTriggerTag()
104 {
105 // intentionally left blank.
106 }
107
108 // ------------------------------------------------------------
109 // ------------------------------------------------------------
110
111 /*** Set the name.
112 *
113 * @param name.
114 */
115 public void setName(String name)
116 {
117 this.name = name;
118 }
119
120 /*** Retrieve the name.
121 *
122 * @return The name.
123 */
124 public String getName()
125 {
126 return this.name;
127 }
128
129 /*** Set the group
130 *
131 * @param group The group
132 */
133 public void setGroup(String group)
134 {
135 this.group = group;
136 }
137
138 /*** Retrieve the group.
139 *
140 * @return The group.
141 */
142 public String getGroup()
143 {
144 return this.group;
145 }
146
147 /*** Set the cron time spec.
148 *
149 * @param spec The cron time spec.
150 */
151 public void setSpec(String spec)
152 {
153 this.spec = spec;
154 }
155
156 /*** Retrieve the cron time spec.
157 *
158 * @param spec The cron time spec.
159 */
160 public String getSpec()
161 {
162 return this.spec;
163 }
164
165 /*** Set the job name.
166 *
167 * @param jobName The job name.
168 */
169 public void setJobName(String jobName)
170 {
171 this.jobName = jobName;
172 }
173
174 /*** Retrieve the job name.
175 *
176 * @return The job name.
177 */
178 public String getJobName()
179 {
180 return this.jobName;
181 }
182
183 /*** Set the job group.
184 *
185 * @param jobGroup The job group.
186 */
187 public void setJobGroup(String jobGroup)
188 {
189 this.jobGroup = jobGroup;
190 }
191
192 /*** Retrieve the job group.
193 *
194 * @return The job group.
195 */
196 public String getJobGroup()
197 {
198 return this.jobGroup;
199 }
200
201 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
202 // org.apache.commons.jelly.Tag
203 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
204
205 /*** Perform this tag.
206 *
207 * @param output Output sink.
208 *
209 * @throws Exception If an error occurs.
210 */
211 public void doTag(XMLOutput output) throws Exception
212 {
213 if ( getSpec() == null )
214 {
215 throw new MissingAttributeException( "spec" );
216 }
217
218 if ( getName() == null )
219 {
220 throw new MissingAttributeException( "name" );
221 }
222
223 if ( getGroup() == null )
224 {
225 throw new MissingAttributeException( "group" );
226 }
227
228 if ( getJobName() == null )
229 {
230 throw new MissingAttributeException( "jobName" );
231 }
232
233 if ( getJobGroup() == null )
234 {
235 throw new MissingAttributeException( "jobGroup" );
236 }
237
238 CronTrigger trigger = new CronTrigger( getName(),
239 getGroup() );
240
241 trigger.setCronExpression( getSpec() );
242 trigger.setJobName( getJobName() );
243 trigger.setJobGroup( getJobGroup() );
244 trigger.setStartTime( new Date() );
245 Scheduler sched = getScheduler();
246 sched.scheduleJob( trigger );
247 }
248 }
This page was automatically generated by Maven