KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > engine > pojo > PojoSE


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: PojoSE.java 676 2006-06-27 15:44:03Z alouis $
20  * -------------------------------------------------------------------------
21  */

22
23 package org.objectweb.petals.engine.pojo;
24
25 import java.util.HashMap JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import javax.jbi.JBIException;
29 import javax.jbi.component.ComponentContext;
30 import javax.jbi.servicedesc.ServiceEndpoint;
31
32 import org.objectweb.petals.component.common.HandlingException;
33 import org.objectweb.petals.component.common.se.AbstractServiceEngine;
34 import org.objectweb.petals.component.common.su.ServiceUnitDataHandler;
35 import org.objectweb.petals.component.common.su.SimpleServiceUnitManager;
36 import org.objectweb.petals.component.common.util.MessageExchangeWrapper;
37 import org.objectweb.petals.tools.jbicommon.descriptor.Extensions;
38
39 public class PojoSE extends AbstractServiceEngine {
40
41     private Map JavaDoc<String JavaDoc, Pojo> pojos;
42
43     public void init(final ComponentContext compContext) throws JBIException {
44         super.init(compContext);
45
46         pojos = new HashMap JavaDoc<String JavaDoc, Pojo>();
47
48         // set the SU listener that will perform extra process on SU deployment
49
PojoServiceUnitListener suListener = new PojoServiceUnitListener(this,
50                 pojos);
51         setServiceUnitListener(suListener);
52     }
53
54     @Override JavaDoc
55     protected boolean onExchange(MessageExchangeWrapper exchangeWrapper, Extensions extensions)
56             throws HandlingException {
57         ServiceEndpoint ep = exchangeWrapper.getEndpoint();
58
59         ServiceUnitDataHandler suData = ((SimpleServiceUnitManager) getServiceUnitManager())
60                 .getSuDataHandlerForEp(ep);
61
62         if (suData == null) {
63             throw new HandlingException("No POJO is found for service "
64                     + ep.getServiceName());
65         }
66         Pojo pojo = pojos.get(suData.getName());
67         return pojo.callOnExchangeMethod(exchangeWrapper);
68     }
69
70 }
71
Popular Tags