1 17 package org.apache.servicemix.common; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.w3c.dom.Document ; 22 import org.w3c.dom.DocumentFragment ; 23 24 import javax.jbi.component.Component; 25 import javax.jbi.component.ComponentContext; 26 import javax.jbi.component.ComponentLifeCycle; 27 import javax.jbi.component.ServiceUnitManager; 28 import javax.jbi.messaging.MessageExchange; 29 import javax.jbi.messaging.MessageExchange.Role; 30 import javax.jbi.servicedesc.ServiceEndpoint; 31 import javax.resource.spi.work.WorkManager ; 32 33 40 public abstract class BaseComponent implements Component { 41 42 protected final transient Log logger = LogFactory.getLog(getClass()); 43 44 protected BaseLifeCycle lifeCycle; 45 protected Registry registry; 46 protected BaseServiceUnitManager serviceUnitManager; 47 48 public BaseComponent() { 49 lifeCycle = createLifeCycle(); 50 registry = createRegistry(); 51 serviceUnitManager = createServiceUnitManager(); 52 } 53 54 57 public ComponentLifeCycle getLifeCycle() { 58 return lifeCycle; 59 } 60 61 64 public ServiceUnitManager getServiceUnitManager() { 65 return serviceUnitManager; 66 } 67 68 71 public Document getServiceDescription(ServiceEndpoint endpoint) { 72 if (logger.isDebugEnabled()) { 73 logger.debug("Querying service description for " + endpoint); 74 } 75 String key = EndpointSupport.getKey(endpoint); 76 Endpoint ep = this.registry.getEndpoint(key); 77 if (ep != null) { 78 Document doc = ep.getDescription(); 79 if (doc == null) { 80 if (logger.isDebugEnabled()) { 81 logger.debug("No description found for " + key); 82 } 83 } 84 return doc; 85 } else { 86 if (logger.isDebugEnabled()) { 87 logger.debug("No endpoint found for " + key); 88 } 89 return null; 90 } 91 } 92 93 96 public boolean isExchangeWithConsumerOkay(ServiceEndpoint endpoint, MessageExchange exchange) { 97 String key = EndpointSupport.getKey(endpoint); 98 Endpoint ep = this.registry.getEndpoint(key); 99 if (ep != null) { 100 if (ep.getRole() != Role.PROVIDER) { 101 if (logger.isDebugEnabled()) { 102 logger.debug("Endpoint " + key + " is a consumer. Refusing exchange with consumer."); 103 } 104 return false; 105 } else { 106 return ep.isExchangeOkay(exchange); 107 } 108 } else { 109 if (logger.isDebugEnabled()) { 110 logger.debug("No endpoint found for " + key + ". Refusing exchange with consumer."); 111 } 112 return false; 113 } 114 } 115 116 119 public boolean isExchangeWithProviderOkay(ServiceEndpoint endpoint, MessageExchange exchange) { 120 return true; 122 } 123 124 127 public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) { 128 return null; 129 } 130 131 138 protected BaseLifeCycle createLifeCycle() { 139 return new BaseLifeCycle(this); 140 } 141 142 150 protected BaseServiceUnitManager createServiceUnitManager() { 151 return null; 152 } 153 154 protected Registry createRegistry() { 155 return new Registry(this); 156 } 157 158 public ComponentContext getComponentContext() { 159 return lifeCycle.getContext(); 160 } 161 162 public String getComponentName() { 163 if (getComponentContext() == null) { 164 return "Component (" + getClass().getName() + ") not yet initialized"; 165 } 166 return getComponentContext().getComponentName(); 167 } 168 169 public WorkManager getWorkManager() { 170 return lifeCycle.workManager; 171 } 172 173 176 public Log getLogger() { 177 return logger; 178 } 179 180 183 public Registry getRegistry() { 184 return registry; 185 } 186 187 } 188 | Popular Tags |