001: /*
002: * ====================================================================
003: *
004: * XFLOW - Process Management System
005: * Copyright (C) 2003 Rob Tan
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions, and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions, and the disclaimer that follows
017: * these conditions in the documentation and/or other materials
018: * provided with the distribution.
019: *
020: * 3. The name "XFlow" must not be used to endorse or promote products
021: * derived from this software without prior written permission. For
022: * written permission, please contact rcktan@yahoo.com
023: *
024: * 4. Products derived from this software may not be called "XFlow", nor
025: * may "XFlow" appear in their name, without prior written permission
026: * from the XFlow Project Management (rcktan@yahoo.com)
027: *
028: * In addition, we request (but do not require) that you include in the
029: * end-user documentation provided with the redistribution and/or in the
030: * software itself an acknowledgement equivalent to the following:
031: * "This product includes software developed by the
032: * XFlow Project (http://xflow.sourceforge.net/)."
033: * Alternatively, the acknowledgment may be graphical using the logos
034: * available at http://xflow.sourceforge.net/
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE XFLOW AUTHORS OR THE PROJECT
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: * ====================================================================
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the XFlow Project and was originally
052: * created by Rob Tan (rcktan@yahoo.com)
053: * For more information on the XFlow Project, please see:
054: * <http://xflow.sourceforge.net/>.
055: * ====================================================================
056: */
057: package xflow.events;
058:
059: import java.util.Iterator;
060: import java.util.Vector;
061:
062: import javax.xml.parsers.DocumentBuilder;
063: import javax.xml.parsers.DocumentBuilderFactory;
064:
065: import org.w3c.dom.DOMImplementation;
066: import org.w3c.dom.Document;
067: import org.w3c.dom.Element;
068:
069: import xflow.common.XflowConstants;
070: import xflow.common.Node;
071: import xflow.common.WorkItem;
072: import xflow.common.WorkItemId;
073: import xflow.common.WorkflowId;
074: import xflow.common.XflowException;
075: import xflow.messaging.JMSPublisher;
076: import xflow.messaging.JMSTopicConnection;
077: import xflow.util.XflowGraphSerializer;
078:
079: /**
080: * @author xzma
081: * The methods in this class are called by the XFlow server to publish an event.
082: */
083: public class EventsPublisher {
084:
085: public void publishModelDeployedEvent(String workflowName,
086: int workflowVersion, String user) throws XflowException {
087: String docNS = "http://schemas.xmlsoap.org/soap/envelope/";
088:
089: try {
090: Document doc = createXMLDoc();
091: Element body = (Element) doc.getElementsByTagNameNS(docNS,
092: "Body").item(0);
093:
094: Element event = doc.createElementNS(docNS,
095: "ModelDeployedEvent");
096: event.setAttribute("xmlns", "http://xflow.net/events");
097: body.appendChild(event);
098:
099: Element timeStamp = doc.createElementNS(docNS, "Timestamp");
100: org.w3c.dom.Node n = doc.createTextNode(xflow.util.DateUtil
101: .getTimestamp());
102: timeStamp.appendChild(n);
103: event.appendChild(timeStamp);
104:
105: Element usere = doc.createElementNS(docNS, "User");
106: if (user == null) {
107: event.appendChild(usere);
108: } else {
109: n = doc.createTextNode(user);
110: usere.appendChild(n);
111: event.appendChild(usere);
112: }
113:
114: Element wkfn = doc.createElementNS(docNS, "WorkflowName");
115: if (workflowName == null) {
116: event.appendChild(wkfn);
117: } else {
118: n = doc.createTextNode(workflowName);
119: wkfn.appendChild(n);
120: event.appendChild(wkfn);
121: }
122:
123: Element version = doc.createElementNS(docNS,
124: "WorkflowVersion");
125:
126: n = doc.createTextNode(new Integer(workflowVersion)
127: .toString());
128: version.appendChild(n);
129: event.appendChild(version);
130:
131: //publish the xml string
132: String xmlString = XflowGraphSerializer.serialize(doc
133: .getDocumentElement());
134: publish(xmlString, XflowConstants.XFLOW_EVENT_TOPIC, null);
135: //System.out.println(XflowGraphSerializer.serialize(body));
136: //System.out.println(xmlString);
137: } catch (Exception ex) {
138: throw new XflowException(ex.getMessage());
139: }
140: }
141:
142: public void publishWorkflowStartedEvent(String workflowName,
143: int workflowVersion, int workflowId, int parentWorkflowId,
144: String user, WorkItem witem) throws XflowException {
145: String docNS = "http://schemas.xmlsoap.org/soap/envelope/";
146: try {
147: Document doc = createXMLDoc();
148: Element body = (Element) doc.getElementsByTagNameNS(docNS,
149: "Body").item(0);
150:
151: Element event = doc.createElementNS(docNS,
152: "WorkflowStartedEvent");
153: event.setAttribute("xmlns", "http://xflow.net/events");
154: body.appendChild(event);
155:
156: Element timeStamp = doc.createElementNS(docNS, "Timestamp");
157: org.w3c.dom.Node n = doc.createTextNode(xflow.util.DateUtil
158: .getTimestamp());
159: timeStamp.appendChild(n);
160: event.appendChild(timeStamp);
161:
162: Element usere = doc.createElementNS(docNS, "User");
163: if (user == null) {
164: event.appendChild(usere);
165: } else {
166: n = doc.createTextNode(user);
167: usere.appendChild(n);
168: event.appendChild(usere);
169: }
170:
171: Element wkfn = doc.createElementNS(docNS, "WorkflowName");
172: if (workflowName == null) {
173: event.appendChild(wkfn);
174: } else {
175: n = doc.createTextNode(workflowName);
176: wkfn.appendChild(n);
177: event.appendChild(wkfn);
178: }
179:
180: Element version = doc.createElementNS(docNS,
181: "WorkflowVersion");
182: n = doc.createTextNode(new Integer(workflowVersion)
183: .toString());
184: version.appendChild(n);
185: event.appendChild(version);
186:
187: Element wkfId = doc.createElementNS(docNS,
188: "WorkflowInstanceId");
189: n = doc.createTextNode(new Integer(workflowId).toString());
190: wkfId.appendChild(n);
191: event.appendChild(wkfId);
192:
193: Element pId = doc.createElementNS(docNS,
194: "ParentWorkflowInstanceId");
195: if (parentWorkflowId == -1) {
196: event.appendChild(pId);
197: } else {
198: n = doc.createTextNode(new Integer(parentWorkflowId)
199: .toString());
200: pId.appendChild(n);
201: event.appendChild(pId);
202: }
203:
204: Element wkItem = doc.createElementNS(docNS, "WorkItem");
205:
206: buildWorkItemXML(witem, docNS, doc, wkItem);
207:
208: event.appendChild(wkItem);
209:
210: //publish the xml string
211: String xmlString = XflowGraphSerializer.serialize(doc
212: .getDocumentElement());
213: publish(xmlString, XflowConstants.XFLOW_EVENT_TOPIC, null);
214: //System.out.println(XflowGraphSerializer.serialize(body));
215: //System.out.println(xmlString);
216: } catch (Exception ex) {
217: throw new XflowException(ex.getMessage());
218: }
219:
220: }
221:
222: private void buildWorkItemXML(WorkItem witem, String docNS,
223: Document doc, Element wkItem) {
224: org.w3c.dom.Node n;
225: Element wkItemId = doc.createElementNS(docNS, "WorkItemId");
226: int id = witem.getId().getId();
227: n = doc.createTextNode(new Integer(id).toString());
228: wkItemId.appendChild(n);
229: wkItem.appendChild(wkItemId);
230:
231: Element payload = doc.createElementNS(docNS, "Payload");
232: String ptype = witem.getPayloadType();
233: payload.setAttribute("type", ptype);
234: Object pd = witem.getPayload();
235: if (pd == null) {
236: wkItem.appendChild(payload);
237: } else {
238: n = doc.createTextNode(xflow.util.HexUtil
239: .hexEncodeObject(pd));
240: payload.appendChild(n);
241: wkItem.appendChild(payload);
242: }
243: Element props = doc.createElementNS(docNS, "Properties");
244:
245: Iterator it = witem.getProperties().keySet().iterator();
246: while (it.hasNext()) {
247: Element prop = doc.createElementNS(docNS, "Property");
248: String name = (String) it.next();
249: Object value = witem.getProperty(name);
250: String type = getType(value);
251: String vl = xflow.util.HexUtil.hexEncodeObject(value);
252:
253: Element nm = doc.createElementNS(docNS, "Name");
254: n = doc.createTextNode(name);
255: nm.appendChild(n);
256: prop.appendChild(nm);
257:
258: Element tp = doc.createElementNS(docNS, "Type");
259: n = doc.createTextNode(type);
260: tp.appendChild(n);
261: prop.appendChild(tp);
262:
263: Element v = doc.createElementNS(docNS, "Value");
264: n = doc.createTextNode(vl);
265: v.appendChild(n);
266: prop.appendChild(v);
267:
268: props.appendChild(prop);
269: }
270:
271: wkItem.appendChild(props);
272:
273: }
274:
275: public void publishWorkflowAbortedEvent(String workflowName,
276: int workflowVersion, int workflowId, String user)
277: throws XflowException {
278: String docNS = "http://schemas.xmlsoap.org/soap/envelope/";
279: try {
280: Document doc = createXMLDoc();
281: Element body = (Element) doc.getElementsByTagNameNS(docNS,
282: "Body").item(0);
283:
284: Element event = doc.createElementNS(docNS,
285: "WorkflowAbortedEvent");
286: event.setAttribute("xmlns", "http://xflow.net/events");
287: body.appendChild(event);
288:
289: Element timeStamp = doc.createElementNS(docNS, "Timestamp");
290: org.w3c.dom.Node n = doc.createTextNode(xflow.util.DateUtil
291: .getTimestamp());
292: timeStamp.appendChild(n);
293: event.appendChild(timeStamp);
294:
295: Element usere = doc.createElementNS(docNS, "User");
296: if (user == null) {
297: event.appendChild(usere);
298: } else {
299: n = doc.createTextNode(user);
300: usere.appendChild(n);
301: event.appendChild(usere);
302: }
303:
304: Element wkfn = doc.createElementNS(docNS, "WorkflowName");
305: if (workflowName == null) {
306: event.appendChild(wkfn);
307: } else {
308: n = doc.createTextNode(workflowName);
309: wkfn.appendChild(n);
310: event.appendChild(wkfn);
311: }
312:
313: Element version = doc.createElementNS(docNS,
314: "WorkflowVersion");
315: n = doc.createTextNode(new Integer(workflowVersion)
316: .toString());
317: version.appendChild(n);
318: event.appendChild(version);
319:
320: Element wkfId = doc.createElementNS(docNS,
321: "WorkflowInstanceId");
322: n = doc.createTextNode(new Integer(workflowId).toString());
323: wkfId.appendChild(n);
324: event.appendChild(wkfId);
325:
326: //publish the xml string
327: String xmlString = XflowGraphSerializer.serialize(doc
328: .getDocumentElement());
329: publish(xmlString, XflowConstants.XFLOW_EVENT_TOPIC, null);
330: //System.out.println(XflowGraphSerializer.serialize(body));
331: //System.out.println(xmlString);
332: } catch (Exception ex) {
333: throw new XflowException(ex.getMessage());
334: }
335:
336: }
337:
338: public void publishWorkflowSuspendedEvent(String workflowName,
339: int workflowVersion, int workflowId, String user)
340: throws XflowException {
341: String docNS = "http://schemas.xmlsoap.org/soap/envelope/";
342: try {
343: Document doc = createXMLDoc();
344: Element body = (Element) doc.getElementsByTagNameNS(docNS,
345: "Body").item(0);
346:
347: Element event = doc.createElementNS(docNS,
348: "WorkflowSuspendedEvent");
349: event.setAttribute("xmlns", "http://xflow.net/events");
350: body.appendChild(event);
351:
352: Element timeStamp = doc.createElementNS(docNS, "Timestamp");
353: org.w3c.dom.Node n = doc.createTextNode(xflow.util.DateUtil
354: .getTimestamp());
355: timeStamp.appendChild(n);
356: event.appendChild(timeStamp);
357:
358: Element usere = doc.createElementNS(docNS, "User");
359: if (user == null) {
360: event.appendChild(usere);
361: } else {
362: n = doc.createTextNode(user);
363: usere.appendChild(n);
364: event.appendChild(usere);
365: }
366:
367: Element wkfn = doc.createElementNS(docNS, "WorkflowName");
368: if (workflowName == null) {
369: event.appendChild(wkfn);
370: } else {
371: n = doc.createTextNode(workflowName);
372: wkfn.appendChild(n);
373: event.appendChild(wkfn);
374: }
375:
376: Element version = doc.createElementNS(docNS,
377: "WorkflowVersion");
378: n = doc.createTextNode(new Integer(workflowVersion)
379: .toString());
380: version.appendChild(n);
381: event.appendChild(version);
382:
383: Element wkfId = doc.createElementNS(docNS,
384: "WorkflowInstanceId");
385: n = doc.createTextNode(new Integer(workflowId).toString());
386: wkfId.appendChild(n);
387: event.appendChild(wkfId);
388:
389: //publish the xml string
390: String xmlString = XflowGraphSerializer.serialize(doc
391: .getDocumentElement());
392: publish(xmlString, XflowConstants.XFLOW_EVENT_TOPIC, null);
393: //System.out.println(XflowGraphSerializer.serialize(body));
394: //System.out.println(xmlString);
395: } catch (Exception ex) {
396: throw new XflowException(ex.getMessage());
397: }
398: }
399:
400: public void publishWorkflowResumedEvent(String workflowName,
401: int workflowVersion, int workflowId, String user)
402: throws XflowException {
403: String docNS = "http://schemas.xmlsoap.org/soap/envelope/";
404: try {
405: Document doc = createXMLDoc();
406: Element body = (Element) doc.getElementsByTagNameNS(docNS,
407: "Body").item(0);
408:
409: Element event = doc.createElementNS(docNS,
410: "WorkflowResumedEvent");
411: event.setAttribute("xmlns", "http://xflow.net/events");
412: body.appendChild(event);
413:
414: Element timeStamp = doc.createElementNS(docNS, "Timestamp");
415: org.w3c.dom.Node n = doc.createTextNode(xflow.util.DateUtil
416: .getTimestamp());
417: timeStamp.appendChild(n);
418: event.appendChild(timeStamp);
419:
420: Element usere = doc.createElementNS(docNS, "User");
421: if (user == null) {
422: event.appendChild(usere);
423: } else {
424: n = doc.createTextNode(user);
425: usere.appendChild(n);
426: event.appendChild(usere);
427: }
428:
429: Element wkfn = doc.createElementNS(docNS, "WorkflowName");
430: if (workflowName == null) {
431: event.appendChild(wkfn);
432: } else {
433: n = doc.createTextNode(workflowName);
434: wkfn.appendChild(n);
435: event.appendChild(wkfn);
436: }
437:
438: Element version = doc.createElementNS(docNS,
439: "WorkflowVersion");
440: n = doc.createTextNode(new Integer(workflowVersion)
441: .toString());
442: version.appendChild(n);
443: event.appendChild(version);
444:
445: Element wkfId = doc.createElementNS(docNS,
446: "WorkflowInstanceId");
447: n = doc.createTextNode(new Integer(workflowId).toString());
448: wkfId.appendChild(n);
449: event.appendChild(wkfId);
450:
451: //publish the xml string
452: String xmlString = XflowGraphSerializer.serialize(doc
453: .getDocumentElement());
454: publish(xmlString, XflowConstants.XFLOW_EVENT_TOPIC, null);
455: //System.out.println(XflowGraphSerializer.serialize(body));
456: //System.out.println(xmlString);
457: } catch (Exception ex) {
458: throw new XflowException(ex.getMessage());
459: }
460: }
461:
462: public void publishWorkflowCompletedEvent(String workflowName,
463: int workflowVersion, int workflowId, String user)
464: throws XflowException {
465: String docNS = "http://schemas.xmlsoap.org/soap/envelope/";
466: try {
467: Document doc = createXMLDoc();
468: Element body = (Element) doc.getElementsByTagNameNS(docNS,
469: "Body").item(0);
470:
471: Element event = doc.createElementNS(docNS,
472: "WorkflowCompletedEvent");
473: event.setAttribute("xmlns", "http://xflow.net/events");
474: body.appendChild(event);
475:
476: Element timeStamp = doc.createElementNS(docNS, "Timestamp");
477: org.w3c.dom.Node n = doc.createTextNode(xflow.util.DateUtil
478: .getTimestamp());
479: timeStamp.appendChild(n);
480: event.appendChild(timeStamp);
481:
482: Element usere = doc.createElementNS(docNS, "User");
483: if (user == null) {
484: event.appendChild(usere);
485: } else {
486: n = doc.createTextNode(user);
487: usere.appendChild(n);
488: event.appendChild(usere);
489: }
490:
491: Element wkfn = doc.createElementNS(docNS, "WorkflowName");
492: if (workflowName == null) {
493: event.appendChild(wkfn);
494: } else {
495: n = doc.createTextNode(workflowName);
496: wkfn.appendChild(n);
497: event.appendChild(wkfn);
498: }
499:
500: Element version = doc.createElementNS(docNS,
501: "WorkflowVersion");
502: n = doc.createTextNode(new Integer(workflowVersion)
503: .toString());
504: version.appendChild(n);
505: event.appendChild(version);
506:
507: Element wkfId = doc.createElementNS(docNS,
508: "WorkflowInstanceId");
509: n = doc.createTextNode(new Integer(workflowId).toString());
510: wkfId.appendChild(n);
511: event.appendChild(wkfId);
512:
513: //publish the xml string
514: String xmlString = XflowGraphSerializer.serialize(doc
515: .getDocumentElement());
516: publish(xmlString, XflowConstants.XFLOW_EVENT_TOPIC, null);
517: //System.out.println(XflowGraphSerializer.serialize(body));
518: //System.out.println(xmlString);
519: } catch (Exception ex) {
520: throw new XflowException(ex.getMessage());
521: }
522: }
523:
524: public void publishNodeTransitionEvent(String workflowName,
525: int workflowVersion, int workflowId, String fromNodeName,
526: String toNodeName, WorkItem witem) throws XflowException {
527: String docNS = "http://schemas.xmlsoap.org/soap/envelope/";
528: try {
529: Document doc = createXMLDoc();
530: Element body = (Element) doc.getElementsByTagNameNS(docNS,
531: "Body").item(0);
532:
533: Element event = doc.createElementNS(docNS,
534: "NodeTransitionEvent");
535: event.setAttribute("xmlns", "http://xflow.net/events");
536: body.appendChild(event);
537:
538: Element timeStamp = doc.createElementNS(docNS, "Timestamp");
539: org.w3c.dom.Node n = doc.createTextNode(xflow.util.DateUtil
540: .getTimestamp());
541: timeStamp.appendChild(n);
542: event.appendChild(timeStamp);
543:
544: Element wkfn = doc.createElementNS(docNS, "WorkflowName");
545: if (workflowName == null) {
546: event.appendChild(wkfn);
547: } else {
548: n = doc.createTextNode(workflowName);
549: wkfn.appendChild(n);
550: event.appendChild(wkfn);
551: }
552:
553: Element version = doc.createElementNS(docNS,
554: "WorkflowVersion");
555: n = doc.createTextNode(new Integer(workflowVersion)
556: .toString());
557: version.appendChild(n);
558: event.appendChild(version);
559:
560: Element wkfId = doc.createElementNS(docNS,
561: "WorkflowInstanceId");
562: n = doc.createTextNode(new Integer(workflowId).toString());
563: wkfId.appendChild(n);
564: event.appendChild(wkfId);
565:
566: Element from = doc.createElementNS(docNS, "From");
567: from.setAttribute("nodeId", "0"); // obsolete
568: from.setAttribute("nodeName", fromNodeName);
569: from.setAttribute("nodeType", ""); // obsolete
570: event.appendChild(from);
571:
572: Element to = doc.createElementNS(docNS, "To");
573: to.setAttribute("nodeId", "0"); // obsolete
574: to.setAttribute("nodeName", toNodeName);
575: to.setAttribute("nodeType", ""); // obsolete
576: event.appendChild(to);
577:
578: Element wkItem = doc.createElementNS(docNS, "WorkItem");
579:
580: buildWorkItemXML(witem, docNS, doc, wkItem);
581:
582: event.appendChild(wkItem);
583:
584: //publish the xml string
585: String xmlString = XflowGraphSerializer.serialize(doc
586: .getDocumentElement());
587: publish(xmlString, XflowConstants.XFLOW_EVENT_TOPIC, null);
588: //System.out.println(XflowGraphSerializer.serialize(body));
589: //System.out.println(xmlString);
590: } catch (Exception ex) {
591: throw new XflowException(ex.getMessage());
592: }
593:
594: }
595:
596: public void publishVariableUpdatedEvent(String workflowName,
597: int workflowVersion, int workflowId, String variableName,
598: Object variableValue) throws XflowException {
599: String docNS = "http://schemas.xmlsoap.org/soap/envelope/";
600: try {
601: Document doc = createXMLDoc();
602: Element body = (Element) doc.getElementsByTagNameNS(docNS,
603: "Body").item(0);
604:
605: Element event = doc.createElementNS(docNS,
606: "VariableUpdatedEvent");
607: event.setAttribute("xmlns", "http://xflow.net/events");
608: body.appendChild(event);
609:
610: Element timeStamp = doc.createElementNS(docNS, "Timestamp");
611: org.w3c.dom.Node n = doc.createTextNode(xflow.util.DateUtil
612: .getTimestamp());
613: timeStamp.appendChild(n);
614: event.appendChild(timeStamp);
615:
616: Element wkfn = doc.createElementNS(docNS, "WorkflowName");
617: if (workflowName == null) {
618: event.appendChild(wkfn);
619: } else {
620: n = doc.createTextNode(workflowName);
621: wkfn.appendChild(n);
622: event.appendChild(wkfn);
623: }
624:
625: Element version = doc.createElementNS(docNS,
626: "WorkflowVersion");
627: n = doc.createTextNode(new Integer(workflowVersion)
628: .toString());
629: version.appendChild(n);
630: event.appendChild(version);
631:
632: Element wkfId = doc.createElementNS(docNS,
633: "WorkflowInstanceId");
634: n = doc.createTextNode(new Integer(workflowId).toString());
635: wkfId.appendChild(n);
636: event.appendChild(wkfId);
637:
638: Element var = doc.createElementNS(docNS, "Variable");
639: String type = getType(variableValue);
640: n = doc.createTextNode(xflow.util.HexUtil
641: .hexEncodeObject(variableValue));
642: var.appendChild(n);
643: var.setAttribute("name", variableName);
644: var.setAttribute("type", type);
645: event.appendChild(var);
646:
647: //publish the xml string
648: String xmlString = XflowGraphSerializer.serialize(doc
649: .getDocumentElement());
650: publish(xmlString, XflowConstants.XFLOW_EVENT_TOPIC, null);
651: //System.out.println(XflowGraphSerializer.serialize(body));
652: //System.out.println(xmlString);
653: } catch (Exception ex) {
654: throw new XflowException(ex.getMessage());
655: }
656: }
657:
658: public void publishProcessTimeoutEvent(String workflowName,
659: int workflowVersion, int workflowId, String processName)
660: throws XflowException {
661: String docNS = "http://schemas.xmlsoap.org/soap/envelope/";
662: try {
663: Document doc = createXMLDoc();
664: Element body = (Element) doc.getElementsByTagNameNS(docNS,
665: "Body").item(0);
666:
667: Element event = doc.createElementNS(docNS,
668: "ProcessTimedOutEvent");
669: event.setAttribute("xmlns", "http://xflow.net/events");
670: body.appendChild(event);
671:
672: Element timeStamp = doc.createElementNS(docNS, "Timestamp");
673: org.w3c.dom.Node n = doc.createTextNode(xflow.util.DateUtil
674: .getTimestamp());
675: timeStamp.appendChild(n);
676: event.appendChild(timeStamp);
677:
678: Element wkfn = doc.createElementNS(docNS, "WorkflowName");
679: if (workflowName == null) {
680: event.appendChild(wkfn);
681: } else {
682: n = doc.createTextNode(workflowName);
683: wkfn.appendChild(n);
684: event.appendChild(wkfn);
685: }
686:
687: Element version = doc.createElementNS(docNS,
688: "WorkflowVersion");
689: n = doc.createTextNode(new Integer(workflowVersion)
690: .toString());
691: version.appendChild(n);
692: event.appendChild(version);
693:
694: Element wkfId = doc.createElementNS(docNS,
695: "WorkflowInstanceId");
696: n = doc.createTextNode(new Integer(workflowId).toString());
697: wkfId.appendChild(n);
698: event.appendChild(wkfId);
699:
700: Element pname = doc.createElementNS(docNS, "ProcessName");
701: n = doc.createTextNode(processName);
702: pname.appendChild(n);
703: event.appendChild(pname);
704:
705: //publish the xml string
706: String xmlString = XflowGraphSerializer.serialize(doc
707: .getDocumentElement());
708: publish(xmlString, XflowConstants.XFLOW_EVENT_TOPIC, null);
709: //System.out.println(XflowGraphSerializer.serialize(body));
710: //System.out.println(xmlString);
711: } catch (Exception ex) {
712: throw new XflowException(ex.getMessage());
713: }
714: }
715:
716: private String getType(Object o) {
717: String name = o.getClass().getName();
718: return name.substring(name.lastIndexOf(".") + 1);
719: }
720:
721: public Document createXMLDoc() throws XflowException {
722: Document xmldoc = null;
723: Element e = null;
724: String ns_env = "http://schemas.xmlsoap.org/soap/envelope/";
725: String ns_xsi = "http://www.w3c.org/2001/XMLSchema-instance";
726: String ns_enc = "http://schemas.xmlsoap.org/soap/encoding/";
727: String ns_xsd = "http://www.w3c.org/2001/XMLSchema";
728: try {
729: DocumentBuilderFactory factory = DocumentBuilderFactory
730: .newInstance();
731: factory.setNamespaceAware(true);
732: DocumentBuilder builder = factory.newDocumentBuilder();
733: DOMImplementation impl = builder.getDOMImplementation();
734:
735: org.w3c.dom.Node n = null;
736:
737: xmldoc = impl.createDocument(ns_env, "SOAP-ENV:Envelope",
738: null);
739: Element root = xmldoc.getDocumentElement();
740: root.setAttribute("xmlns:SOAP-ENC", ns_enc);
741: root.setAttribute("xmlns:xsi", ns_xsi);
742: root.setAttribute("xmlns:SOAP-ENV", ns_env);
743: root.setAttribute("xmlns:xsd", ns_xsd);
744: e = xmldoc.createElementNS(ns_env, "SOAP-ENV:Header");
745: root.appendChild(e);
746: e = xmldoc.createElementNS(ns_env, "SOAP-ENV:Body");
747: root.appendChild(e);
748: } catch (Exception ex) {
749: throw new XflowException(ex.getMessage());
750: }
751: return xmldoc;
752: }
753:
754: private void publish(String msg, String topicName, Vector props)
755: throws XflowException {
756: try {
757: JMSTopicConnection.initialize();
758: JMSPublisher.send(topicName, msg, props);
759: } catch (Exception e) {
760: throw new XflowException(e.getMessage());
761: }
762: }
763: }
|