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: SubmitScheduleResponse.java 7088 2007-04-25 20:06:32Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.ccsl.messages;
025:
026: import javax.xml.namespace.QName;
027: import javax.xml.transform.Source;
028: import javax.xml.transform.dom.DOMSource;
029:
030: import org.jdom.Document;
031: import org.jdom.Element;
032: import org.jdom.input.DOMBuilder;
033: import org.jdom.output.DOMOutputter;
034:
035: public class SubmitScheduleResponse extends SchedulerMessage {
036:
037: private boolean success;
038:
039: /**
040: * @return the success
041: */
042: public boolean isSuccess() {
043: return success;
044: }
045:
046: /**
047: * @param success the success to set
048: */
049: public void setSuccess(boolean success) {
050: this .success = success;
051: }
052:
053: /* (non-Javadoc)
054: * @see com.bostechcorp.cbesb.runtime.component.scheduler.messages.SchedulerMessage#getMessageType()
055: */
056: @Override
057: public QName getMessageType() {
058: return SchedulerMessageFactory.TYPE_SUBMIT_RESPONSE;
059: }
060:
061: public static SchedulerMessage createFromSource(Source src)
062: throws Exception {
063: DOMBuilder domBuilder = new DOMBuilder();
064: Document jdomDoc = domBuilder.build(getDocFromSource(src));
065: Element rootElem = jdomDoc.getRootElement();
066:
067: if (rootElem.getNamespace().equals(schedulerNS)
068: && rootElem.getName().equals(SUBMIT_SCHEDULE_RESPONSE)) {
069: SubmitScheduleResponse message = new SubmitScheduleResponse();
070:
071: Element successElem = rootElem.getChild(SUCCESS,
072: schedulerNS);
073: if (successElem != null) {
074: message.success = Boolean.parseBoolean(successElem
075: .getText());
076: } else {
077: throw new Exception("Missing required element: "
078: + SUCCESS);
079: }
080:
081: return message;
082: } else {
083: throw new Exception("XML message is not {" + SCHEDULER_NS
084: + "}" + SUBMIT_SCHEDULE_RESPONSE);
085: }
086: }
087:
088: /* (non-Javadoc)
089: * @see com.bostechcorp.cbesb.runtime.component.scheduler.messages.SchedulerMessage#toSource()
090: */
091: @Override
092: public Source toSource() throws Exception {
093: Element rootElem = new Element(SUBMIT_SCHEDULE_RESPONSE,
094: schedulerNS);
095: Document jdomDoc = new Document(rootElem);
096:
097: Element successElem = new Element(SUCCESS, schedulerNS);
098: rootElem.addContent(successElem);
099: successElem.setText(Boolean.toString(success));
100:
101: DOMOutputter domOut = new DOMOutputter();
102: org.w3c.dom.Document domDoc = domOut.output(jdomDoc);
103: return new DOMSource(domDoc);
104: }
105:
106: }
|