KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > component > common > PetalsComponent


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: PetalsComponent.java 601 2006-06-13 12:53:50Z wjoseph $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.component.common;
23
24 import java.util.logging.Level JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26
27 import javax.jbi.JBIException;
28 import javax.jbi.component.Component;
29 import javax.jbi.component.ComponentContext;
30 import javax.jbi.component.ComponentLifeCycle;
31 import javax.jbi.component.ServiceUnitManager;
32 import javax.jbi.messaging.DeliveryChannel;
33 import javax.jbi.messaging.MessageExchange;
34 import javax.jbi.servicedesc.ServiceEndpoint;
35 import javax.management.ObjectName JavaDoc;
36
37 import org.objectweb.petals.component.common.listener.AbstractInternalMEProcessor;
38 import org.objectweb.petals.component.common.listener.MessageExchangeListener;
39 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager;
40 import org.objectweb.petals.component.common.util.ComponentLogger;
41
42 import org.w3c.dom.Document JavaDoc;
43 import org.w3c.dom.DocumentFragment JavaDoc;
44
45 /**
46  * This class provides a basic component, allowing developper to create simply a
47  * new JBI component
48  *
49  * @author wjoseph - eBMWebSourcing
50  *
51  */

52 public abstract class PetalsComponent implements Component, ComponentLifeCycle {
53
54     /**
55      * The component name
56      */

57     protected String JavaDoc componentName;
58
59     /**
60      * The component's delivery channel
61      */

62     protected DeliveryChannel channel;
63
64     /**
65      * the componentContext
66      */

67     private ComponentContext context;
68
69     /**
70      * The message exhange listener
71      */

72     private MessageExchangeListener listener;
73
74     /**
75      * The component's logger
76      */

77     protected Logger JavaDoc logger;
78
79     /**
80      * The component's service unit manager
81      */

82     protected PetalsServiceUnitManager serviceUnitManager;
83
84     /**
85      * Default contructor
86      */

87     public PetalsComponent() {
88         this.serviceUnitManager = createServiceUnitManager();
89     }
90
91     /*
92      * (non-Javadoc)
93      *
94      * @see javax.jbi.component.ComponentLifeCycle#getExtensionMBeanName()
95      */

96     public ObjectName JavaDoc getExtensionMBeanName() {
97         return null;
98     }
99
100     /*
101      * (non-Javadoc)
102      *
103      * @see javax.jbi.component.ComponentLifeCycle#init(javax.jbi.component.ComponentContext)
104      */

105     public void init(ComponentContext ctx) throws JBIException {
106         this.context = ctx;
107         Logger JavaDoc log = context.getLogger("", null);
108         logger = new ComponentLogger(log, log.getName(), log
109             .getResourceBundleName(), componentName);
110         channel = ctx.getDeliveryChannel();
111         logger.log(Level.INFO, componentName + "init");
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see javax.jbi.component.ComponentLifeCycle#shutDown()
118      */

119     public void shutDown() throws JBIException {
120         logger.log(Level.INFO, componentName + " shutdown");
121         listener = null;
122     }
123
124     /*
125      * (non-Javadoc)
126      *
127      * @see javax.jbi.component.ComponentLifeCycle#start()
128      */

129     public void start() throws JBIException {
130         logger.log(Level.INFO, componentName + " start");
131         AbstractInternalMEProcessor processor = createMessageExchangeProcessor();
132         listener = createMessageExchangeListener(processor);
133         listener.listen();
134     }
135
136     protected abstract AbstractInternalMEProcessor createMessageExchangeProcessor();
137
138     /**
139      * Creates a new MessageExchangeListener
140      *
141      * @param processor
142      * the messageExchange processor
143      * @return
144      */

145     protected MessageExchangeListener createMessageExchangeListener(
146         AbstractInternalMEProcessor processor) {
147         return new MessageExchangeListener(channel, processor,
148             MessageExchangeListener.IgnoredStatus.DONE_AND_ERROR_IGNORED, 0,
149             context.getComponentName());
150     }
151
152     /**
153      * (non-Javadoc)
154      *
155      * @see javax.jbi.component.ComponentLifeCycle#stop()
156      */

157     public void stop() throws JBIException {
158         logger.log(Level.INFO, componentName + " stop");
159         this.listener.terminate();
160     }
161
162     /**
163      * Create a new service unit manager
164      *
165      * @return new instance of service unit manager
166      */

167     protected PetalsServiceUnitManager createServiceUnitManager() {
168         return new PetalsServiceUnitManager();
169     }
170
171     /*
172      * (non-Javadoc)
173      *
174      * @see javax.jbi.component.Component#getLifeCycle()
175      */

176     public ComponentLifeCycle getLifeCycle() {
177         return this;
178     }
179
180     /*
181      * (non-Javadoc)
182      *
183      * @see javax.jbi.component.Component#getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint)
184      */

185     public Document JavaDoc getServiceDescription(ServiceEndpoint endpoint) {
186         return serviceUnitManager.getServiceDescription(endpoint);
187     }
188
189     /*
190      * (non-Javadoc)
191      *
192      * @see javax.jbi.component.Component#getServiceUnitManager()
193      */

194     public ServiceUnitManager getServiceUnitManager() {
195         return serviceUnitManager;
196     }
197
198     /*
199      * (non-Javadoc)
200      *
201      * @see javax.jbi.component.Component#isExchangeWithConsumerOkay(javax.jbi.servicedesc.ServiceEndpoint,
202      * javax.jbi.messaging.MessageExchange)
203      */

204     public boolean isExchangeWithConsumerOkay(ServiceEndpoint endpoint,
205         MessageExchange exchange) {
206         return true;
207     }
208
209     /*
210      * (non-Javadoc)
211      *
212      * @see javax.jbi.component.Component#isExchangeWithProviderOkay(javax.jbi.servicedesc.ServiceEndpoint,
213      * javax.jbi.messaging.MessageExchange)
214      */

215     public boolean isExchangeWithProviderOkay(ServiceEndpoint endpoint,
216         MessageExchange exchange) {
217         return true;
218     }
219
220     /*
221      * (non-Javadoc)
222      *
223      * @see javax.jbi.component.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment)
224      */

225     public ServiceEndpoint resolveEndpointReference(DocumentFragment JavaDoc epr) {
226         return null;
227     }
228
229     /**
230      * Returns the component's name
231      *
232      * @return the componentName
233      */

234     public String JavaDoc getComponentName() {
235         return componentName;
236     }
237
238     /**
239      * Set componentName
240      *
241      * @param componentName
242      */

243     public void setComponentName(String JavaDoc componentName) {
244         this.componentName = componentName;
245     }
246
247 }
248
Popular Tags