1 package org.objectweb.petals.engine.clock; 2 3 import java.io.File ; 4 import java.util.HashMap ; 5 import java.util.Map ; 6 import java.util.logging.Level ; 7 import java.util.logging.Logger ; 8 9 import javax.jbi.JBIException; 10 import javax.jbi.component.Component; 11 import javax.jbi.component.ComponentContext; 12 import javax.jbi.component.ComponentLifeCycle; 13 import javax.jbi.component.ServiceUnitManager; 14 import javax.jbi.messaging.DeliveryChannel; 15 import javax.jbi.messaging.MessageExchange; 16 import javax.jbi.messaging.MessagingException; 17 import javax.jbi.servicedesc.ServiceEndpoint; 18 import javax.management.ObjectName ; 19 import javax.xml.namespace.QName ; 20 21 import org.objectweb.petals.shared.xmlmanipulation.XMLHelper; 22 import org.w3c.dom.Document ; 23 import org.w3c.dom.DocumentFragment ; 24 import org.w3c.dom.Node ; 25 26 public class Clock implements Component, ComponentLifeCycle { 27 28 private ComponentContext context; 29 30 private DeliveryChannel channel; 31 32 @SuppressWarnings ("unused") 33 private ServiceEndpoint endpointReference; 34 35 private ClockListener listener; 36 37 private static final String SERVICE = "ClockService"; 38 private static final String ENDPOINT = "ClockEndpoint"; 39 40 private Logger logger; 41 42 private Map <String ,TimeZonesMap> timeZoneMaps; 43 44 public void init(ComponentContext context) throws JBIException 45 { 46 this.context = context; 47 48 logger = context.getLogger("",null); 49 50 logger.log(Level.INFO,""); 51 52 timeZoneMaps = new HashMap <String ,TimeZonesMap>(); 53 } 54 55 56 public void shutDown() throws JBIException 57 { 58 this.listener.stopProcessing(); 59 } 60 61 62 public void start() throws JBIException 63 { 64 logger.log(Level.INFO,""); 65 66 try 67 { 68 this.channel = this.context.getDeliveryChannel(); 69 this.listener = new ClockListener(this.channel,logger); 70 71 Thread listenerThread = new Thread (this.listener); 72 listenerThread.start(); 73 74 endpointReference = this.context.activateEndpoint(new QName (SERVICE), ENDPOINT); 75 } 76 catch (MessagingException e) 77 { 78 throw new JBIException(e); 79 } 80 81 } 82 83 84 public void stop() throws JBIException { 85 logger.log(Level.INFO,""); 86 87 this.listener.stopProcessing(); 88 } 89 90 91 public ComponentLifeCycle getLifeCycle() 92 { 93 return this; 94 } 95 96 public Document getServiceDescription(ServiceEndpoint arg0) 97 { 98 if( new QName (SERVICE).equals(arg0.getServiceName())) 99 { 100 File wsdlFile = new File (context.getInstallRoot()+"/META-INF/ClockService.wsdl"); 101 102 return XMLHelper.createDocumentFromWSDL(wsdlFile); 103 } 104 return null; 105 } 106 107 public ServiceUnitManager getServiceUnitManager() 108 { 109 return new ClockServiceUnitManager(this); 110 } 111 112 public boolean isExchangeWithConsumerOkay(ServiceEndpoint arg0, 113 MessageExchange arg1) { 114 logger.log(Level.INFO,"accept the exchange"); 115 return true; 116 } 117 118 public boolean isExchangeWithProviderOkay(ServiceEndpoint arg0, 119 MessageExchange arg1) { 120 return false; 121 } 122 123 public ServiceEndpoint resolveEndpointReference(DocumentFragment arg0) { 124 ServiceEndpoint result = null; 125 126 if (arg0 != null) 127 { 128 Node service = XMLHelper.findChild(arg0,"service",true); 129 130 if (service != null) 131 { 132 String serviceRequested = XMLHelper.getAttributeValue(service,"name"); 133 134 if (SERVICE.equals(serviceRequested)) 135 { 136 result = endpointReference; 137 } 138 } 139 } 140 return result; 141 } 142 143 public ObjectName getExtensionMBeanName() { 144 return null; 146 } 147 148 protected TimeZonesMap getTimeZonesForArtifact(String artifactName){ 149 return timeZoneMaps.get(artifactName); 150 } 151 152 protected void addTimeZonesForArtifact(String artifactName, TimeZonesMap tzm){ 153 timeZoneMaps.put(artifactName,tzm); 154 } 155 156 protected void removeTimeZonesForArtifact(String artifactName){ 157 timeZoneMaps.remove(artifactName); 158 } 159 160 protected int getOffSet (String city){ 161 Integer tz=null; 162 for (TimeZonesMap tzm : timeZoneMaps.values()){ 163 tz = tzm.getTimeZone(city); 164 } 165 if (tz!=null){ 166 return tz.intValue(); 167 } 168 else { 169 return 0; 170 } 171 } 172 } 173 | Popular Tags |