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: ExecuteStandardRequest.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 ExecuteStandardRequest extends SchedulerMessage {
039:
040: private QName jobEndpointServiceName;
041: private String jobEndpointEPName;
042:
043: /**
044: * @return the jobEndpointEPName
045: */
046: public String getJobEndpointEPName() {
047: return jobEndpointEPName;
048: }
049:
050: /**
051: * @param jobEndpointEPName the jobEndpointEPName to set
052: */
053: public void setJobEndpointEPName(String jobEndpointEPName) {
054: this .jobEndpointEPName = jobEndpointEPName;
055: }
056:
057: /**
058: * @return the jobEndpointServiceName
059: */
060: public QName getJobEndpointServiceName() {
061: return jobEndpointServiceName;
062: }
063:
064: /**
065: * @param jobEndpointServiceName the jobEndpointServiceName to set
066: */
067: public void setJobEndpointServiceName(QName jobEndpointServiceName) {
068: this .jobEndpointServiceName = jobEndpointServiceName;
069: }
070:
071: /* (non-Javadoc)
072: * @see com.bostechcorp.cbesb.runtime.component.scheduler.messages.SchedulerMessage#getMessageType()
073: */
074: @Override
075: public QName getMessageType() {
076: return SchedulerMessageFactory.TYPE_EXEC_STANDARD_REQUEST;
077: }
078:
079: public static SchedulerMessage createFromSource(Source src)
080: throws Exception {
081: DOMBuilder domBuilder = new DOMBuilder();
082: Document jdomDoc = domBuilder.build(getDocFromSource(src));
083: Element rootElem = jdomDoc.getRootElement();
084:
085: HashMap<String, Namespace> nsMap = getNamespaceMap(rootElem);
086:
087: if (rootElem.getNamespace().equals(schedulerNS)
088: && rootElem.getName().equals(STANDARD_TRIGGER)) {
089: ExecuteStandardRequest message = new ExecuteStandardRequest();
090:
091: Element jobEP = rootElem
092: .getChild(JOB_ENDPOINT, schedulerNS);
093: if (jobEP != null) {
094: Element serviceName = jobEP.getChild(SERVICE_NAME,
095: schedulerNS);
096: if (serviceName != null) {
097: QName serviceNameQName = getQNameFromPrefixedName(
098: serviceName.getValue(), nsMap);
099: message.setJobEndpointServiceName(serviceNameQName);
100: }
101: Element endpointName = jobEP.getChild(ENDPOINT_NAME,
102: schedulerNS);
103: if (endpointName != null) {
104: String epName = endpointName.getValue();
105: message.setJobEndpointEPName(epName);
106: }
107:
108: } else {
109: throw new Exception("Missing required element: "
110: + JOB_ENDPOINT);
111: }
112:
113: return message;
114: } else {
115: throw new Exception("XML message is not {" + SCHEDULER_NS
116: + "}" + STANDARD_TRIGGER);
117: }
118: }
119:
120: /* (non-Javadoc)
121: * @see com.bostechcorp.cbesb.runtime.component.scheduler.messages.SchedulerMessage#toSource()
122: */
123: @Override
124: public Source toSource() throws Exception {
125: HashMap<String, Namespace> nsMap = new HashMap<String, Namespace>();
126:
127: Element rootElem = new Element(STANDARD_TRIGGER, schedulerNS);
128: Document jdomDoc = new Document(rootElem);
129:
130: Element jobEP = new Element(JOB_ENDPOINT, schedulerNS);
131: rootElem.addContent(jobEP);
132: Element serviceName = new Element(SERVICE_NAME, schedulerNS);
133: serviceName.setText(getPrefixedNameFromQName(
134: getJobEndpointServiceName(), nsMap));
135: jobEP.addContent(serviceName);
136: Element endpointName = new Element(ENDPOINT_NAME, schedulerNS);
137: endpointName.setText(getJobEndpointEPName());
138: jobEP.addContent(endpointName);
139:
140: addNamespaceDeclsToRoot(rootElem, nsMap);
141: DOMOutputter domOut = new DOMOutputter();
142: org.w3c.dom.Document domDoc = domOut.output(jdomDoc);
143: return new DOMSource(domDoc);
144: }
145:
146: }
|