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: CcslComponent.java 11977 2008-02-16 06:36:12Z lzheng $
023: */
024:
025: package com.bostechcorp.cbesb.runtime.ccsl.base;
026:
027: import javax.jbi.JBIException;
028: import javax.jbi.component.Component;
029: import javax.jbi.component.ComponentContext;
030: import javax.jbi.component.ComponentLifeCycle;
031: import javax.jbi.component.ServiceUnitManager;
032: import javax.jbi.messaging.DeliveryChannel;
033: import javax.jbi.messaging.MessageExchange;
034: import javax.jbi.servicedesc.ServiceEndpoint;
035: import javax.management.ObjectName;
036:
037: import org.apache.commons.logging.Log;
038: import org.apache.commons.logging.LogFactory;
039: import org.w3c.dom.Document;
040: import org.w3c.dom.DocumentFragment;
041:
042: import com.bostechcorp.cbesb.common.version.Version;
043: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.CbComponent;
044: import com.bostechcorp.cbesb.runtime.ccsl.lib.CcslConfig;
045: import com.bostechcorp.cbesb.runtime.ccsl.lib.ExceptionUtil;
046:
047: public class CcslComponent implements Component, ComponentLifeCycle {
048: String realComponentClassName;
049: CcslConfig config;
050: Component realComponent;
051: ComponentLifeCycle realComponentLifeCycle;
052: ServiceUnitManager realSuManager;
053:
054: ServiceUnitManager ccslSuManager;
055: ComponentContext realComponentContext;
056: ComponentContext ccslComponentContext;
057: DeliveryChannel realDeliveryChannel;
058: Log log;
059:
060: public static String CCSL_NAME = "CCSL";
061:
062: public ComponentLifeCycle getLifeCycle() {
063: return this ;
064: }
065:
066: public Document getServiceDescription(ServiceEndpoint arg0) {
067: Document desc = realComponent.getServiceDescription(arg0);
068: // try {
069: // ByteArrayOutputStream baos = new ByteArrayOutputStream();
070: // StreamResult result = new StreamResult(baos);
071: // TransformerFactory tf = TransformerFactory.newInstance();
072: // Transformer t = tf.newTransformer();
073: // t.setOutputProperty("indent", "yes");
074: // DOMSource ds = new DOMSource(desc.getFirstChild());
075: // t.transform(ds, result);
076: // log.debug("CCSL-SERVICEDESC="+baos.toString("utf-8")+"\n");
077: // }
078: // catch (Exception e) {
079: // log.error("\n\n\nException printing content: "+e+"\n"+ExceptionUtil.stackTraceString(e)+"\n\n\n");
080: // }
081: //
082: return desc;
083: }
084:
085: public ServiceUnitManager getServiceUnitManager() {
086: if (ccslSuManager == null) {
087: realSuManager = realComponent.getServiceUnitManager();
088: ccslSuManager = new CcslSuManager(this , realSuManager);
089: }
090: return ccslSuManager;
091: }
092:
093: public boolean isExchangeWithConsumerOkay(ServiceEndpoint arg0,
094: MessageExchange arg1) {
095: return realComponent.isExchangeWithConsumerOkay(arg0, arg1);
096: }
097:
098: public boolean isExchangeWithProviderOkay(ServiceEndpoint arg0,
099: MessageExchange arg1) {
100: return realComponent.isExchangeWithProviderOkay(arg0, arg1);
101: }
102:
103: public ServiceEndpoint resolveEndpointReference(
104: DocumentFragment arg0) {
105: return realComponent.resolveEndpointReference(arg0);
106: }
107:
108: public ObjectName getExtensionMBeanName() {
109: return realComponentLifeCycle.getExtensionMBeanName();
110: }
111:
112: public void init(ComponentContext arg0) throws JBIException {
113: // save the real component context
114: realComponentContext = arg0;
115: // get a logger for our use
116: log = LogFactory.getLog(this .getClass());
117: // load the configuration file
118: config = new CcslConfig(log, realComponentContext
119: .getInstallRoot());
120: realComponentClassName = config.getComponentClassName();
121: realDeliveryChannel = realComponentContext.getDeliveryChannel();
122: // create our adapter context
123: ccslComponentContext = new CcslComponentContext(this ,
124: realComponentContext, realDeliveryChannel, log);
125: log.debug("CCSL is initializing");
126:
127: //Print the CCSL version
128: Version ccslVersInfo = Version.getInstance(this .getClass());
129: if (ccslVersInfo != null) {
130: log.info("ChainBuilder ESB CCSL version: "
131: + ccslVersInfo.toString() + " built on "
132: + ccslVersInfo.getBuildTimestamp());
133:
134: } else {
135: log.warn("Unable to load CCSL version.");
136: }
137:
138: // load the real component
139: log.debug("CCSL is loading component class "
140: + realComponentClassName);
141: try {
142: Class comp = Class.forName(realComponentClassName, true,
143: this .getClass().getClassLoader());
144: realComponent = (Component) comp.newInstance();
145: //Print version info for real component
146: Version versInfo = Version.getInstance(comp);
147: if (versInfo != null) {
148: log.info(realComponentClassName + " Component version:"
149: + versInfo.toString() + " built on "
150: + versInfo.getBuildTimestamp());
151:
152: }
153: if (realComponent instanceof CbComponent) {
154: CbComponent cbComponent = (CbComponent) realComponent;
155: if (ccslVersInfo != null) {
156: cbComponent.setCcslLibVersionInfo(ccslVersInfo);
157: }
158: if (versInfo != null) {
159: cbComponent.setVersionInfo(versInfo);
160: }
161: }
162: realComponentLifeCycle = realComponent.getLifeCycle();
163: realComponentLifeCycle.init(ccslComponentContext);
164:
165: // MacroUtil.reLoadMacro();
166: } catch (ClassNotFoundException e) {
167: log.error("\n\n\nCCSL error loading class: " + e + "\n"
168: + ExceptionUtil.stackTraceString(e) + "\n\n\n"
169: + e.getMessage());
170: if (log.isDebugEnabled()) {
171: log.debug("\n\n\nCCSL error loading class: " + e + "\n"
172: + ExceptionUtil.stackTraceString(e) + "\n\n\n",
173: e);
174: }
175: } catch (Exception e) {
176: log.error("\n\n\nCCSL component class "
177: + realComponentClassName
178: + " loaded but failed to instantiate "
179: + e.getMessage());
180: if (log.isDebugEnabled()) {
181: log.debug("\n\n\nCCSL component class "
182: + realComponentClassName
183: + " loaded but failed to instantiate", e);
184: }
185: }
186: }
187:
188: public void shutDown() throws JBIException {
189: realComponentLifeCycle.shutDown();
190: // MacroUtil.clearMacro();
191: }
192:
193: public void start() throws JBIException {
194: realComponentLifeCycle.start();
195:
196: }
197:
198: public void stop() throws JBIException {
199: realComponentLifeCycle.stop();
200:
201: }
202:
203: public CcslConfig getConfig() {
204: return config;
205: }
206:
207: }
|