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: ComponentSchedule.java 6895 2007-04-18 15:31:19Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.scheduler;
025:
026: import java.util.Iterator;
027: import java.util.List;
028: import java.util.Vector;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.jdom.Element;
033:
034: public class ComponentSchedule extends ConfigFileSupport {
035:
036: protected static final String SCHED_NAMESPACE = "http://cbesb.bostechcorp.com/scheduler/1.0";
037: protected static final String COMPONENT_SCHEDULE = "componentSchedule";
038: protected static final String STANDARD_SCHEDULE = "standardSchedule";
039: protected static final String AUTO_RETRY_SCHEDULE = "autoRetrySchedule";
040: protected static final String SECONDS = "seconds";
041: protected static final String MINUTES = "minutes";
042: protected static final String HOURS = "hours";
043: protected static final String DAY_OF_MONTH = "dayOfMonth";
044: protected static final String MONTH = "month";
045: protected static final String DAY_OF_WEEK = "dayOfWeek";
046: protected static final String HOLIDAY_SCHEDULE = "holidaySchedule";
047: protected static final String START_TIME = "startTime";
048: protected static final String END_TIME = "endTime";
049: protected static final String RETRY_INTERVAL = "retryInterval";
050: protected static final String SUCCESS_NOTIFICATION_EP = "successNotificationEP";
051: protected static final String FAILURE_NOTIFICATION_EP = "failureNotificationEP";
052: protected static final String SERVICE_NAME = "serviceName";
053: protected static final String ENDPOINT_NAME = "endpointName";
054:
055: private Log log;
056: private Vector<ISchedule> schedules;
057:
058: /**
059: *
060: */
061: public ComponentSchedule() {
062: super ();
063: log = LogFactory.getLog(ComponentSchedule.class);
064: setNamespaceURI(SCHED_NAMESPACE);
065: setRootName(COMPONENT_SCHEDULE);
066: schedules = new Vector<ISchedule>();
067: }
068:
069: public List<ISchedule> getSchedules() {
070: return schedules;
071: }
072:
073: public void addSchedule(ISchedule schedule) {
074: schedules.add(schedule);
075: }
076:
077: /* (non-Javadoc)
078: * @see com.bostechcorp.cbesb.runtime.scheduler.ConfigFileSupport#buildDoc()
079: */
080: @Override
081: protected boolean buildDoc() {
082: createNewDoc();
083: Element rootElem = this .getRootElement();
084:
085: for (Iterator iter = schedules.iterator(); iter.hasNext();) {
086: ISchedule schedule = (ISchedule) iter.next();
087: Element childElem = schedule.toJDomElement(this );
088: if (childElem != null) {
089: rootElem.addContent(childElem);
090: } else {
091: return false;
092: }
093: }
094: return true;
095: }
096:
097: /* (non-Javadoc)
098: * @see com.bostechcorp.cbesb.runtime.scheduler.ConfigFileSupport#processParsedDoc()
099: */
100: @Override
101: protected boolean processParsedDoc() {
102: Element rootElem = getRootElement();
103: List children = rootElem.getChildren();
104: for (Iterator iter = children.iterator(); iter.hasNext();) {
105: ISchedule schedule;
106: Element child = (Element) iter.next();
107: if (child.getName().equals(STANDARD_SCHEDULE)) {
108: schedule = new StandardSchedule();
109: } else if (child.getName().equals(AUTO_RETRY_SCHEDULE)) {
110: schedule = new AutoRetrySchedule();
111: } else {
112: log.error("Unexpected element: " + child.getName());
113: return false;
114: }
115: if (!schedule.fromJDomElement(child, this )) {
116: return false;
117: }
118: schedules.add(schedule);
119: }
120: return true;
121: }
122: }
|