KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > demo > mortgage > workflow > sdk > MortgageWorkflowEngine


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.workflow.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 MortgageWorkflowEngine extends AbstractServiceEngine {
42
43     private ServiceEndpoint endpoint1;
44
45     private ServiceEndpoint endpoint2;
46
47     private static final String JavaDoc SERVICE = "MortgageWorkflow";
48
49     private static final QName JavaDoc SERVICE_NAME = new QName JavaDoc(
50             "http://petals.objectweb.org/", SERVICE);
51
52     public static final String JavaDoc ENDPOINT1 = "simpleMortgageProfiler";
53
54     public static final String JavaDoc ENDPOINT2 = "detailedMortgageProfiler";
55
56     private MortgageWorkflow workflow;
57
58     @Override JavaDoc
59     protected boolean onExchange(MessageExchangeWrapper exchange,
60             Extensions extensions) throws HandlingException {
61         String JavaDoc outContent = null;
62         boolean outResponse = false;
63
64         // Get Operation name
65
String JavaDoc opName = exchange.getOperationName();
66
67         // Get Message Exchange Pattern
68
URI JavaDoc pattern = exchange.getExchangePattern();
69
70         // Get in Message content
71
String JavaDoc stringContent = exchange.getInMessageContent();
72
73         // Get Endpointname
74
String JavaDoc endpointName = exchange.getEndpointName();
75
76         if ("orchestrate".equalsIgnoreCase(opName)
77                 && pattern.equals(MEPConstants.IN_OPTIONAL_OUT_PATTERN.value())) {
78             try {
79                 outContent = workflow.orchestrate(endpointName, stringContent);
80             } catch (Exception JavaDoc e) {
81                 throw new HandlingException(e);
82             }
83         } else {
84             throw new HandlingException("Operation not allowed (" + opName
85                     + ") with the following pattern (" + pattern + ")");
86         }
87
88         if (outContent != null) {
89             exchange.setOutMessageContent(outContent);
90             outResponse = true;
91         } else {
92             throw new HandlingException(opName
93                     + " method returns a null result");
94         }
95
96         return outResponse;
97     }
98
99     @Override JavaDoc
100     public void start() throws JBIException {
101         super.start();
102         workflow = new MortgageWorkflowImpl(getLogger(), getChannel());
103         endpoint1 = getContext().activateEndpoint(SERVICE_NAME, ENDPOINT1);
104         endpoint2 = getContext().activateEndpoint(SERVICE_NAME, ENDPOINT2);
105
106     }
107
108     @Override JavaDoc
109     public void stop() throws JBIException {
110         super.stop();
111         workflow = null;
112         getContext().deactivateEndpoint(endpoint1);
113         getContext().deactivateEndpoint(endpoint2);
114     }
115
116 }
117
Popular Tags