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: */package com.bostechcorp.cbesb.common.util.generators;
024:
025: import java.util.Iterator;
026: import java.util.List;
027:
028: import org.jdom.Element;
029: import org.jdom.Namespace;
030:
031: import com.bostechcorp.cbesb.common.sa.component.AbstractComponent;
032:
033: /**
034: * @author LPS
035: *
036: */
037: public class AbstractComponentDOMJbiXMLGenerator extends
038: AbstractDOMGenerator {
039: private static final String JBI_T = "jbi";
040: private static final String SERVICES_T = "services";
041: private static final String PROVIDES_T = "provides";
042: private static final String CONSUMES_T = "consumes";
043: private static final String INTERFACE_NAME_A = "interface-name";
044: private static final String SERVICE_NAME_A = "service-name";
045: private static final String ENDPOINT_NAME_A = "endpoint-name";
046: private static final String BINDING_COMPONENT_A = "binding-component";
047:
048: protected String sus_jbi_xml_output_filename = "META-INF/jbi.xml";
049: private String JBI_Namespace = "http://java.sun.com/xml/ns/jbi";
050: private String namespacePrefixtext = "nspf"; //
051: private int namespacePrefixIndex = 0; //
052: private static String URI_CONSTANT_STRING = "http://bostechcorp.com/SU/";
053: protected Element services; // inner tag
054: private String saName;
055:
056: public AbstractComponentDOMJbiXMLGenerator(
057: Boolean isBindingComponent, String saName) {
058: super ();
059: this .saName = saName;
060: buildDocumentStructure();
061: setIsBindingComponent(isBindingComponent);
062: }
063:
064: public AbstractComponentDOMJbiXMLGenerator(String path,
065: Boolean isBindingComponent, String saName) {
066: super (path);
067: this .saName = saName;
068: buildDocumentStructure();
069: setIsBindingComponent(isBindingComponent);
070: }
071:
072: /* (non-Javadoc)
073: * @see com.bostechcorp.cbesb.common.util.generators.AbstractDOMGenerator#buildDocumentStructure()
074: */
075: @Override
076: protected void buildDocumentStructure() {
077: rootElement = jdomFactory.element(JBI_T);
078: rootElement.setNamespace(Namespace.getNamespace(JBI_Namespace));
079: rootElement.setAttribute(jdomFactory
080: .attribute("version", "1.0"));
081: services = jdomFactory.element(SERVICES_T);
082:
083: rootElement.addContent(services);
084: }
085:
086: /**
087: *
088: * @param suName
089: * @param interfaceName
090: * @param ServiceName
091: * @param endpointName
092: */
093: public void addProviderPart(String suName, String interfaceName,
094: String ServiceName, String endpointName) {
095: Namespace ns = getNamespaceDeclaration(suName);
096: rootElement.addNamespaceDeclaration(ns);
097: Element provides = jdomFactory.element(PROVIDES_T);
098: provides.setAttribute(jdomFactory.attribute(INTERFACE_NAME_A,
099: ns.getPrefix() + ":" + saName + "_" + interfaceName));
100: provides.setAttribute(jdomFactory.attribute(SERVICE_NAME_A, ns
101: .getPrefix()
102: + ":" + saName + "_" + ServiceName));
103: provides.setAttribute(jdomFactory.attribute(ENDPOINT_NAME_A,
104: saName + "_" + endpointName));
105: services.addContent(provides);
106: }
107:
108: /**
109: * @param suName
110: * @param interfaceName
111: * @param ServiceName
112: * @param endpointName
113: * @param conn
114: */
115: public void addConsumerPart(List<AbstractComponent> conn) {
116: //DONE -- modified
117:
118: for (AbstractComponent component : conn) {
119: Namespace ns = getNamespaceDeclaration(component.getName());
120: rootElement.addNamespaceDeclaration(ns);
121: //String suName= saName+"_"+component.getName();
122: String interfaceName = saName + "_" + component.getName()
123: + "_Interface";
124: String ServiceName = saName + "_" + component.getName()
125: + "_Service";
126: String endpointName = saName + "_"
127: + component.getProviderEndpointName();
128: Element consumes = jdomFactory.element(CONSUMES_T);
129: consumes.setAttribute(jdomFactory.attribute(
130: INTERFACE_NAME_A, ns.getPrefix() + ":"
131: + interfaceName));
132: consumes.setAttribute(jdomFactory.attribute(SERVICE_NAME_A,
133: ns.getPrefix() + ":" + ServiceName));
134: consumes.setAttribute(jdomFactory.attribute(
135: ENDPOINT_NAME_A, endpointName));
136: services.addContent(consumes);
137: }
138: }
139:
140: private void setIsBindingComponent(Boolean isBindingComponent) {
141: services.setAttribute(jdomFactory
142: .attribute(BINDING_COMPONENT_A, String
143: .valueOf(isBindingComponent)));
144: }
145:
146: /* (non-Javadoc)
147: * @see com.bostechcorp.cbesb.common.util.generators.AbstractDOMGenerator#getFileOut()
148: */
149: @Override
150: protected String getFileOut() {
151: if (filePath.endsWith("/"))
152: return filePath + sus_jbi_xml_output_filename;
153: return filePath + "/" + sus_jbi_xml_output_filename;
154: }
155:
156: private Namespace getNamespaceDeclaration(String suName) {
157: String prefixString = "";
158: // test wether the namespace exist
159: List l = rootElement.getAdditionalNamespaces();
160: for (Iterator nsIter = l.iterator(); nsIter.hasNext();) {
161: Object nsObject = nsIter.next();
162: if (nsObject instanceof Namespace) {
163: Namespace nsElement = (Namespace) nsObject;
164: if (nsElement.getURI().equals(
165: URI_CONSTANT_STRING + saName + "_" + suName)) {
166: return nsElement;
167: }
168: }
169: }
170: prefixString = namespacePrefixtext + namespacePrefixIndex;
171: namespacePrefixIndex++;
172: String uriString = URI_CONSTANT_STRING + saName + "_" + suName;
173: return Namespace.getNamespace(prefixString, uriString);
174: }
175: }
|