Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

ModuleLoader.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  * 
00027  */
00028 
00029 package org.openmobileis.embedded.modules;
00030 
00031 import java.util.Hashtable;
00032 
00033 import org.openmobileis.common.util.log.*;
00034 import org.openmobileis.services.Service;
00035 import org.openmobileis.services.common.ServiceManager;
00036 
00045 public  abstract class ModuleLoader {
00046   private java.util.HashMap serviceMap;
00047   
00049   public ModuleLoader() {
00050     serviceMap = new java.util.HashMap(10);
00051   }
00052   
00058   public abstract void preLoadingInit();
00059   
00065   public abstract void postLoadingInit();
00066   
00073   public void loadService(java.util.Hashtable servicesList) {
00074     try {
00075       this.preLoadingInit();
00076       String[] serviceList = this.getServiceClassList();
00077       if (serviceList != null)  {
00078               for (int i=0; i<serviceList.length;i++) {
00079                 if (serviceList[i] != null) {
00080                   Service service = (Service) Class.forName(serviceList[i]).newInstance();
00081                   serviceMap.put(service.getName(), service);
00082                   // calculate service URI (without /services/
00083                   String serviceName = service.getServiceUri().substring(ServiceManager.getManager().getServiceBaseURI().length(), service.getServiceUri().length());
00084                   servicesList.put(serviceName, service);
00085                 }
00086               }
00087       }
00088       this.postLoadingInit();
00089     } catch (Exception ex)  {
00090       LogManager.traceError(LogServices.WEBSERVICE, "Can't load module");
00091       LogManager.traceError(LogServices.WEBSERVICE, ex);
00092     }
00093   }
00094   
00095   public void unloadService(Hashtable servicesList) {
00096           try {
00097                   this.preUnloadingInit();
00098               String[] serviceList = this.getServiceClassList();
00099               if (serviceList != null)  {
00100                   for (int i=0; i<serviceList.length;i++) {
00101                           if (serviceList[i] != null) {
00102                                   Service service = (Service) Class.forName(serviceList[i]).newInstance();
00103                                   serviceMap.remove(service.getName());
00104                                   // calculate service URI (without /services/
00105                                   String serviceName = service.getServiceUri().substring(ServiceManager.getManager().getServiceBaseURI().length()+1, service.getServiceUri().length());
00106                                   servicesList.remove(serviceName);
00107                           }
00108                   }
00109               }
00110                   this.postUnloadingInit();
00111           } catch (Exception ex)  {
00112                   LogManager.traceError(LogServices.WEBSERVICE, "Can't load module");
00113                   LogManager.traceError(LogServices.WEBSERVICE, ex);
00114           }
00115   }
00116   
00117   public void preUnloadingInit() {
00118   }
00119   public void postUnloadingInit() {
00120   }
00121   
00127   public abstract String[] getServiceClassList();
00128   
00134   public Service getService(String serviceName){
00135     return (Service)serviceMap.get(serviceName);
00136   }
00137   
00138 }

Generated on Wed Dec 14 21:05:34 2005 for OpenMobileIS by  doxygen 1.4.4