001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2007 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: StandardSchedule.java 6905 2007-04-19 03:05:32Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.scheduler;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.jdom.Element;
029: import org.quartz.CronExpression;
030:
031: public class StandardSchedule implements ISchedule {
032:
033: private Log log = LogFactory.getLog(StandardSchedule.class);
034: private String seconds;
035: private String minutes;
036: private String hours;
037: private String dayOfMonth;
038: private String month;
039: private String dayOfWeek;
040: private String holidaySchedule;
041:
042: /**
043: * @return the dayOfMonth
044: */
045: public String getDayOfMonth() {
046: return dayOfMonth;
047: }
048:
049: /**
050: * @param dayOfMonth the dayOfMonth to set
051: */
052: public void setDayOfMonth(String dayOfMonth) {
053: this .dayOfMonth = dayOfMonth;
054: }
055:
056: /**
057: * @return the dayOfWeek
058: */
059: public String getDayOfWeek() {
060: return dayOfWeek;
061: }
062:
063: /**
064: * @param dayOfWeek the dayOfWeek to set
065: */
066: public void setDayOfWeek(String dayOfWeek) {
067: this .dayOfWeek = dayOfWeek;
068: }
069:
070: /**
071: * @return the holidaySchedule
072: */
073: public String getHolidaySchedule() {
074: return holidaySchedule;
075: }
076:
077: /**
078: * @param holidaySchedule the holidaySchedule to set
079: */
080: public void setHolidaySchedule(String holidaySchedule) {
081: this .holidaySchedule = holidaySchedule;
082: }
083:
084: /**
085: * @return the hours
086: */
087: public String getHours() {
088: return hours;
089: }
090:
091: /**
092: * @param hours the hours to set
093: */
094: public void setHours(String hours) {
095: this .hours = hours;
096: }
097:
098: /**
099: * @return the minutes
100: */
101: public String getMinutes() {
102: return minutes;
103: }
104:
105: /**
106: * @param minutes the minutes to set
107: */
108: public void setMinutes(String minutes) {
109: this .minutes = minutes;
110: }
111:
112: /**
113: * @return the month
114: */
115: public String getMonth() {
116: return month;
117: }
118:
119: /**
120: * @param month the month to set
121: */
122: public void setMonth(String month) {
123: this .month = month;
124: }
125:
126: /**
127: * @return the seconds
128: */
129: public String getSeconds() {
130: return seconds;
131: }
132:
133: /**
134: * @param seconds the seconds to set
135: */
136: public void setSeconds(String seconds) {
137: this .seconds = seconds;
138: }
139:
140: public CronExpression getCronExpression() throws Exception {
141: String cronStr = seconds + " " + minutes + " " + hours + " "
142: + dayOfMonth + " " + month + " " + dayOfWeek;
143: CronExpression cronExpr = new CronExpression(cronStr);
144: return cronExpr;
145: }
146:
147: /* (non-Javadoc)
148: * @see com.bostechcorp.cbesb.runtime.scheduler.ISchedule#fromJDomElement()
149: */
150: public boolean fromJDomElement(Element standSchedElem,
151: ComponentSchedule compSched) {
152: String value = compSched.getChildTextValue(standSchedElem,
153: ComponentSchedule.SECONDS);
154: if (value != null) {
155: setSeconds(value);
156: } else {
157: log.error("StandardSchedule - Unable to load value of '"
158: + ComponentSchedule.SECONDS + "'");
159: return false;
160: }
161: value = compSched.getChildTextValue(standSchedElem,
162: ComponentSchedule.MINUTES);
163: if (value != null) {
164: setMinutes(value);
165: } else {
166: log.error("StandardSchedule - Unable to load value of '"
167: + ComponentSchedule.MINUTES + "'");
168: return false;
169: }
170: value = compSched.getChildTextValue(standSchedElem,
171: ComponentSchedule.HOURS);
172: if (value != null) {
173: setHours(value);
174: } else {
175: log.error("StandardSchedule - Unable to load value of '"
176: + ComponentSchedule.HOURS + "'");
177: return false;
178: }
179: value = compSched.getChildTextValue(standSchedElem,
180: ComponentSchedule.DAY_OF_MONTH);
181: if (value != null) {
182: setDayOfMonth(value);
183: } else {
184: log.error("StandardSchedule - Unable to load value of '"
185: + ComponentSchedule.DAY_OF_MONTH + "'");
186: return false;
187: }
188: value = compSched.getChildTextValue(standSchedElem,
189: ComponentSchedule.MONTH);
190: if (value != null) {
191: setMonth(value);
192: } else {
193: log.error("StandardSchedule - Unable to load value of '"
194: + ComponentSchedule.MONTH + "'");
195: return false;
196: }
197: value = compSched.getChildTextValue(standSchedElem,
198: ComponentSchedule.DAY_OF_WEEK);
199: if (value != null) {
200: setDayOfWeek(value);
201: } else {
202: log.error("StandardSchedule - Unable to load value of '"
203: + ComponentSchedule.DAY_OF_WEEK + "'");
204: return false;
205: }
206: value = compSched.getChildTextValue(standSchedElem,
207: ComponentSchedule.HOLIDAY_SCHEDULE);
208: if (value != null) {
209: setHolidaySchedule(value);
210: }
211:
212: return true;
213:
214: }
215:
216: /* (non-Javadoc)
217: * @see com.bostechcorp.cbesb.runtime.scheduler.ISchedule#toJDomElement()
218: */
219: public Element toJDomElement(ComponentSchedule compSched) {
220: Element standSchedElem = compSched
221: .createElement(ComponentSchedule.STANDARD_SCHEDULE);
222:
223: Element childElem = compSched
224: .createElement(ComponentSchedule.SECONDS);
225: childElem.setText(seconds);
226: standSchedElem.addContent(childElem);
227:
228: childElem = compSched.createElement(ComponentSchedule.MINUTES);
229: childElem.setText(minutes);
230: standSchedElem.addContent(childElem);
231:
232: childElem = compSched.createElement(ComponentSchedule.HOURS);
233: childElem.setText(hours);
234: standSchedElem.addContent(childElem);
235:
236: childElem = compSched
237: .createElement(ComponentSchedule.DAY_OF_MONTH);
238: childElem.setText(dayOfMonth);
239: standSchedElem.addContent(childElem);
240:
241: childElem = compSched.createElement(ComponentSchedule.MONTH);
242: childElem.setText(month);
243: standSchedElem.addContent(childElem);
244:
245: childElem = compSched
246: .createElement(ComponentSchedule.DAY_OF_WEEK);
247: childElem.setText(dayOfWeek);
248: standSchedElem.addContent(childElem);
249:
250: if (holidaySchedule != null) {
251: childElem = compSched
252: .createElement(ComponentSchedule.HOLIDAY_SCHEDULE);
253: childElem.setText(holidaySchedule);
254: standSchedElem.addContent(childElem);
255: }
256:
257: return standSchedElem;
258: }
259:
260: }
|