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

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 org.openmobileis.common.util.log.*;
00032 import org.openmobileis.services.Service;
00033 import org.openmobileis.services.ServiceManager;
00034 
00043 public  abstract class ModuleLoader {
00044   private java.util.HashMap serviceMap;
00045   
00047   public ModuleLoader() {
00048     serviceMap = new java.util.HashMap(10);
00049   }
00050   
00056   public abstract void preLoadingInit();
00057   
00063   public abstract void postLoadingInit();
00064   
00071   public void loadService(java.util.Hashtable servicesList) {
00072     try {
00073       this.preLoadingInit();
00074       String[] serviceList = this.getServiceClassList();
00075       if (serviceList != null)  {
00076               for (int i=0; i<serviceList.length;i++) {
00077                 if (serviceList[i] != null) {
00078                   Service service = (Service) Class.forName(serviceList[i]).newInstance();
00079                   serviceMap.put(service.getName(), service);
00080                   // calculate service URI (without /services/
00081                   String serviceName = service.getServiceUri().substring(ServiceManager.getManager().getServiceBaseURI().length(), service.getServiceUri().length());
00082                   servicesList.put(serviceName, service);
00083                 }
00084               }
00085       }
00086       this.postLoadingInit();
00087     } catch (Exception ex)  {
00088       LogManager.traceError(LogServices.WEBSERVICE, "Can't load module");
00089       LogManager.traceError(LogServices.WEBSERVICE, ex);
00090     }
00091   }
00092   
00098   public abstract String[] getServiceClassList();
00099   
00105   public Service getService(String serviceName){
00106     return (Service)serviceMap.get(serviceName);
00107   }
00108   
00109 }

Generated on Thu Oct 6 10:06:33 2005 for OpenMobileIS by  doxygen 1.4.3