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.RoleAdminService;
028: import com.nabhinc.spi.RoleAdminServiceFactory;
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 RoleAdminServiceLocator implements
044: WebServiceLifeCycleListener, RoleAdminServiceFactory {
045: private static RoleAdminService raslSingleton = null;
046: private static RoleAdminServiceLocator raslLocatorSingleton = null;
047: private static String raslServiceName = null;
048: private static Log asLogger = LogFactory
049: .getLog(RoleAdminServiceLocator.class);
050:
051: public static RoleAdminService getRoleAdminService() {
052: if (raslSingleton == null) {
053: try {
054: WebServiceInfo wsInfo = WebServiceDirectoryLocator
055: .getWebServiceDirectory().lookupByType(
056: RoleAdminService.class);
057: if (wsInfo == null) {
058: asLogger
059: .warn("Role admin web service has not been started.");
060: } else {
061: raslSingleton = (RoleAdminService) wsInfo.webService;
062: if (raslLocatorSingleton == null) {
063: raslLocatorSingleton = new RoleAdminServiceLocator();
064: WebServiceManager
065: .addWebServiceLifeCycleListener(raslLocatorSingleton);
066: }
067: raslServiceName = wsInfo.name;
068: }
069: } catch (WebServiceException e) {
070: asLogger
071: .error(
072: "Failed to get instance of role admin service.",
073: e);
074: }
075: }
076: return raslSingleton;
077: }
078:
079: public static RoleAdminService getRoleAdminService(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 (RoleAdminService) 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(raslServiceName)
094: && (e.type == WebServiceLifeCycleEvent.WSLCE_DELETED
095: || e.type == WebServiceLifeCycleEvent.WSLCE_RELOADED || e.type == WebServiceLifeCycleEvent.WSLCE_UNLOADED)) {
096: raslSingleton = null;
097: }
098:
099: }
100:
101: /* (non-Javadoc)
102: * @see com.nabhinc.spi.RoleAdminServiceFactory#getService()
103: */
104: public RoleAdminService getService() {
105: return RoleAdminServiceLocator.getRoleAdminService();
106: }
107:
108: /* (non-Javadoc)
109: * @see com.nabhinc.core.XMLInitable#init(org.w3c.dom.Element)
110: */
111: public void init(Element config) throws Exception {
112: // No initialization needed.
113:
114: }
115:
116: }
|