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.bundle.update.server;
00026
00027 import java.io.File;
00028 import java.io.FileNotFoundException;
00029 import java.io.IOException;
00030 import java.util.Iterator;
00031 import java.util.jar.Attributes;
00032 import java.util.jar.JarFile;
00033
00034 import org.openmobileis.bundle.update.terminal.ApplicationUpdateJarUtil;
00035 import org.openmobileis.common.util.log.LogManager;
00036 import org.openmobileis.synchro.openmsp.OpenMSPException;
00037 import org.openmobileis.synchro.openmsp.protocol.Command;
00038 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00039 import org.openmobileis.synchro.openmsp.protocol.DataItem;
00040 import org.openmobileis.synchro.openmsp.protocol.Element;
00041 import org.openmobileis.synchro.openmsp.protocol.Result;
00042 import org.openmobileis.synchro.openmsp.protocol.Status;
00043 import org.openmobileis.synchro.openmsp.server.synctarget.DefaultOpenMSPSynchroTargetListener;
00044 import org.openmobileis.synchro.openmsp.server.util.MemoryFile;
00045 import org.openmobileis.synchro.security.auth.Credential;
00046 import org.xmlpull.v1.XmlPullParserException;
00047
00055 public final class FullAppUpdateSynchroTarget extends DefaultOpenMSPSynchroTargetListener {
00056
00057 protected File currentjarFile;
00058
00059 protected byte[] terminaljar;
00060
00061 public FullAppUpdateSynchroTarget(File jarfile) throws FileNotFoundException, XmlPullParserException, IOException {
00062 this.currentjarFile = jarfile;
00063 }
00064
00065
00066
00067
00068 public String getTargetName() {
00069 return ApplicationUpdateJarUtil.FULL_APP_UPDATE_NAME;
00070 }
00071
00072
00073
00074
00075 protected ContainerMessage processMapCommand(Credential cred, ContainerMessage mapContainer) {
00076 return null;
00077 }
00078
00079
00080
00081
00082 protected void notifySyncAction(long sessionId, Credential cred, Command syncCommand) throws OpenMSPException {
00083 }
00084
00085
00086
00087
00088 protected void processResultCommand(Credential cred, Result resultCommande) throws OpenMSPException {
00089 }
00090
00091
00092
00093
00094 protected void processStatusCommand(Credential cred, Status statusCommande) throws OpenMSPException {
00095 }
00096
00097
00098
00099
00100 protected Status processAddCommand(Credential cred, ContainerMessage addContainer) throws OpenMSPException {
00101 return null;
00102 }
00103
00104
00105
00106
00107 protected Status processDeleteCommand(Credential cred, ContainerMessage deleteContainer) throws OpenMSPException {
00108 return null;
00109 }
00110
00111
00112
00113
00114 protected Status processReplaceCommand(Credential cred, ContainerMessage replaceContainer) throws OpenMSPException {
00115 return null;
00116 }
00117
00118
00119
00120
00121 protected void beginProcessOpenMSpCommand(Credential cred) throws OpenMSPException {
00122 }
00123
00124
00125
00126
00127 protected ContainerMessage[] endProcessOpenMSpCommand() throws OpenMSPException {
00128 return null;
00129 }
00130
00131
00132
00133
00134 protected ContainerMessage[] processGetCommand(Credential cred, ContainerMessage getContainer) throws OpenMSPException {
00135
00136 Command getCommand = (Command)getContainer.getElement();
00137 DataItem item = (DataItem) getContainer.nextMessage().getElement();
00138 try {
00139 String pdaversion = item.getData();
00140 if (pdaversion == null) pdaversion="";
00141 String serverversion = this.readJarVersion(this.currentjarFile);
00142 Result resultCommand = new Result(getCommand.getCmdId(), this.getTargetName(), this.getTargetName());
00143 ContainerMessage resultContainer = new ContainerMessage(resultCommand);
00144 LogManager.traceDebug(0, "FullAppUpdateSynchroTarget processGetCommand pdaversion :"+pdaversion);
00145 LogManager.traceDebug(0, "FullAppUpdateSynchroTarget processGetCommand serverversion :"+serverversion);
00146 if (!pdaversion.equals(serverversion)) {
00147 LogManager.traceDebug(0, "FullAppUpdateSynchroTarget processGetCommand UPDATE PDA");
00148 MemoryFile mf = new MemoryFile(this.currentjarFile);
00149 mf.setFileName(ApplicationUpdateJarUtil.APPLICATION_JAR_FILENAME);
00150 this.addFileToSynchro(mf);
00151 DataItem newItem = new DataItem(Element.ITEM, "jarfile", ApplicationUpdateJarUtil.APPLICATION_JAR_FILENAME, null, null);
00152 resultContainer.add(newItem);
00153 } else {
00154 DataItem newItem = new DataItem(Element.ITEM, "nofile", "nofile", null, null);
00155 resultContainer.add(newItem);
00156 }
00157 ContainerMessage[] ret = new ContainerMessage[1];
00158 ret[0] = resultContainer;
00159 return ret;
00160 } catch (Exception ex) {
00161 LogManager.traceError(0, ex);
00162 Status status = new Status(getCommand.getCmdId(), Status.STATUS_FAILED);
00163 status.setCmdRef(getCommand.getCmdId());
00164 ContainerMessage statusContainer = new ContainerMessage(status);
00165 ContainerMessage[] ret = new ContainerMessage[1];
00166 ret[0] = statusContainer;
00167 return ret;
00168 }
00169 }
00170
00171 private String readJarVersion(File file) throws IOException{
00172 String version = "";
00173 if (file.exists()) {
00174 JarFile jarFile = new JarFile(file);
00175 try {
00176 if (jarFile.getManifest() != null) {
00177 Iterator iter = jarFile.getManifest().getMainAttributes().keySet().iterator();
00178 while (iter.hasNext()) {
00179 Attributes.Name attribute = (Attributes.Name) iter.next();
00180 if (attribute.equals(ApplicationUpdateJarUtil.VERSIONNAME)) {
00181 version = jarFile.getManifest().getMainAttributes().getValue(attribute);
00182 }
00183 }
00184 }
00185 } finally {
00186 if (jarFile != null) {
00187 try {
00188 jarFile.close();
00189 } catch (IOException ioe) {
00190 }
00191 }
00192 }
00193 }
00194 return version;
00195 }
00196
00197 }