1 22 package org.objectweb.petals.demo.mortgage.evalrate.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 41 public class EvalRateEngine extends AbstractServiceEngine { 42 43 private EvalRate evalRate; 44 45 private ServiceEndpoint endpoint; 46 47 private static final String SERVICE = "EvalRateService"; 48 49 private static final String ENDPOINT = "EvalRateEndpoint"; 50 51 private static final QName SERVICE_NAME = new QName ( 52 "http://petals.objectweb.org/", SERVICE); 53 54 @Override 55 protected boolean onExchange(MessageExchangeWrapper exchange, 56 Extensions extensions) throws HandlingException { 57 58 String outContent = null; 59 boolean outResponse = false; 60 61 String opName = exchange.getOperationName(); 63 64 URI pattern = exchange.getExchangePattern(); 66 67 String stringContent = exchange.getInMessageContent(); 69 70 if ("evaluate".equalsIgnoreCase(opName) 71 && pattern.equals(MEPConstants.IN_OUT_PATTERN.value())) { 72 outContent = evalRate.evaluate(stringContent); 73 } else { 74 throw new HandlingException("Operation not allowed (" + opName 75 + ") with the following pattern (" + pattern + ")"); 76 } 77 if (outContent != null) { 78 exchange.setOutMessageContent(outContent); 79 outResponse = true; 80 } else { 81 throw new HandlingException(opName 82 + " method returns a null result"); 83 } 84 85 return outResponse; 86 } 87 88 @Override 89 public void start() throws JBIException { 90 super.start(); 91 evalRate = new EvalRateImpl(getLogger()); 92 endpoint = getContext().activateEndpoint(SERVICE_NAME, ENDPOINT); 93 } 94 95 @Override 96 public void stop() throws JBIException { 97 super.stop(); 98 evalRate = null; 99 getContext().deactivateEndpoint(endpoint); 100 } 101 102 } 103 | Popular Tags |