1 22 package org.objectweb.petals.engine.edifact; 23 24 import java.util.HashMap ; 25 import java.util.Map ; 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.ebmwebsourcing.b2bgw.edifact.dictionary.Dictionary; 41 import org.objectweb.petals.component.common.listener.MessageExchangeListener; 42 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager; 43 import org.objectweb.petals.component.common.util.ComponentLogger; 44 import org.objectweb.petals.component.common.util.XMLHelper; 45 46 import org.w3c.dom.Document ; 47 import org.w3c.dom.DocumentFragment ; 48 import org.w3c.dom.Node ; 49 50 57 public class Edifact implements Component, ComponentLifeCycle { 58 59 protected DeliveryChannel channel; 60 61 protected PetalsServiceUnitManager suManager; 62 63 protected Map <QName , QName > mapEndpointXslt; 64 65 private ComponentContext context; 66 67 private MessageExchangeListener listener; 68 69 private Logger logger; 70 71 public ObjectName getExtensionMBeanName() { 72 return null; 73 } 74 75 public ComponentLifeCycle getLifeCycle() { 76 return this; 77 } 78 79 82 public Document getServiceDescription(ServiceEndpoint arg0) { 83 return suManager.getServiceDescription(arg0); 84 } 85 86 public ServiceUnitManager getServiceUnitManager() { 87 return suManager; 88 } 89 90 public void init(ComponentContext ctx) throws JBIException { 91 this.context = ctx; 92 Logger log = context.getLogger("", null); 93 logger = new ComponentLogger(log, log.getName(), log 94 .getResourceBundleName(), context.getComponentName()); 95 logger.log(Level.INFO, "init()"); 96 97 this.channel = ctx.getDeliveryChannel(); 98 this.mapEndpointXslt = new HashMap <QName , QName >(); 99 } 100 101 public boolean isExchangeWithConsumerOkay(ServiceEndpoint arg0, 102 MessageExchange arg1) { 103 104 logger.log(Level.FINE, "accept the exchange"); 105 return true; 106 } 107 108 public boolean isExchangeWithProviderOkay(ServiceEndpoint arg0, 109 MessageExchange arg1) { 110 return false; 111 } 112 113 116 public ServiceEndpoint resolveEndpointReference(DocumentFragment arg0) { 117 ServiceEndpoint result = null; 118 119 if (arg0 != null) { 120 String prefix = arg0.getPrefix(); 121 if (prefix == null) { 122 prefix = new String (); 123 } else { 124 prefix += ":"; 125 } 126 Node service = XMLHelper.findChild(arg0, prefix + "service", true); 127 128 if (service != null) { 129 String serviceRequested = XMLHelper.getAttributeValue(service, 130 "name"); 131 if (serviceRequested != null) { 132 result = suManager.findEndpointForService(QName 133 .valueOf(serviceRequested)); 134 } 135 } 136 } 137 return result; 138 } 139 140 public void shutDown() throws JBIException { 141 logger.log(Level.INFO, "shutDown()"); 142 listener = null; 143 144 } 145 146 public void start() throws JBIException { 147 logger.log(Level.INFO, "start()"); 148 149 EdifactProcessor processor = new EdifactProcessor(channel, logger, 150 this.context, this.mapEndpointXslt); 151 152 listener = new MessageExchangeListener(channel, processor, 153 MessageExchangeListener.IgnoredStatus.DONE_AND_ERROR_IGNORED, 0, 154 context.getComponentName()); 155 listener.listen(); 156 EdifactSUHandler SUHandler = new EdifactSUHandler(context, 157 this.mapEndpointXslt, logger); 158 EdifactMappingHandler mappingHandler = new EdifactMappingHandler( 159 context, logger); 160 this.suManager = new PetalsServiceUnitManager(context, logger); 161 162 suManager.addNewHandler(SUHandler); 163 suManager.addNewHandler(mappingHandler); 164 165 Dictionary.getInstance(); 166 } 167 168 public void stop() throws JBIException { 169 logger.log(Level.INFO, "stop"); 170 this.listener.terminate(); 171 172 } 173 174 } 175 | Popular Tags |