01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.core.event;
23:
24: import org.jboss.portal.jems.as.system.AbstractJBossService;
25:
26: /**
27: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
28: * @version $Revision: 8786 $
29: */
30: public class PortalEventListenerServiceImpl extends
31: AbstractJBossService implements PortalEventListenerService {
32:
33: protected String registryId;
34: protected PortalEventListenerRegistry registry;
35: protected Object listener;
36: protected String listenerClassName;
37:
38: public String getListenerClassName() {
39: return listenerClassName;
40: }
41:
42: public void setListenerClassName(String listenerClassName) {
43: this .listenerClassName = listenerClassName;
44: }
45:
46: public String getRegistryId() {
47: return registryId;
48: }
49:
50: public void setRegistryId(String registryId) {
51: this .registryId = registryId;
52: }
53:
54: public PortalEventListenerRegistry getRegistry() {
55: return registry;
56: }
57:
58: public void setRegistry(PortalEventListenerRegistry registry) {
59: this .registry = registry;
60: }
61:
62: public Object getListener() {
63: return listener;
64: }
65:
66: protected void startService() throws Exception {
67: log.debug("Getting listener class " + listenerClassName);
68: ClassLoader loader = Thread.currentThread()
69: .getContextClassLoader();
70: Class listenerClass = loader.loadClass(listenerClassName);
71: log.debug("Creating listener instance of "
72: + listenerClass.getName());
73: listener = listenerClass.newInstance();
74:
75: //
76: log.debug("Registering listener instance "
77: + listenerClass.getName() + " with id " + registryId);
78: registry.registerListener(registryId, listener);
79: }
80:
81: protected void stopService() {
82: log.debug("Unregistering listener instance with id "
83: + registryId);
84: registry.unregisterListener(registryId);
85:
86: //
87: listener = null;
88: }
89: }
|