KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > engine > clock > sdk > ClockEngine


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 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.engine.clock.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 public class ClockEngine extends AbstractServiceEngine {
37
38     private Clock clock;
39
40     private ServiceEndpoint endpoint;
41
42     private static final String JavaDoc SERVICE = "ClockService";
43
44     private static final String JavaDoc ENDPOINT = "ClockEndpoint";
45
46     private static final QName JavaDoc SERVICE_NAME = new QName JavaDoc(
47             "http://petals.objectweb.org/", SERVICE);
48
49     @Override JavaDoc
50     protected boolean onExchange(MessageExchangeWrapper exchange, Extensions extensions)
51             throws HandlingException {
52
53         // Get Operation name
54
String JavaDoc opName = exchange.getOperationName();
55
56         // Get Message Exchange Pattern
57
URI JavaDoc pattern = exchange.getExchangePattern();
58
59         if ("time".equalsIgnoreCase(opName)
60                 && pattern.equals(MEPConstants.IN_OUT_PATTERN.value())) {
61
62             String JavaDoc 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 JavaDoc
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 JavaDoc
84     public void stop() throws JBIException {
85         super.stop();
86         getContext().deactivateEndpoint(endpoint);
87         clock = null;
88     }
89
90 }
91
Popular Tags