1 22 package org.objectweb.petals.binding.xquarebc; 23 24 import java.io.File ; 25 import java.util.HashMap ; 26 import java.util.Properties ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 30 import javax.jbi.JBIException; 31 import javax.jbi.component.Component; 32 import javax.jbi.component.ComponentContext; 33 import javax.jbi.component.ComponentLifeCycle; 34 import javax.jbi.component.ServiceUnitManager; 35 import javax.jbi.messaging.DeliveryChannel; 36 import javax.jbi.messaging.MessageExchange; 37 import javax.jbi.servicedesc.ServiceEndpoint; 38 import javax.management.ObjectName ; 39 import javax.xml.namespace.QName ; 40 41 import org.objectweb.petals.binding.xquarebc.listeners.XQuareBCJBIProcessor; 42 import org.objectweb.petals.binding.xquarebc.listeners.XQuareBCListener; 43 import org.objectweb.petals.component.common.listener.MessageExchangeListener; 44 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager; 45 import org.objectweb.petals.component.common.util.ComponentLogger; 46 import org.objectweb.petals.component.common.util.XMLHelper; 47 import org.w3c.dom.Document ; 48 import org.w3c.dom.DocumentFragment ; 49 import org.w3c.dom.Node ; 50 51 70 public class XQuareBC implements Component, ComponentLifeCycle { 71 72 protected ComponentContext context; 73 protected Logger logger; 74 protected HashMap <String , Properties > serviceToPropertiesMap; 75 protected DeliveryChannel channel; 76 77 protected PetalsServiceUnitManager suManager; 78 protected MessageExchangeListener jbiListener; 79 80 protected XQuareBCListener xquareListener; 81 protected XQuareSUHandler xquareSUHandler; 82 83 84 public ObjectName getExtensionMBeanName() { 85 return null; 86 } 87 88 public ComponentLifeCycle getLifeCycle() { 89 return this; 90 } 91 92 public Document getServiceDescription(ServiceEndpoint arg0) { 93 return suManager.getServiceDescription(arg0); 94 } 95 96 public ServiceUnitManager getServiceUnitManager() { 97 return this.suManager; 98 } 99 100 public void init(ComponentContext context) throws JBIException { 101 try { 102 this.context = context; 103 Logger log = context.getLogger("", null); 104 logger = new ComponentLogger(log, log.getName(), log 105 .getResourceBundleName(), context.getComponentName()); 106 107 this.channel = context.getDeliveryChannel(); this.serviceToPropertiesMap = new HashMap <String , Properties >(); 109 110 } catch (Exception e) { 111 throw new JBIException(e); 112 } 113 logger.log(Level.INFO, "init"); 114 } 115 116 public boolean isExchangeWithConsumerOkay(ServiceEndpoint arg0, 117 MessageExchange arg1) { 118 return true; 119 } 120 121 public boolean isExchangeWithProviderOkay(ServiceEndpoint arg0, 122 MessageExchange arg1) { 123 return true; 124 } 125 126 public ServiceEndpoint resolveEndpointReference(DocumentFragment arg0) { 127 ServiceEndpoint result = null; 128 if (arg0 != null) { 129 String prefix = arg0.getPrefix(); 130 if (prefix == null) { 131 prefix = new String (); 132 } else { 133 prefix += ":"; 134 } 135 Node service = XMLHelper.findChild(arg0, prefix + "service", true); 136 137 if (service != null) { 138 String serviceRequested = XMLHelper.getAttributeValue(service, 139 "name"); 140 if (serviceRequested != null) { 141 result = suManager.findEndpointForService(QName 142 .valueOf(serviceRequested)); 143 } 144 } 145 } 146 return result; 147 } 148 149 public void shutDown() throws JBIException { 150 logger.log(Level.INFO, "shutDown"); 151 } 152 153 public void start() throws JBIException { 154 logger.log(Level.INFO, "start"); 155 156 XQuareBCJBIProcessor processor = new XQuareBCJBIProcessor(context, channel, logger, 157 serviceToPropertiesMap); 158 jbiListener = new MessageExchangeListener(channel, processor, 159 MessageExchangeListener.IgnoredStatus.DONE_AND_ERROR_IGNORED, 0); 160 jbiListener.listen(); 162 xquareListener = new XQuareBCListener(context, channel, logger, 163 serviceToPropertiesMap, processor); 164 new Thread (xquareListener).start(); 166 xquareSUHandler = new XQuareSUHandler(context, logger, 167 serviceToPropertiesMap); 168 this.suManager = new PetalsServiceUnitManager(context, logger); 169 suManager.addNewHandler(xquareSUHandler); 170 } 171 172 public void stop() throws JBIException { 173 logger.log(Level.INFO, "stop"); 174 jbiListener.terminate(); 175 xquareListener.stopProcessing(); 176 } 177 178 protected String getDirectoryRoot() { 179 String baseDir = context.getInstallRoot(); 180 baseDir = baseDir.substring(0, baseDir.length() - 7); 181 baseDir += "work" + File.separator; 182 return baseDir; 183 } 184 185 } 186 | Popular Tags |