StaticModuleManagerListener.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
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  *  Creation P.Delrieu
00026  * 
00027  */
00028 package org.openmobileis.module.terminal;
00029 
00030 import java.io.File;
00031 
00032 import org.openmobileis.common.util.collection.Array;
00033 import org.openmobileis.common.util.exception.ServiceException;
00034 import org.openmobileis.common.util.log.LogManager;
00035 import org.openmobileis.database.fastobjectdb.FastObjectDBManager;
00036 import org.openmobileis.database.fastobjectdb.db.FODBCollection;
00037 import org.openmobileis.module.core.ProfileModule;
00038 import org.openmobileis.module.core.ProfileModuleRubric;
00039 import org.openmobileis.modules.profiles.terminal.RubricLoader;
00040 import org.openmobileis.services.common.ServiceManager;
00041 import org.openmobileis.synchro.client.SynchroDescriptor;
00042 import org.openmobileis.synchro.openmsp.OpenMSPException;
00043 import org.openmobileis.synchro.openmsp.client.EmptyOpenMSPSyncListener;
00044 import org.openmobileis.synchro.openmsp.client.OpenMSPSyncListener;
00045 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00046 import org.openmobileis.synchro.openmsp.client.core.NumSyncManagerDB;
00047 import org.openmobileis.synchro.security.auth.Credential;
00048 
00053 public final class StaticModuleManagerListener extends EmptyOpenMSPSyncListener implements ModuleManagerListener {
00054         private static Array collectionToremoveList;
00055         private boolean restartAppli = false;
00056 
00060         public StaticModuleManagerListener() {
00061                 collectionToremoveList = new Array();
00062         }
00063         
00064   public void initManager() throws ServiceException     {
00065         
00066         //copy all synchronized jar to the lib dir.
00067         File copyDir = new File(this.getJarInstallPath());
00068         File[] jarList = copyDir.listFiles();
00069         String baseDestDir = System.getProperty("user.dir")+"/WEB-INF/lib/";
00070         for (int i=0; i<jarList.length; i++)    {
00071                 File temp1 = jarList[i].getAbsoluteFile();
00072                 String temp2 = baseDestDir+jarList[i].getName();
00073                 jarList[i].getAbsoluteFile().renameTo(new File(baseDestDir+jarList[i].getName()));
00074         }
00075                 OpenMSPSynchroManager.getManager().addListener(this, null);
00076   }
00077 
00082          public String getSyncName()    {
00083                  return "FWK StaticModuleManagerListener";
00084          }
00085 
00086         /* (non-Javadoc)
00087          * @see org.openmobileis.module.terminal.ModuleManagerListener#getJarInstallPath()
00088          */
00089         public String getJarInstallPath() {
00090                 return System.getProperty("user.dir")+"/WEB-INF/module/jar";
00091         }
00092 
00093         /* (non-Javadoc)
00094          * @see org.openmobileis.module.terminal.ModuleManagerListener#getXMLInstallPath()
00095          */
00096         public String getXMLInstallPath() {
00097                 return System.getProperty("user.dir")+"/WEB-INF/module/xml";
00098         }
00099 
00100         /* (non-Javadoc)
00101          * @see org.openmobileis.module.terminal.ModuleManagerListener#notifyModuleLoading(org.openmobileis.module.core.ProfileModule)
00102          */
00103         public void notifyModuleLoading(ProfileModule module) throws ServiceException {
00104                 Array rubList = module.getModuleRubrics();
00105                 for (int i=0; i<rubList.size(); i++)    {
00106                         ProfileModuleRubric rubric = (ProfileModuleRubric) rubList.get(i);
00107                         String loaderClassName = rubric.getLoaderClass();
00108                         if (loaderClassName != null)    {
00109                                 try     {
00110                                         RubricLoader loader = (RubricLoader) Class.forName(loaderClassName).newInstance();
00111                                         ServiceManager.getManager().loadRubricLoader(loader);
00112                                 } catch (Throwable ex)  {
00113                                         LogManager.traceError(0, "StaticModuleManagerListener notifyModuleLoading : Exception during module "+module.getName()+" loading :"+ex.getMessage());
00114                                         throw new ServiceException(ex);
00115                                 }
00116                         }
00117                 }
00118                 
00119 
00120         }
00121 
00122         /* (non-Javadoc)
00123          * @see org.openmobileis.module.terminal.ModuleManagerListener#notifyModuleLoading(org.openmobileis.module.core.ProfileModule)
00124          */
00125         public void notifyModuleUpdate(ProfileModule module) throws ServiceException {
00126                 try     {
00127                         if (FastObjectDBManager.isFodbStarted())        {
00128                                 Array rubrics = module.getModuleRubrics(); //all database collection is a rubric in the profil.
00129                                 FODBCollection[] collist = FastObjectDBManager.getCurrentFODB().getDatabaseCollectionArray();
00130                                 int rubsize = rubrics.size();
00131                                 for (int i=0; i<rubsize; i++)   {
00132                                         ProfileModuleRubric rubric = (ProfileModuleRubric)rubrics.get(i);
00133                                         for (int j=0; j<collist.length; j++)    {
00134                                                 if (rubric.getName().equals(collist[j].getName()))      {
00135                                                         //validate collection synchro OK.
00136                                                         OpenMSPSyncListener listener = OpenMSPSynchroManager.getManager().getListenerByName(collist[j].getName());
00137                                                         if (listener != null){ //synchronized collection
00138                                                                 if (!listener.isSyncOK())       {                                                       
00139                                                                         throw new ServiceException(module.getName()+" collection "+collist[j].getName()+" synchro error. Module can't be updated. Remove synchro module files");
00140                                                                 }
00141                                                                 // add collecion to the remove list.
00142                                                                 collectionToremoveList.add(collist[j].getName());
00143                                                                 //force complete synchro for the listener.
00144                                         NumSyncManagerDB.getManager().saveSyncNumberForService(0, collist[j].getName());
00145                                                         }
00146                                                 }
00147                                         }
00148                                 }
00149                         }
00150                 } catch (Exception ex)  {
00151                         throw new ServiceException(ex);
00152                 }
00153                 this.restartAppli = true;
00154         }
00155 
00156         /* (non-Javadoc)
00157          * @see org.openmobileis.synchro.openmsp.client.OpenMSPSyncListener#startSync(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.client.SynchroDescriptor)
00158          */
00159         public void startSync(Credential cred, SynchroDescriptor synchrodescriptor) throws OpenMSPException {
00160                 this.restartAppli = false;
00161                 collectionToremoveList.clear();
00162         }
00163 
00164         /* (non-Javadoc)
00165          * @see org.openmobileis.synchro.openmsp.client.OpenMSPSyncListener#endSync()
00166          */
00167         public void endSync() throws OpenMSPException {
00168                 if (this.restartAppli)  {
00169                         Thread thread = new Thread(new Runnable()       {
00170                                 public void run() {
00171                                         try     {
00172                                                 Thread.currentThread().sleep(10000); //way 10 second the synchronisation finised.
00173                                         } catch (Throwable ex)  {
00174                                                 LogManager.traceError(0, ex);
00175                                         }
00176                                         System.exit(0);
00177                                 };
00178                         });
00179                         thread.start();
00180 //                      remove fodb collection before stop.
00181 //                      restart appli. show return page and after stop
00182 //                      ajout du message l'application va être redémarrer dans quelques instant veuillez patienter.
00183 //                      Ajouter au redémarrage l'ajout du message, pour terminer la mise à jour vous devez réaliser une nouvelle synchronisation.
00184                 }
00185         }
00186 
00187 }

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