00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 package org.openmobileis.bundle.coldupdate.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.module.terminal.ModuleManagerListener;
00040 import org.openmobileis.modules.profiles.terminal.RubricLoader;
00041 import org.openmobileis.services.common.ServiceManager;
00042 import org.openmobileis.synchro.client.SynchroDescriptor;
00043 import org.openmobileis.synchro.openmsp.OpenMSPException;
00044 import org.openmobileis.synchro.openmsp.client.EmptyOpenMSPSyncListener;
00045 import org.openmobileis.synchro.openmsp.client.OpenMSPSyncListener;
00046 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00047 import org.openmobileis.synchro.openmsp.client.core.NumSyncManagerDB;
00048 import org.openmobileis.synchro.security.auth.Credential;
00049
00054 public final class ColdUpdateModuleManagerListener extends EmptyOpenMSPSyncListener implements ModuleManagerListener {
00055 private static Array collectionToremoveList;
00056 private boolean restartAppli = false;
00057
00061 public ColdUpdateModuleManagerListener() {
00062 collectionToremoveList = new Array();
00063 }
00064
00065 public void initManager() throws ServiceException {
00066
00067
00068 File copyDir = new File(this.getJarInstallPath());
00069 File[] jarList = copyDir.listFiles();
00070 String baseDestDir = System.getProperty("user.dir")+"/WEB-INF/lib/";
00071 for (int i=0; i<jarList.length; i++) {
00072
00073
00074 jarList[i].getAbsoluteFile().renameTo(new File(baseDestDir+jarList[i].getName()));
00075 }
00076 OpenMSPSynchroManager.getManager().addListener(this, null);
00077 }
00078
00083 public String getSyncName() {
00084 return "FWK StaticModuleManagerListener";
00085 }
00086
00087
00088
00089
00090 public String getJarInstallPath() {
00091 return System.getProperty("user.dir")+"/WEB-INF/module/jar";
00092 }
00093
00094
00095
00096
00097 public String getXMLInstallPath() {
00098 return System.getProperty("user.dir")+"/WEB-INF/module/xml";
00099 }
00100
00101
00102
00103
00104 public void notifyModuleLoading(ProfileModule module) throws ServiceException {
00105 Array rubList = module.getModuleRubrics();
00106 for (int i=0; i<rubList.size(); i++) {
00107 ProfileModuleRubric rubric = (ProfileModuleRubric) rubList.get(i);
00108 String loaderClassName = rubric.getLoaderClass();
00109 if (loaderClassName != null) {
00110 try {
00111 RubricLoader loader = (RubricLoader) Class.forName(loaderClassName).newInstance();
00112 ServiceManager.getManager().loadRubricLoader(loader);
00113 } catch (Throwable ex) {
00114 LogManager.traceError(0, "StaticModuleManagerListener notifyModuleLoading : Exception during module "+module.getName()+" loading :"+ex.getMessage());
00115 throw new ServiceException(ex);
00116 }
00117 }
00118 }
00119
00120
00121 }
00122
00123
00124
00125
00126 public void notifyModuleUpdate(ProfileModule module) throws ServiceException {
00127 try {
00128 if (FastObjectDBManager.getManager().isFodbStarted()) {
00129 Array rubrics = module.getModuleRubrics();
00130 FODBCollection[] collist = FastObjectDBManager.getManager().getCurrentFODB().getDatabaseCollectionArray();
00131 int rubsize = rubrics.size();
00132 for (int i=0; i<rubsize; i++) {
00133 ProfileModuleRubric rubric = (ProfileModuleRubric)rubrics.get(i);
00134 for (int j=0; j<collist.length; j++) {
00135 if (rubric.getName().equals(collist[j].getName())) {
00136
00137 OpenMSPSyncListener listener = OpenMSPSynchroManager.getManager().getListenerByName(collist[j].getName());
00138 if (listener != null){
00139 if (!listener.isSyncOK()) {
00140 throw new ServiceException(module.getName()+" collection "+collist[j].getName()+" synchro error. Module can't be updated. Remove synchro module files");
00141 }
00142
00143 collectionToremoveList.add(collist[j].getName());
00144
00145 NumSyncManagerDB.getManager().saveSyncNumberForService(0, collist[j].getName());
00146 }
00147 }
00148 }
00149 }
00150 }
00151 } catch (Exception ex) {
00152 throw new ServiceException(ex);
00153 }
00154 this.restartAppli = true;
00155 }
00156
00157
00158
00159
00160 public void startSync(Credential cred, SynchroDescriptor synchrodescriptor) throws OpenMSPException {
00161 this.restartAppli = false;
00162 collectionToremoveList.clear();
00163 }
00164
00165
00166
00167
00168 public void endSync() throws OpenMSPException {
00169 if (this.restartAppli) {
00170 Thread thread = new Thread(new Runnable() {
00171 public void run() {
00172 try {
00173 Thread.currentThread().sleep(10000);
00174 } catch (Throwable ex) {
00175 LogManager.traceError(0, ex);
00176 }
00177 System.exit(0);
00178 };
00179 });
00180 thread.start();
00181
00182
00183
00184
00185 }
00186 }
00187
00188 }