001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 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:$
023: *
024: */
025: package com.bostechcorp.cbesb.common.util.generators;
026:
027: import java.io.FileInputStream;
028: import java.util.List;
029:
030: import org.jdom.Content;
031: import org.jdom.Document;
032: import org.jdom.Element;
033: import org.jdom.Namespace;
034: import org.jdom.input.SAXBuilder;
035:
036: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
037:
038: /**
039: * @author LPS
040: *
041: */
042: public abstract class CanScheduleDOMWsdlXMLGenerator extends
043: AbstractComponentDOMWsdlXMLGenerator {
044: protected static String EXECUTESTANDARD_V = "executeStandard";
045: protected static String INPUT_T = "input";
046: protected static String MESSAGE_A = "message";
047: protected static String TNS_EXECUTESTANDARDREQUEST_V = "tns:executeStandardRequest";
048: protected static String EXECUTEAUTORETRY_V = "executeAutoRetry";
049: protected static String OUTPUT_T = "output";
050: protected static String TNS_EXECUTEAUTORETRYREQUEST_V = "tns:executeAutoRetryRequest";
051: protected static String TNS_EXECUTEAUTORETRYRESPONSE_V = "tns:executeAutoRetryResponse";
052:
053: private static String TEMPLATE_NAME = "HasSchedulerComponent_WSDL.template";
054:
055: public CanScheduleDOMWsdlXMLGenerator(String s) {
056: super (s);
057: }
058:
059: public CanScheduleDOMWsdlXMLGenerator(String s, boolean useSchedule) {
060: super (s);
061: this .useSchedule = useSchedule;
062: }
063:
064: protected boolean useSchedule = false;
065:
066: public void setDefinitionNamespace(String componentType,
067: String saName, String suName, String endPointName)
068: throws Exception {
069:
070: super .setDefinitionNamespace(componentType, saName, suName,
071: endPointName);
072:
073: if (useSchedule) {
074: Namespace sched = Namespace.getNamespace("sched",
075: "http://cbesb.bostechcorp.com/wsdl/scheduler/1.0");
076: Namespace schedSu = Namespace.getNamespace("schedsu",
077: "http://bostechcorp.com/SU/" + saName
078: + "_Scheduler");
079: rootElement.addNamespaceDeclaration(sched);
080: rootElement.addNamespaceDeclaration(schedSu);
081: SAXBuilder builder = new SAXBuilder();
082: Document docTypes = builder.build(new FileInputStream(
083: getTemplateName()));
084: Element eType = docTypes.getRootElement().getChild("types");
085: List eMessages = docTypes.getRootElement().getChildren(
086: "message");
087:
088: rootElement.addContent(0, eType.detach());
089: for (int i = 0; i < eMessages.size(); i++) {
090: rootElement.addContent(i + 1, ((Content) eMessages
091: .get(i)).detach());
092: }
093:
094: }
095:
096: }
097:
098: public void setPortTypeAttributes(String name) {
099: super .setPortTypeAttributes(name);
100: if (useSchedule) {
101:
102: Element operationElement = jdomFactory.element(OPERATION_T,
103: rootElement.getNamespace());
104: operationElement.setAttribute(NAME_A, EXECUTESTANDARD_V);
105:
106: Element inputElement = jdomFactory.element(INPUT_T,
107: rootElement.getNamespace());
108: inputElement.setAttribute(MESSAGE_A,
109: TNS_EXECUTESTANDARDREQUEST_V);
110: operationElement.addContent(inputElement);
111: portTypeElement.addContent(operationElement);
112:
113: Element operationElement2 = jdomFactory.element(
114: OPERATION_T, rootElement.getNamespace());
115: operationElement2.setAttribute(NAME_A, EXECUTEAUTORETRY_V);
116:
117: Element inputElement2 = jdomFactory.element(INPUT_T,
118: rootElement.getNamespace());
119: inputElement2.setAttribute(MESSAGE_A,
120: TNS_EXECUTEAUTORETRYREQUEST_V);
121: operationElement2.addContent(inputElement2);
122:
123: Element outputElement = jdomFactory.element(OUTPUT_T,
124: rootElement.getNamespace());
125: outputElement.setAttribute(MESSAGE_A,
126: TNS_EXECUTEAUTORETRYRESPONSE_V);
127: operationElement2.addContent(outputElement);
128:
129: portTypeElement.addContent(operationElement2);
130:
131: }
132: }
133:
134: public boolean isUseSchedule() {
135: return useSchedule;
136: }
137:
138: public void setUseSchedule(boolean useSchedule) {
139: this .useSchedule = useSchedule;
140: }
141:
142: public String getTemplateName() {
143: return EsbPathHelper.getCbesbHomeDir() + "/config/template/xml"
144: + "/" + TEMPLATE_NAME;
145: }
146:
147: }
|