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: ExecuteAutoRetryResponse.java 7088 2007-04-25 20:06:32Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.ccsl.messages;
025:
026: import java.util.HashMap;
027:
028: import javax.xml.namespace.QName;
029: import javax.xml.transform.Source;
030: import javax.xml.transform.dom.DOMSource;
031:
032: import org.jdom.Document;
033: import org.jdom.Element;
034: import org.jdom.Namespace;
035: import org.jdom.input.DOMBuilder;
036: import org.jdom.output.DOMOutputter;
037:
038: public class ExecuteAutoRetryResponse extends SchedulerMessage {
039:
040: private QName jobEndpointServiceName;
041: private String jobEndpointEPName;
042: private boolean success;
043: private String error;
044:
045: /**
046: * @return the error
047: */
048: public String getError() {
049: return error;
050: }
051:
052: /**
053: * @param error the error to set
054: */
055: public void setError(String error) {
056: this .error = error;
057: }
058:
059: /**
060: * @return the jobEndpointEPName
061: */
062: public String getJobEndpointEPName() {
063: return jobEndpointEPName;
064: }
065:
066: /**
067: * @param jobEndpointEPName the jobEndpointEPName to set
068: */
069: public void setJobEndpointEPName(String jobEndpointEPName) {
070: this .jobEndpointEPName = jobEndpointEPName;
071: }
072:
073: /**
074: * @return the jobEndpointServiceName
075: */
076: public QName getJobEndpointServiceName() {
077: return jobEndpointServiceName;
078: }
079:
080: /**
081: * @param jobEndpointServiceName the jobEndpointServiceName to set
082: */
083: public void setJobEndpointServiceName(QName jobEndpointServiceName) {
084: this .jobEndpointServiceName = jobEndpointServiceName;
085: }
086:
087: /**
088: * @return the success
089: */
090: public boolean isSuccess() {
091: return success;
092: }
093:
094: /**
095: * @param success the success to set
096: */
097: public void setSuccess(boolean success) {
098: this .success = success;
099: }
100:
101: /* (non-Javadoc)
102: * @see com.bostechcorp.cbesb.runtime.component.scheduler.messages.SchedulerMessage#getMessageType()
103: */
104: @Override
105: public QName getMessageType() {
106: return SchedulerMessageFactory.TYPE_EXEC_AUTO_RETRY_RESPONSE;
107: }
108:
109: public static SchedulerMessage createFromSource(Source src)
110: throws Exception {
111: DOMBuilder domBuilder = new DOMBuilder();
112: Document jdomDoc = domBuilder.build(getDocFromSource(src));
113: Element rootElem = jdomDoc.getRootElement();
114:
115: HashMap<String, Namespace> nsMap = getNamespaceMap(rootElem);
116:
117: if (rootElem.getNamespace().equals(schedulerNS)
118: && rootElem.getName().equals(
119: AUTO_RETRY_TRIGGER_RESPONSE)) {
120: ExecuteAutoRetryResponse message = new ExecuteAutoRetryResponse();
121:
122: Element jobEP = rootElem
123: .getChild(JOB_ENDPOINT, schedulerNS);
124: if (jobEP != null) {
125: Element serviceName = jobEP.getChild(SERVICE_NAME,
126: schedulerNS);
127: if (serviceName != null) {
128: QName serviceNameQName = getQNameFromPrefixedName(
129: serviceName.getValue(), nsMap);
130: message.setJobEndpointServiceName(serviceNameQName);
131: }
132: Element endpointName = jobEP.getChild(ENDPOINT_NAME,
133: schedulerNS);
134: if (endpointName != null) {
135: String epName = endpointName.getValue();
136: message.setJobEndpointEPName(epName);
137: }
138:
139: } else {
140: throw new Exception("Missing required element: "
141: + JOB_ENDPOINT);
142: }
143:
144: Element successElem = rootElem.getChild(SUCCESS,
145: schedulerNS);
146: if (successElem != null) {
147: message.success = Boolean.parseBoolean(successElem
148: .getText());
149: } else {
150: throw new Exception("Missing required element: "
151: + SUCCESS);
152: }
153:
154: Element errorElem = rootElem.getChild(ERROR, schedulerNS);
155: if (errorElem != null) {
156: message.error = errorElem.getText();
157: }
158:
159: return message;
160: } else {
161: throw new Exception("XML message is not {" + SCHEDULER_NS
162: + "}" + AUTO_RETRY_TRIGGER_RESPONSE);
163: }
164: }
165:
166: /* (non-Javadoc)
167: * @see com.bostechcorp.cbesb.runtime.component.scheduler.messages.SchedulerMessage#toSource()
168: */
169: @Override
170: public Source toSource() throws Exception {
171: HashMap<String, Namespace> nsMap = new HashMap<String, Namespace>();
172:
173: Element rootElem = new Element(AUTO_RETRY_TRIGGER_RESPONSE,
174: schedulerNS);
175: Document jdomDoc = new Document(rootElem);
176:
177: Element jobEP = new Element(JOB_ENDPOINT, schedulerNS);
178: rootElem.addContent(jobEP);
179: Element serviceName = new Element(SERVICE_NAME, schedulerNS);
180: serviceName.setText(getPrefixedNameFromQName(
181: getJobEndpointServiceName(), nsMap));
182: jobEP.addContent(serviceName);
183: Element endpointName = new Element(ENDPOINT_NAME, schedulerNS);
184: endpointName.setText(getJobEndpointEPName());
185: jobEP.addContent(endpointName);
186:
187: Element successElem = new Element(SUCCESS, schedulerNS);
188: rootElem.addContent(successElem);
189: successElem.setText(Boolean.toString(success));
190:
191: Element errorElem = new Element(ERROR, schedulerNS);
192: rootElem.addContent(errorElem);
193: errorElem.setText(error);
194:
195: addNamespaceDeclsToRoot(rootElem, nsMap);
196: DOMOutputter domOut = new DOMOutputter();
197: org.w3c.dom.Document domDoc = domOut.output(jdomDoc);
198: return new DOMSource(domDoc);
199: }
200:
201: }
|