KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > component > common > bc > AbstractBindingComponent


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
23 package org.objectweb.petals.component.common.bc;
24
25 import org.objectweb.petals.component.common.AbstractComponent;
26 import org.objectweb.petals.component.common.HandlingException;
27 import org.objectweb.petals.component.common.su.BindingComponentServiceUnitManager;
28 import org.objectweb.petals.component.common.util.MessageExchangeWrapper;
29 import org.objectweb.petals.component.common.util.PetalsExtensionsUtil;
30 import org.objectweb.petals.tools.jbicommon.descriptor.Extensions;
31
32 /**
33  * An abstract class that can be used to easily create a new JBI Binding
34  * Component. It extends AbstractComponent to add binding component specific
35  * features.
36  *
37  * @author ofabre,alouis
38  *
39  */

40 public abstract class AbstractBindingComponent extends AbstractComponent {
41
42     /**
43      * An initialization class that handles the JBIListener and the
44      * ExternalListenerManager
45      */

46     private BindingComponentInitializer initializer;
47
48     @Override JavaDoc
49     protected BindingComponentServiceUnitManager createServiceUnitManager() {
50
51         return new BindingComponentServiceUnitManager(getContext(),
52             getLogger(), this);
53     }
54
55     @Override JavaDoc
56     protected boolean onExchange(final MessageExchangeWrapper exchange,
57         final Extensions extensions) throws HandlingException {
58         String JavaDoc externalAddress = PetalsExtensionsUtil
59             .extractValueFromKeyValueExtension(extensions,
60                 PetalsExtensionsUtil.ADDRESS);
61
62         JBIListener listener = initializer.getJbiListener();
63         if (listener == null) {
64             throw new HandlingException("No jbi Listener provided. "
65                 + "So provides node not allowed");
66         }
67
68         return listener.onJBIMessage(externalAddress, exchange, extensions);
69
70     }
71
72     @Override JavaDoc
73     protected void init() {
74         super.init();
75         initializer = new BindingComponentInitializer();
76         init(initializer);
77
78     }
79
80     /**
81      * This method must be overidden to initialize JBIListener and
82      * ExternalListenerManager handled by the
83      * {@link BindingComponentInitializer}. This method is called at the end of
84      * the component classical initialization. When this method is called, the
85      * component's delivery channel, context, logger and service unit manager
86      * are available.<br/> If this binding component must handle jbi messages,
87      * you must provide your custom {@link JBIListener} by calling
88      * "setJbiListener" on the BindingComponentInitializer.<br/> If this
89      * binding component must handle messages from external service to internal
90      * jbi components, you must provide your custom
91      * {@link ExternalListenerManager} by calling "setExternalListenerManager"
92      * on the BindingComponentInitializer.
93      *
94      * @param initializer
95      * the {@link BindingComponentInitializer} to fill
96      */

97     protected abstract void init(BindingComponentInitializer initializer);
98
99     /**
100      * An initialization class that handles the JBIListener and the
101      * ExternalListenerManager
102      *
103      * @author ofabre
104      *
105      */

106     public class BindingComponentInitializer {
107
108         private JBIListener jbiListener;
109
110         private ExternalListenerManager externalListenerManager;
111
112         public ExternalListenerManager getExternalListenerManager() {
113             return externalListenerManager;
114         }
115
116         public void setExternalListenerManager(
117             ExternalListenerManager externalListenerManager) {
118             this.externalListenerManager = externalListenerManager;
119         }
120
121         public JBIListener getJbiListener() {
122             return jbiListener;
123         }
124
125         public void setJbiListener(JBIListener jbiListener) {
126             this.jbiListener = jbiListener;
127         }
128
129     }
130
131     public BindingComponentInitializer getInitializer() {
132         return initializer;
133     }
134
135 }
136
Popular Tags