001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /*
019: * ChainBuilder ESB
020: * Visual Enterprise Integration
021: *
022: * Copyright (C) 2006 Bostech Corporation
023: *
024: * This program is free software; you can redistribute it and/or modify it
025: * under the terms of the GNU General Public License as published by the
026: * Free Software Foundation; either version 2 of the License, or (at your option)
027: * any later version.
028: *
029: * This program is distributed in the hope that it will be useful,
030: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
031: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
032: * for more details.
033: *
034: * You should have received a copy of the GNU General Public License along with
035: * this program; if not, write to the Free Software Foundation, Inc.,
036: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
037: *
038: * $Id: CbComponent.java 9975 2007-11-09 03:11:12Z lzheng $
039: */
040: package com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging;
041:
042: import javax.jbi.component.Component;
043: import javax.jbi.component.ComponentContext;
044: import javax.jbi.component.ComponentLifeCycle;
045: import javax.jbi.component.ServiceUnitManager;
046: import javax.jbi.messaging.MessageExchange;
047: import javax.jbi.messaging.MessageExchange.Role;
048: import javax.jbi.servicedesc.ServiceEndpoint;
049: import javax.resource.spi.work.WorkManager;
050:
051: import org.apache.commons.logging.Log;
052: import org.apache.commons.logging.LogFactory;
053: import org.w3c.dom.Document;
054: import org.w3c.dom.DocumentFragment;
055:
056: import com.bostechcorp.cbesb.common.version.Version;
057:
058: /**
059: * Base class for a component.
060: *
061: * @author Guillaume Nodet
062: * @version $Revision: 426415 $
063: * @since 3.0
064: */
065: public abstract class CbComponent implements Component {
066:
067: protected final transient Log logger = LogFactory
068: .getLog(getClass());
069:
070: protected CbLifeCycle lifeCycle;
071: protected ComponentRegistry registry;
072: protected CbServiceUnitManager serviceUnitManager;
073: protected Version versionInfo;
074: protected Version ccslLibVersionInfo;
075:
076: public CbComponent() {
077: lifeCycle = createLifeCycle();
078: registry = createRegistry();
079: serviceUnitManager = createServiceUnitManager();
080: }
081:
082: /* (non-Javadoc)
083: * @see javax.jbi.component.Component#getLifeCycle()
084: */
085: public ComponentLifeCycle getLifeCycle() {
086: return lifeCycle;
087: }
088:
089: /* (non-Javadoc)
090: * @see javax.jbi.component.Component#getServiceUnitManager()
091: */
092: public ServiceUnitManager getServiceUnitManager() {
093: return serviceUnitManager;
094: }
095:
096: /* (non-Javadoc)
097: * @see javax.jbi.component.Component#getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint)
098: */
099: public Document getServiceDescription(ServiceEndpoint endpoint) {
100: if (logger.isDebugEnabled()) {
101: logger
102: .debug("Querying service description for "
103: + endpoint);
104: }
105: String key = EndpointKeyUtil.getKey(endpoint);
106: CbEndpoint ep = this .registry.getEndpoint(key);
107: if (ep != null) {
108: Document doc = ep.getDescription();
109: if (doc == null) {
110: if (logger.isDebugEnabled()) {
111: logger.debug("No description found for " + key);
112: }
113: }
114: return doc;
115: } else {
116: if (logger.isDebugEnabled()) {
117: logger.debug("No endpoint found for " + key);
118: }
119: return null;
120: }
121: }
122:
123: /* (non-Javadoc)
124: * @see javax.jbi.component.Component#isExchangeWithConsumerOkay(javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange)
125: */
126: public boolean isExchangeWithConsumerOkay(ServiceEndpoint endpoint,
127: MessageExchange exchange) {
128: String key = EndpointKeyUtil.getKey(endpoint);
129: CbEndpoint ep = this .registry.getEndpoint(key);
130: if (ep != null) {
131: if (ep.getRole() != Role.PROVIDER) {
132: if (logger.isDebugEnabled()) {
133: logger
134: .debug("Endpoint "
135: + key
136: + " is a consumer. Refusing exchange with consumer.");
137: }
138: return false;
139: } else {
140: return ep.isExchangeOkay(exchange);
141: }
142: } else {
143: if (logger.isDebugEnabled()) {
144: logger.debug("No endpoint found for " + key
145: + ". Refusing exchange with consumer.");
146: }
147: return false;
148: }
149: }
150:
151: /* (non-Javadoc)
152: * @see javax.jbi.component.Component#isExchangeWithProviderOkay(javax.jbi.servicedesc.ServiceEndpoint, javax.jbi.messaging.MessageExchange)
153: */
154: public boolean isExchangeWithProviderOkay(ServiceEndpoint endpoint,
155: MessageExchange exchange) {
156: // TODO: check if the selected endpoint is good for us
157: return true;
158: }
159:
160: /* (non-Javadoc)
161: * @see javax.jbi.component.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment)
162: */
163: public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
164: return null;
165: }
166:
167: /**
168: * Create the life cycle object.
169: * Derived classes should override this method to be able to
170: * use a custom life cycle implementation.
171: *
172: * @return a life cycle object
173: */
174: protected CbLifeCycle createLifeCycle() {
175: return new CbLifeCycle(this );
176: }
177:
178: /**
179: * Create the service unit manager.
180: * Derived classes should override this method and return a
181: * BaseServiceUnitManager so that the component is able to
182: * handle service unit deployment.
183: *
184: * @return a service unit manager
185: */
186: protected CbServiceUnitManager createServiceUnitManager() {
187: return null;
188: }
189:
190: protected ComponentRegistry createRegistry() {
191: return new ComponentRegistry(this );
192: }
193:
194: public ComponentContext getComponentContext() {
195: return lifeCycle.getContext();
196: }
197:
198: public String getComponentName() {
199: if (getComponentContext() == null) {
200: return "Component (" + getClass().getName()
201: + ") not yet initialized";
202: }
203: return getComponentContext().getComponentName();
204: }
205:
206: public WorkManager getWorkManager() {
207: return lifeCycle.workManager;
208: }
209:
210: /**
211: * @return Returns the logger.
212: */
213: public Log getLogger() {
214: return logger;
215: }
216:
217: /**
218: * @return Returns the registry.
219: */
220: public ComponentRegistry getRegistry() {
221: return registry;
222: }
223:
224: public Version getVersionInfo() {
225: return versionInfo;
226: }
227:
228: public void setVersionInfo(Version versionInfo) {
229: this .versionInfo = versionInfo;
230: }
231:
232: public Version getCcslLibVersionInfo() {
233: return ccslLibVersionInfo;
234: }
235:
236: public void setCcslLibVersionInfo(Version ccslLibVersionInfo) {
237: this.ccslLibVersionInfo = ccslLibVersionInfo;
238: }
239:
240: }
|