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.File;
00028 import java.io.FileNotFoundException;
00029 import java.io.IOException;
00030
00031 import org.openmobileis.common.util.log.LogManager;
00032 import org.openmobileis.module.core.ProfileModule;
00033 import org.openmobileis.synchro.openmsp.OpenMSPException;
00034 import org.openmobileis.synchro.openmsp.protocol.Command;
00035 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00036 import org.openmobileis.synchro.openmsp.protocol.DataItem;
00037 import org.openmobileis.synchro.openmsp.protocol.Element;
00038 import org.openmobileis.synchro.openmsp.protocol.Result;
00039 import org.openmobileis.synchro.openmsp.protocol.Status;
00040 import org.openmobileis.synchro.openmsp.server.synctarget.DefaultOpenMSPSynchroTargetListener;
00041 import org.openmobileis.synchro.openmsp.server.util.MemoryFile;
00042 import org.openmobileis.synchro.security.auth.Credential;
00043 import org.xmlpull.v1.XmlPullParserException;
00044
00052 public final class ModuleJarSynchroTarget extends DefaultOpenMSPSynchroTargetListener {
00053
00054 protected ProfileModule listenerModule;
00055
00056 protected byte[] terminaljar;
00057 protected long moduleJarLastModified;
00058
00059 public ModuleJarSynchroTarget(ProfileModule module) throws FileNotFoundException, XmlPullParserException, IOException {
00060 this.listenerModule = module;
00061 }
00062
00063 public ProfileModule getProfilModule() {
00064 return listenerModule;
00065 }
00066
00067 public void setTerminalJar(byte[] jar, long lastModified) {
00068 this.terminaljar = jar;
00069 this.moduleJarLastModified = lastModified;
00070 }
00071
00072
00073
00074
00075 public String getTargetName() {
00076 return listenerModule.getName();
00077 }
00078
00079 public String getVersion() {
00080 return listenerModule.getVersion();
00081 }
00082
00083
00084
00085
00086 protected ContainerMessage processMapCommand(Credential cred, ContainerMessage mapContainer) {
00087 return null;
00088 }
00089
00090
00091
00092
00093 protected void notifySyncAction(long sessionId, Credential cred, Command syncCommand) throws OpenMSPException {
00094
00095
00096
00097
00098 }
00099
00100
00101
00102
00103 protected void processResultCommand(Credential cred, Result resultCommande) throws OpenMSPException {
00104 }
00105
00106
00107
00108
00109 protected void processStatusCommand(Credential cred, Status statusCommande) throws OpenMSPException {
00110 }
00111
00112
00113
00114
00115 protected Status processAddCommand(Credential cred, ContainerMessage addContainer) throws OpenMSPException {
00116 return null;
00117 }
00118
00119
00120
00121
00122 protected Status processDeleteCommand(Credential cred, ContainerMessage deleteContainer) throws OpenMSPException {
00123 return null;
00124 }
00125
00126
00127
00128
00129 protected Status processReplaceCommand(Credential cred, ContainerMessage replaceContainer) throws OpenMSPException {
00130 return null;
00131 }
00132
00133
00134
00135
00136 protected void beginProcessOpenMSpCommand(Credential cred) throws OpenMSPException {
00137 }
00138
00139
00140
00141
00142 protected ContainerMessage[] endProcessOpenMSpCommand() throws OpenMSPException {
00143 return null;
00144 }
00145
00146
00147
00148
00149 protected ContainerMessage[] processGetCommand(Credential cred, ContainerMessage getContainer) throws OpenMSPException {
00150
00151 Command getCommand = (Command)getContainer.getElement();
00152 long synchroFileModifTS = getCommand.getSourceSessionID();
00153 long newSessionId = synchroFileModifTS;
00154 Result resultCommand = new Result(getCommand.getCmdId(), this.getTargetName(), this.getTargetName());
00155 ContainerMessage resultContainer = new ContainerMessage(resultCommand);
00156 try {
00157 if (synchroFileModifTS < this.moduleJarLastModified) {
00158 newSessionId = this.moduleJarLastModified;
00159 this.addFileToSynchro(new MemoryFile("/filedir/"+listenerModule.getName()+".jar", this.terminaljar));
00160 DataItem newItem = new DataItem(Element.ITEM, "jarfile", listenerModule.getName()+".jar", null, null);
00161 resultContainer.add(newItem);
00162 this.addFileToSynchro(new MemoryFile("/filedir/"+listenerModule.getName()+".xml", listenerModule.toXML().getBytes()));
00163 newItem = new DataItem(Element.ITEM, "xmlfile",listenerModule.getName()+".xml", null, null);
00164 resultContainer.add(newItem);
00165 } else {
00166 DataItem newItem = new DataItem(Element.ITEM, "nofile", "nofile", null, null);
00167 resultContainer.add(newItem);
00168 }
00169 resultCommand.setMetaInformation(Long.toString(newSessionId));
00170 } catch (Exception ex) {
00171 LogManager.traceError(0, ex);
00172 Status status = new Status(getCommand.getCmdId(), Status.STATUS_FAILED);
00173 status.setCmdRef(getCommand.getCmdId());
00174 ContainerMessage statusContainer = new ContainerMessage(status);
00175 ContainerMessage[] ret = new ContainerMessage[1];
00176 ret[0] = statusContainer;
00177 return ret;
00178 }
00179 ContainerMessage[] ret = new ContainerMessage[1];
00180 ret[0] = resultContainer;
00181 return ret;
00182 }
00183
00184 }