1 22 package org.objectweb.petals.engine.clock.sdk; 23 24 import java.net.URI ; 25 26 import javax.jbi.JBIException; 27 import javax.jbi.servicedesc.ServiceEndpoint; 28 import javax.xml.namespace.QName ; 29 30 import org.objectweb.petals.component.common.HandlingException; 31 import org.objectweb.petals.component.common.MEPConstants; 32 import org.objectweb.petals.component.common.se.AbstractServiceEngine; 33 import org.objectweb.petals.component.common.util.MessageExchangeWrapper; 34 import org.objectweb.petals.tools.jbicommon.descriptor.Extensions; 35 36 public class ClockEngine extends AbstractServiceEngine { 37 38 private Clock clock; 39 40 private ServiceEndpoint endpoint; 41 42 private static final String SERVICE = "ClockService"; 43 44 private static final String ENDPOINT = "ClockEndpoint"; 45 46 private static final QName SERVICE_NAME = new QName ( 47 "http://petals.objectweb.org/", SERVICE); 48 49 @Override 50 protected boolean onExchange(MessageExchangeWrapper exchange, Extensions extensions) 51 throws HandlingException { 52 53 String opName = exchange.getOperationName(); 55 56 URI pattern = exchange.getExchangePattern(); 58 59 if ("time".equalsIgnoreCase(opName) 60 && pattern.equals(MEPConstants.IN_OUT_PATTERN.value())) { 61 62 String en = clock.time(); 63 64 exchange.setOutMessageContent(en); 65 66 } else { 67 throw new HandlingException("Operation not allowed (" 68 + exchange.getOperation().getLocalPart() 69 + ") with the following pattern (" 70 + exchange.getPattern().toString() + ")"); 71 } 72 73 return true; 74 } 75 76 @Override 77 public void start() throws JBIException { 78 super.start(); 79 endpoint = getContext().activateEndpoint(SERVICE_NAME, ENDPOINT); 80 clock = new ClockImpl(getLogger()); 81 } 82 83 @Override 84 public void stop() throws JBIException { 85 super.stop(); 86 getContext().deactivateEndpoint(endpoint); 87 clock = null; 88 } 89 90 } 91 | Popular Tags |