KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > demo > mortgage > evalrate > sdk > EvalRateEngine


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id$
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.demo.mortgage.evalrate.sdk;
23
24 import java.net.URI JavaDoc;
25
26 import javax.jbi.JBIException;
27 import javax.jbi.servicedesc.ServiceEndpoint;
28 import javax.xml.namespace.QName JavaDoc;
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 /**
37  *
38  * @author ofabre
39  *
40  */

41 public class EvalRateEngine extends AbstractServiceEngine {
42
43     private EvalRate evalRate;
44
45     private ServiceEndpoint endpoint;
46
47     private static final String JavaDoc SERVICE = "EvalRateService";
48
49     private static final String JavaDoc ENDPOINT = "EvalRateEndpoint";
50
51     private static final QName JavaDoc SERVICE_NAME = new QName JavaDoc(
52             "http://petals.objectweb.org/", SERVICE);
53
54     @Override JavaDoc
55     protected boolean onExchange(MessageExchangeWrapper exchange,
56             Extensions extensions) throws HandlingException {
57
58         String JavaDoc outContent = null;
59         boolean outResponse = false;
60
61         // Get Operation name
62
String JavaDoc opName = exchange.getOperationName();
63
64         // Get Message Exchange Pattern
65
URI JavaDoc pattern = exchange.getExchangePattern();
66
67         // Get in Message content
68
String JavaDoc 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 JavaDoc
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 JavaDoc
96     public void stop() throws JBIException {
97         super.stop();
98         evalRate = null;
99         getContext().deactivateEndpoint(endpoint);
100     }
101
102 }
103
Popular Tags