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: SchedulerMessage.java 9243 2007-09-25 00:49:54Z lzheng $
023: */
024: package com.bostechcorp.cbesb.runtime.ccsl.messages;
025:
026: import java.util.HashMap;
027: import java.util.Iterator;
028: import java.util.List;
029:
030: import javax.xml.namespace.QName;
031: import javax.xml.transform.Source;
032: import javax.xml.transform.Transformer;
033: import javax.xml.transform.TransformerFactory;
034: import javax.xml.transform.dom.DOMResult;
035: import javax.xml.transform.dom.DOMSource;
036:
037: import org.apache.commons.logging.Log;
038: import org.apache.commons.logging.LogFactory;
039: import org.jdom.Namespace;
040: import org.w3c.dom.Document;
041: import org.w3c.dom.Element;
042: import org.w3c.dom.Node;
043:
044: public abstract class SchedulerMessage {
045:
046: public static final String SCHEDULER_NS = "http://cbesb.bostechcorp.com/wsdl/scheduler/1.0";
047: public static final String SUBMIT_SCHEDULE = "submitSchedule";
048: public static final String SUBMIT_SCHEDULE_RESPONSE = "submitScheduleResponse";
049: public static final String REMOVE_SCHEDULE = "removeSchedule";
050: public static final String REMOVE_SCHEDULE_RESPONSE = "removeScheduleResponse";
051: public static final String TRIGGER_ENDPOINT = "triggerEndpoint";
052: public static final String JOB_ENDPOINT = "jobEndpoint";
053: public static final String SCHEDULES = "schedules";
054: public static final String STANDARD_SCHEDULE = "standardSchedule";
055: public static final String AUTO_RETRY_SCHEDULE = "standardSchedule";
056: public static final String SUCCESS = "success";
057: public static final String SERVICE_NAME = "serviceName";
058: public static final String ENDPOINT_NAME = "endpointName";
059: public static final String SECONDS = "seconds";
060: public static final String MINUTES = "minutes";
061: public static final String HOURS = "hours";
062: public static final String DAY_OF_MONTH = "dayOfMonth";
063: public static final String MONTH = "month";
064: public static final String DAY_OF_WEEK = "dayOfWeek";
065: public static final String HOLIDAY_SCHEDULE = "holidaySchedule";
066: public static final String START_TIME = "startTime";
067: public static final String END_TIME = "endTime";
068: public static final String RETRY_INTERVAL = "retryInterval";
069: public static final String SUCCESS_NOTIFICATION_EP = "successNotificationEP";
070: public static final String FAILURE_NOTIFICATION_EP = "failureNotificationEP";
071: public static final String STANDARD_TRIGGER = "standardTrigger";
072: public static final String AUTO_RETRY_TRIGGER = "autoRetryTrigger";
073: public static final String AUTO_RETRY_TRIGGER_RESPONSE = "autoRetryTriggerResponse";
074: public static final String ERROR = "error";
075: public static final String JOB_STATUS = "jobStatus";
076:
077: protected static Namespace schedulerNS = Namespace
078: .getNamespace(SCHEDULER_NS);
079:
080: protected Log log = LogFactory.getLog(getClass());
081:
082: public SchedulerMessage() {
083:
084: }
085:
086: public static SchedulerMessage createFromSource(Source src)
087: throws Exception {
088: return null;
089: }
090:
091: public Source toSource() throws Exception {
092: return null;
093: }
094:
095: public abstract QName getMessageType();
096:
097: protected static Document getDocFromSource(Source originalSource)
098: throws Exception {
099: Node domNode;
100: if (originalSource instanceof DOMSource) {
101: domNode = ((DOMSource) originalSource).getNode();
102: } else {
103: DOMResult dr = new DOMResult();
104: TransformerFactory tf = TransformerFactory.newInstance();
105: Transformer t = tf.newTransformer();
106: t.transform(originalSource, dr);
107: domNode = dr.getNode();
108: }
109: if (domNode instanceof Document) {
110: return (Document) domNode;
111: } else {
112: return ((Element) domNode).getOwnerDocument();
113: }
114: }
115:
116: protected static HashMap<String, Namespace> getNamespaceMap(
117: org.jdom.Element rootElement) {
118: HashMap<String, Namespace> nsMap = new HashMap<String, Namespace>();
119: nsMap.put(rootElement.getNamespace().getPrefix(), rootElement
120: .getNamespace());
121: List nsDecls = rootElement.getAdditionalNamespaces();
122: for (Iterator iter = nsDecls.iterator(); iter.hasNext();) {
123: Namespace ns = (Namespace) iter.next();
124: nsMap.put(ns.getPrefix(), ns);
125: }
126: return nsMap;
127: }
128:
129: protected static QName getQNameFromPrefixedName(
130: String prefixedName, HashMap<String, Namespace> nsMap) {
131: String prefix;
132: String localName;
133: QName qname;
134: int index = prefixedName.indexOf(':');
135: if (index > 0) {
136: prefix = prefixedName.substring(0, index);
137: localName = prefixedName.substring(index + 1);
138: } else {
139: prefix = null;
140: localName = prefixedName;
141: }
142: Namespace ns = nsMap.get(prefix);
143: if (ns != null) {
144: qname = new QName(ns.getURI(), localName);
145: } else {
146: qname = null;
147: }
148: return qname;
149: }
150:
151: protected static String getPrefixedNameFromQName(QName qname,
152: HashMap<String, Namespace> nsMap) {
153: String prefix;
154: Namespace ns;
155: if (!nsMap.containsKey(qname.getNamespaceURI())) {
156: prefix = "q" + nsMap.size();
157: ns = Namespace
158: .getNamespace(prefix, qname.getNamespaceURI());
159: nsMap.put(qname.getNamespaceURI(), ns);
160: } else {
161: ns = nsMap.get(qname.getNamespaceURI());
162: prefix = ns.getPrefix();
163: }
164:
165: return prefix + ":" + qname.getLocalPart();
166: }
167:
168: protected static void addNamespaceDeclsToRoot(
169: org.jdom.Element rootElem, HashMap<String, Namespace> nsMap) {
170: for (Iterator iter = nsMap.keySet().iterator(); iter.hasNext();) {
171: String key = (String) iter.next();
172: Namespace ns = nsMap.get(key);
173: rootElem.addNamespaceDeclaration(ns);
174: }
175: }
176:
177: }
|