001: /*
002: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portal.spi;
020:
021: import java.rmi.RemoteException;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.w3c.dom.Element;
026:
027: import com.nabhinc.spi.UserAdminService;
028: import com.nabhinc.spi.UserAdminServiceFactory;
029: import com.nabhinc.ws.core.WebServiceException;
030: import com.nabhinc.ws.server.WebServiceDirectoryLocator;
031: import com.nabhinc.ws.server.WebServiceInfo;
032: import com.nabhinc.ws.server.WebServiceLifeCycleEvent;
033: import com.nabhinc.ws.server.WebServiceLifeCycleListener;
034: import com.nabhinc.ws.server.WebServiceManager;
035: import com.nabhinc.ws.server.WebServiceServlet;
036:
037: /**
038: *
039: *
040: * @author Padmanabh Dabke
041: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
042: */
043: public class UserAdminServiceLocator implements
044: WebServiceLifeCycleListener, UserAdminServiceFactory {
045: private static UserAdminService uasSingleton = null;
046: private static UserAdminServiceLocator uasLocatorSingleton = null;
047: private static String uasServiceName = null;
048: private static Log uasLogger = LogFactory
049: .getLog(UserAdminServiceLocator.class);
050:
051: public static UserAdminService getUserAdminService() {
052: if (uasSingleton == null) {
053: try {
054: WebServiceInfo wsInfo = WebServiceDirectoryLocator
055: .getWebServiceDirectory().lookupByType(
056: UserAdminService.class);
057: if (wsInfo == null) {
058: uasLogger
059: .warn("User admin web service has not been started.");
060: } else {
061: uasSingleton = (UserAdminService) wsInfo.webService;
062: if (uasLocatorSingleton == null) {
063: uasLocatorSingleton = new UserAdminServiceLocator();
064: WebServiceManager
065: .addWebServiceLifeCycleListener(uasLocatorSingleton);
066: }
067: uasServiceName = wsInfo.name;
068: }
069: } catch (WebServiceException e) {
070: uasLogger
071: .error(
072: "Failed to get instance of user administration service.",
073: e);
074: }
075: }
076: return uasSingleton;
077: }
078:
079: public static UserAdminService getUserAdminService(String serviceURL)
080: throws RemoteException {
081: // For now return the local instance. In future, we need to return a stub
082: // if the URL points to a remote service.
083: try {
084: return (UserAdminService) WebServiceServlet.getInstance()
085: .getWebServiceInfo(serviceURL).webService;
086: } catch (WebServiceException e) {
087: throw new RemoteException("Failed to get webservice info.",
088: e);
089: }
090: }
091:
092: public void processEvent(WebServiceLifeCycleEvent e) {
093: if (e.webServiceName.equals(uasServiceName)
094: && (e.type == WebServiceLifeCycleEvent.WSLCE_DELETED
095: || e.type == WebServiceLifeCycleEvent.WSLCE_RELOADED || e.type == WebServiceLifeCycleEvent.WSLCE_UNLOADED)) {
096: uasSingleton = null;
097: }
098:
099: }
100:
101: public UserAdminService getService() {
102: return UserAdminServiceLocator.getUserAdminService();
103: }
104:
105: /* (non-Javadoc)
106: * @see com.nabhinc.core.XMLInitable#init(org.w3c.dom.Element)
107: */
108: public void init(Element config) throws Exception {
109: // Not initialization is needed.
110:
111: }
112: }
|