01: /*
02: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * This program 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
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19: package com.nabhinc.portal.spi;
20:
21: import java.rmi.RemoteException;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25:
26: import com.nabhinc.spi.AuthenticationService;
27: import com.nabhinc.ws.core.WebServiceException;
28: import com.nabhinc.ws.server.WebServiceDirectoryLocator;
29: import com.nabhinc.ws.server.WebServiceInfo;
30: import com.nabhinc.ws.server.WebServiceLifeCycleEvent;
31: import com.nabhinc.ws.server.WebServiceLifeCycleListener;
32: import com.nabhinc.ws.server.WebServiceManager;
33: import com.nabhinc.ws.server.WebServiceServlet;
34:
35: /**
36: *
37: *
38: * @author Padmanabh Dabke
39: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
40: */
41: public class AuthenticationServiceLocator implements
42: WebServiceLifeCycleListener {
43: private static AuthenticationService aslSingleton = null;
44: private static AuthenticationServiceLocator aslLocatorSingleton = null;
45: private static String aslServiceName = null;
46: private static Log asLogger = LogFactory
47: .getLog(AuthenticationServiceLocator.class);
48:
49: public static AuthenticationService getAuthenticationService() {
50: if (aslSingleton == null) {
51: try {
52: WebServiceInfo wsInfo = WebServiceDirectoryLocator
53: .getWebServiceDirectory().lookupByType(
54: AuthenticationService.class);
55: if (wsInfo == null) {
56: asLogger
57: .warn("Authentication web service has not been started.");
58: } else {
59: aslSingleton = (AuthenticationService) wsInfo.webService;
60: if (aslLocatorSingleton == null) {
61: aslLocatorSingleton = new AuthenticationServiceLocator();
62: WebServiceManager
63: .addWebServiceLifeCycleListener(aslLocatorSingleton);
64: }
65: aslServiceName = wsInfo.name;
66: }
67: } catch (WebServiceException e) {
68: asLogger
69: .error(
70: "Failed to get instance of authentication service.",
71: e);
72: }
73: }
74: return aslSingleton;
75: }
76:
77: public static AuthenticationService getAuthenticationService(
78: String serviceURL) throws RemoteException {
79: // For now return the local instance. In future, we need to return a stub
80: // if the URL points to a remote service.
81: try {
82: return (AuthenticationService) WebServiceServlet
83: .getInstance().getWebServiceInfo(serviceURL).webService;
84: } catch (WebServiceException e) {
85: throw new RemoteException("Failed to get webservice info.",
86: e);
87: }
88: }
89:
90: public void processEvent(WebServiceLifeCycleEvent e) {
91: if (e.webServiceName.equals(aslServiceName)
92: && (e.type == WebServiceLifeCycleEvent.WSLCE_DELETED
93: || e.type == WebServiceLifeCycleEvent.WSLCE_RELOADED || e.type == WebServiceLifeCycleEvent.WSLCE_UNLOADED)) {
94: aslSingleton = null;
95: }
96:
97: }
98:
99: }
|