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.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
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
00087
00088
00089 public String getJarInstallPath() {
00090 return System.getProperty("user.dir")+"/WEB-INF/module/jar";
00091 }
00092
00093
00094
00095
00096 public String getXMLInstallPath() {
00097 return System.getProperty("user.dir")+"/WEB-INF/module/xml";
00098 }
00099
00100
00101
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
00123
00124
00125 public void notifyModuleUpdate(ProfileModule module) throws ServiceException {
00126 try {
00127 if (FastObjectDBManager.isFodbStarted()) {
00128 Array rubrics = module.getModuleRubrics();
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
00136 OpenMSPSyncListener listener = OpenMSPSynchroManager.getManager().getListenerByName(collist[j].getName());
00137 if (listener != null){
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
00142 collectionToremoveList.add(collist[j].getName());
00143
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
00157
00158
00159 public void startSync(Credential cred, SynchroDescriptor synchrodescriptor) throws OpenMSPException {
00160 this.restartAppli = false;
00161 collectionToremoveList.clear();
00162 }
00163
00164
00165
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);
00173 } catch (Throwable ex) {
00174 LogManager.traceError(0, ex);
00175 }
00176 System.exit(0);
00177 };
00178 });
00179 thread.start();
00180
00181
00182
00183
00184 }
00185 }
00186
00187 }