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 package org.openmobileis.module.server;
00026
00027 import java.io.BufferedInputStream;
00028 import java.io.File;
00029 import java.io.FileInputStream;
00030 import java.io.FileNotFoundException;
00031 import java.io.IOException;
00032 import java.io.InputStreamReader;
00033 import java.io.Reader;
00034
00035 import org.openmobileis.common.util.PropertiesManager;
00036 import org.openmobileis.module.core.ProfileModule;
00037 import org.openmobileis.module.core.XmlModuleParser;
00038 import org.openmobileis.synchro.openmsp.OpenMSPException;
00039 import org.openmobileis.synchro.openmsp.protocol.Command;
00040 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00041 import org.openmobileis.synchro.openmsp.protocol.DataItem;
00042 import org.openmobileis.synchro.openmsp.protocol.Element;
00043 import org.openmobileis.synchro.openmsp.protocol.Result;
00044 import org.openmobileis.synchro.openmsp.protocol.Status;
00045 import org.openmobileis.synchro.openmsp.server.synctarget.DefaultOpenMSPSynchroTargetListener;
00046 import org.openmobileis.synchro.openmsp.server.util.MemoryFile;
00047 import org.openmobileis.synchro.security.auth.Credential;
00048 import org.xmlpull.v1.XmlPullParserException;
00049
00057 public final class ModuleJarSynchroTarget extends DefaultOpenMSPSynchroTargetListener {
00058
00059 protected ProfileModule listenerModule;
00060 protected File xmlFile;
00061
00065 public ModuleJarSynchroTarget(File xmlFile) throws FileNotFoundException, XmlPullParserException, IOException {
00066 super();
00067 this.xmlFile = xmlFile;
00068 Reader reader = new InputStreamReader(new FileInputStream(xmlFile));
00069 try {
00070 XmlModuleParser parser = new XmlModuleParser(reader);
00071 parser.parse();
00072 listenerModule = parser.getModuletoload();
00073 } finally {
00074 reader.close();
00075 }
00076
00077 }
00078
00079 public ProfileModule getProfilModule() {
00080 return listenerModule;
00081 }
00082
00083
00084
00085
00086 public String getTargetName() {
00087 return listenerModule.getName();
00088 }
00089
00090 public String getVersion() {
00091 return listenerModule.getVersion();
00092 }
00093
00094
00095
00096
00097 protected ContainerMessage processMapCommand(Credential cred, ContainerMessage mapContainer) {
00098 return null;
00099 }
00100
00101
00102
00103
00104 protected void notifySyncAction(long sessionId, Credential cred, Command syncCommand) throws OpenMSPException {
00105
00106
00107
00108
00109 }
00110
00111
00112
00113
00114 protected void processResultCommand(Credential cred, Result resultCommande) throws OpenMSPException {
00115 }
00116
00117
00118
00119
00120 protected void processStatusCommand(Credential cred, Status statusCommande) throws OpenMSPException {
00121 }
00122
00123
00124
00125
00126 protected Status processAddCommand(Credential cred, ContainerMessage addContainer) throws OpenMSPException {
00127 return null;
00128 }
00129
00130
00131
00132
00133 protected Status processDeleteCommand(Credential cred, ContainerMessage deleteContainer) throws OpenMSPException {
00134 return null;
00135 }
00136
00137
00138
00139
00140 protected Status processReplaceCommand(Credential cred, ContainerMessage replaceContainer) throws OpenMSPException {
00141 return null;
00142 }
00143
00144
00145
00146
00147 protected void beginProcessOpenMSpCommand(Credential cred) throws OpenMSPException {
00148 }
00149
00150
00151
00152
00153 protected ContainerMessage[] endProcessOpenMSpCommand() throws OpenMSPException {
00154 return null;
00155 }
00156
00157 private File getModuleTerminalJarFile() {
00158 StringBuffer modrep = new StringBuffer(PropertiesManager.getManager().getProperty("org.openmobileis.bundle.module.repositorypath"));
00159 modrep.append('/');
00160 modrep.append(this.listenerModule.getTerminaljar());
00161 return new File(modrep.toString());
00162 }
00163
00164
00165
00166
00167 protected ContainerMessage[] processGetCommand(Credential cred, ContainerMessage getContainer) throws OpenMSPException {
00168
00169 Command getCommand = (Command)getContainer.getElement();
00170 long synchroFileModifTS = getCommand.getSourceSessionID();
00171 long newSessionId = synchroFileModifTS;
00172 Result resultCommand = new Result(getCommand.getCmdId(), this.getTargetName(), this.getTargetName());
00173 ContainerMessage resultContainer = new ContainerMessage(resultCommand);
00174 try {
00175
00176
00177 File terminaljarfile = this.getModuleTerminalJarFile();
00178 long filens = terminaljarfile.lastModified();
00179 if (xmlFile.lastModified() > filens) filens = xmlFile.lastModified();
00180 if (synchroFileModifTS < filens) {
00181 newSessionId = filens;
00182 this.addFileToSynchro(new MemoryFile("/filedir/"+terminaljarfile.getName(), new BufferedInputStream(new FileInputStream(terminaljarfile))));
00183 DataItem newItem = new DataItem(Element.ITEM, "jarfile", terminaljarfile.getName(), null, null);
00184 resultContainer.add(newItem);
00185 this.addFileToSynchro(new MemoryFile("/filedir/"+xmlFile.getName(), new BufferedInputStream(new FileInputStream(xmlFile))));
00186 newItem = new DataItem(Element.ITEM, "xmlfile", xmlFile.getName(), null, null);
00187 resultContainer.add(newItem);
00188 } else {
00189 DataItem newItem = new DataItem(Element.ITEM, "nofile", "nofile", null, null);
00190 resultContainer.add(newItem);
00191 }
00192 resultCommand.setMetaInformation(Long.toString(newSessionId));
00193 } catch (Exception ex) {
00194 Status status = new Status(getCommand.getCmdId(), Status.STATUS_FAILED);
00195 status.setCmdRef(getCommand.getCmdId());
00196 ContainerMessage statusContainer = new ContainerMessage(status);
00197 ContainerMessage[] ret = new ContainerMessage[1];
00198 ret[0] = statusContainer;
00199 return ret;
00200 }
00201 ContainerMessage[] ret = new ContainerMessage[1];
00202 ret[0] = resultContainer;
00203 return ret;
00204 }
00205
00206 }