ModuleServerManager.java

00001 
00025 package org.openmobileis.module.server;
00026 
00027 import java.io.File;
00028 import java.util.HashMap;
00029 
00030 import org.openmobileis.common.util.PropertiesManager;
00031 import org.openmobileis.common.util.collection.Array;
00032 import org.openmobileis.common.util.log.LogManager;
00033 import org.openmobileis.synchro.openmsp.server.synctarget.SynchroTargerManager;
00034 
00035 /*
00036  * Title:        OpenMobileIS project source <BR>
00037  * Description:
00038  * @author      Philippe Delrieu
00039  * @since       JDK 1.1
00040  * @version 1.0.
00041  */
00042 
00043 public final class ModuleServerManager {
00044   private static ModuleServerManager manager;
00048   private ModuleServerManager() {
00049     this.initManager();
00050   }
00051   
00052   public static ModuleServerManager getManager()    {
00053     if (manager == null)    {
00054       synchronized(ModuleServerManager.class)   {
00055         if (manager == null)    {
00056           manager = new ModuleServerManager();
00057         }
00058       }
00059     }
00060     return manager;
00061   }
00062   
00063   private void initManager() {
00064     String repositoryPath = PropertiesManager.getManager().getProperty("org.openmobileis.bundle.module.repositorypath");
00065     if (repositoryPath == null) {
00066       LogManager.traceWarning(0, "org.openmobileis.bundle.module.repositorypath not set. Use user.dir/repository");
00067       repositoryPath = System.getProperty("user.dir")+"/repository";
00068     }
00069     File repFile = new File(repositoryPath);
00070     if (!repFile.exists())  {
00071       LogManager.traceError(0, "Error, repository path :"+repositoryPath+" does not exist. Stop loading module");
00072       return;
00073     }
00074     if (!repFile.isDirectory())  {
00075       LogManager.traceError(0, "Error, repository path :"+repositoryPath+" is not a directory. Stop loading module");
00076       return;
00077     }
00078     
00079     HashMap jarMap = new HashMap(20);
00080     Array xmlList = new Array(20);
00081     File[] fileList = repFile.listFiles();
00082     //TODO to do add subdirectory reading and loading
00083     for (int i=0; i<fileList.length; i++)   {
00084       if (fileList[i].getName().endsWith(".jar"))   {
00085         jarMap.put(fileList[i].getName(), fileList);
00086       } else if(fileList[i].getName().endsWith(".xml"))   {
00087         xmlList.add(fileList[i]);
00088       }
00089     }
00090     
00091     //load xml files
00092     for (int i=0; i<xmlList.size(); i++)    {
00093         File toload = (File)xmlList.get(i);
00094         try   {
00095         ModuleJarSynchroTarget listener = new ModuleJarSynchroTarget(toload);
00096         //TODO add support for multiple terminal
00097         SynchroTargerManager.getManager().addSynchroTargetListener(listener, listener.getVersion(), null);
00098       } catch(Throwable ex) {
00099         LogManager.traceError(0, "An exception occurs during the loading of module xml file :"+toload.getName());
00100         LogManager.traceError(0, ex);
00101       }
00102     }
00103   }
00104 
00105 }

Generated on Mon Dec 4 11:03:28 2006 for OpenMobileIS by  doxygen 1.5.1-p1