SampleFileSyncTarget.java

00001 package org.openmobileis.examples.mycrm.server.synchro;
00002 
00003 import java.io.BufferedInputStream;
00004 import java.io.File;
00005 import java.io.FileInputStream;
00006 
00007 import org.openmobileis.common.util.log.LogManager;
00008 import org.openmobileis.synchro.openmsp.OpenMSPException;
00009 import org.openmobileis.synchro.openmsp.protocol.Command;
00010 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00011 import org.openmobileis.synchro.openmsp.protocol.DataItem;
00012 import org.openmobileis.synchro.openmsp.protocol.Element;
00013 import org.openmobileis.synchro.openmsp.protocol.Result;
00014 import org.openmobileis.synchro.openmsp.protocol.Status;
00015 import org.openmobileis.synchro.openmsp.server.synctarget.DefaultOpenMSPSynchroTargetListener;
00016 import org.openmobileis.synchro.openmsp.server.util.MemoryFile;
00017 import org.openmobileis.synchro.security.auth.Credential;
00018 
00019 public class SampleFileSyncTarget extends DefaultOpenMSPSynchroTargetListener {
00020 
00021         protected void beginProcessOpenMSpCommand(Credential cred)
00022                         throws OpenMSPException {
00023         }
00024 
00025         protected ContainerMessage[] endProcessOpenMSpCommand()
00026                         throws OpenMSPException {
00027                 LogManager.traceInfo(0, "SampleFileSyncTarget endProcessSyncContainerMessage.");
00028             return null;
00029                 }
00030 
00031         public String getTargetName() {
00032                 return "samplefile";
00033         }
00034 
00035         protected void notifySyncAction(long sessionId, Credential cred,
00036                         Command syncCommand) throws OpenMSPException {
00037         }
00038 
00039         protected Status processAddCommand(Credential cred,
00040                         ContainerMessage addContainer) throws OpenMSPException {
00041                 return null;
00042         }
00043 
00044         protected Status processDeleteCommand(Credential cred,
00045                         ContainerMessage deleteContainer) throws OpenMSPException {
00046                 return null;
00047         }
00048 
00049         protected ContainerMessage[] processGetCommand(Credential cred,
00050                         ContainerMessage cm) throws OpenMSPException {
00051                 // construct return command
00052                 Command getCommand = (Command) cm.getElement();
00053                 long synchroFileModifTS = getCommand.getSourceSessionID();
00054                 long newSessionId = synchroFileModifTS;
00055                 Result resultCommand = new Result(getCommand.getCmdId(), getTargetName(), getTargetName());
00056                 ContainerMessage resultContainer = new ContainerMessage(resultCommand);
00057                 try {
00058                         // validate module file modification date.
00059                         File thefile = this.getSampleFile();
00060                         long filens = thefile.lastModified();
00061                         /*if (synchroFileModifTS < filens)*/
00062                         if (true) { // manage file modification.
00063                                 newSessionId = filens;
00064                                 this.addFileToSynchro(new MemoryFile("/filedir/"
00065                                                 + thefile.getName(), new BufferedInputStream(
00066                                                 new FileInputStream(thefile))));
00067                                 DataItem newItem = new DataItem(Element.ITEM,
00068                                                 "svs", thefile.getName(), null, null);
00069                                 resultContainer.add(newItem);
00070                         } else {
00071                                 DataItem newItem = new DataItem(Element.ITEM, "nofile",
00072                                                 "nofile", null, null);
00073                                 resultContainer.add(newItem);
00074                         }
00075                         resultCommand.setMetaInformation(Long.toString(newSessionId));
00076                 } catch (Exception ex) {
00077                         Status status = new Status(getCommand.getCmdId(),
00078                                         Status.STATUS_FAILED);
00079                         status.setCmdRef(getCommand.getCmdId());
00080                         ContainerMessage statusContainer = new ContainerMessage(status);
00081                         ContainerMessage[] ret = new ContainerMessage[1];
00082                         ret[0] = statusContainer;
00083                         return ret;
00084                 }
00085                  
00086                     
00087                 ContainerMessage[] ret = new ContainerMessage[1];
00088                 ret[0] = resultContainer;
00089                 return ret;
00090         }
00091 
00092         protected ContainerMessage processMapCommand(Credential cred,
00093                         ContainerMessage mapContainer) throws OpenMSPException {
00094                 return null;
00095         }
00096 
00097         protected Status processReplaceCommand(Credential cred,
00098                         ContainerMessage replaceContainer) throws OpenMSPException {
00099                 return null;
00100         }
00101 
00102         protected void processResultCommand(Credential cred, Result resultCommande)
00103                         throws OpenMSPException {
00104         }
00105 
00106         protected void processStatusCommand(Credential cred, Status statusCommande)
00107                         throws OpenMSPException {
00108         }
00109 
00110         private File getSampleFile() {
00111                 String path = System.getProperty("user.dir") + File.separator +"samplefiles" + File.separator
00112                                 + "testfile.test";
00113                 return new File(path);
00114         }
00115 
00116 }

Generated on Mon Jan 11 21:19:16 2010 for OpenMobileIS by  doxygen 1.5.4