1 22 package org.objectweb.petals.engine.csv; 23 24 import java.util.HashMap ; 25 import java.util.Properties ; 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 29 import javax.jbi.JBIException; 30 import javax.jbi.component.Component; 31 import javax.jbi.component.ComponentContext; 32 import javax.jbi.component.ComponentLifeCycle; 33 import javax.jbi.component.ServiceUnitManager; 34 import javax.jbi.messaging.DeliveryChannel; 35 import javax.jbi.messaging.MessageExchange; 36 import javax.jbi.servicedesc.ServiceEndpoint; 37 import javax.management.ObjectName ; 38 import javax.xml.namespace.QName ; 39 40 import org.objectweb.petals.component.common.listener.MessageExchangeListener; 41 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager; 42 import org.objectweb.petals.component.common.util.ComponentLogger; 43 import org.objectweb.petals.component.common.util.XMLHelper; 44 45 import org.w3c.dom.Document ; 46 import org.w3c.dom.DocumentFragment ; 47 import org.w3c.dom.Node ; 48 49 59 public class Csv implements Component, ComponentLifeCycle { 60 61 protected DeliveryChannel channel; 62 63 private HashMap <String , Properties > mapEndpointCsv; 64 65 protected PetalsServiceUnitManager suManager; 66 67 protected ComponentContext context; 68 69 private MessageExchangeListener listener; 70 71 protected Logger logger; 72 73 public ObjectName getExtensionMBeanName() { 74 return null; 75 } 76 77 public ComponentLifeCycle getLifeCycle() { 78 return this; 79 } 80 81 84 public Document getServiceDescription(ServiceEndpoint arg0) { 85 return suManager.getServiceDescription(arg0); 86 } 87 88 public ServiceUnitManager getServiceUnitManager() { 89 logger.log(Level.INFO, 90 "Component instance asked to provide a ServiceUnitManager."); 91 return suManager; 92 } 93 94 public void init(ComponentContext ctx) throws JBIException { 95 this.context = ctx; 96 Logger javaLogger = ctx.getLogger("", null); 97 logger = new ComponentLogger(javaLogger, javaLogger.getName(), 98 javaLogger.getResourceBundleName(), ctx.getComponentName()); 99 100 logger.log(Level.INFO, "init"); 101 this.channel = ctx.getDeliveryChannel(); 102 this.mapEndpointCsv = new HashMap <String , Properties >(); 103 } 104 105 public boolean isExchangeWithConsumerOkay(ServiceEndpoint arg0, 106 MessageExchange arg1) { 107 return true; 108 } 109 110 public boolean isExchangeWithProviderOkay(ServiceEndpoint arg0, 111 MessageExchange arg1) { 112 return false; 113 } 114 115 118 public ServiceEndpoint resolveEndpointReference(DocumentFragment arg0) { 119 ServiceEndpoint result = null; 120 121 if (arg0 != null) { 122 String prefix = arg0.getPrefix(); 123 if (prefix == null) { 124 prefix = new String (); 125 } else { 126 prefix += ":"; 127 } 128 Node service = XMLHelper.findChild(arg0, prefix + "service", true); 129 130 if (service != null) { 131 String serviceRequested = XMLHelper.getAttributeValue(service, 132 "name"); 133 if (serviceRequested != null) { 134 result = suManager.findEndpointForService(QName 135 .valueOf(serviceRequested)); 136 } 137 } 138 } 139 return result; 140 } 141 142 public void shutDown() throws JBIException { 143 logger.log(Level.INFO, "shutDown"); 144 listener = null; 145 } 146 147 public void start() throws JBIException { 148 logger.log(Level.INFO, "start"); 149 CsvProcessor processor = new CsvProcessor(channel, logger, 150 mapEndpointCsv); 151 listener = new MessageExchangeListener(channel, processor, 152 MessageExchangeListener.IgnoredStatus.DONE_AND_ERROR_IGNORED, 0); 153 listener.listen(); 154 CsvSUHandler SUHandler = new CsvSUHandler(context, this.mapEndpointCsv, 155 logger); 156 this.suManager = new PetalsServiceUnitManager(context, logger); 157 158 suManager.addNewHandler(SUHandler); 159 } 160 161 public void stop() throws JBIException { 162 logger.log(Level.INFO, "stop"); 163 this.listener.terminate(); 164 } 165 166 } 167 | Popular Tags |