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 package org.openmobileis.synchro.openmsp.server.synctarget.proxy;
00027
00028 import org.openmobileis.common.user.profile.Profile;
00029 import org.openmobileis.common.util.exception.SynchroException;
00030 import org.openmobileis.common.util.log.*;
00031 import org.openmobileis.synchro.openmsp.OpenMSPException;
00032 import org.openmobileis.synchro.openmsp.protocol.AbstractCommand;
00033 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00034 import org.openmobileis.synchro.openmsp.protocol.Message;
00035 import org.openmobileis.synchro.openmsp.protocol.Status;
00036 import org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener;
00037 import org.openmobileis.synchro.openmsp.server.synctarget.SyncTargetAnswer;
00038 import org.openmobileis.synchro.openmsp.server.synctarget.SynchroTargerManager;
00039 import org.openmobileis.synchro.openmsp.server.util.FileSystem;
00040 import org.openmobileis.synchro.security.auth.Credential;
00041 import org.openmobileis.common.context.*;
00042
00051 public class GenericProxySynchroTarget implements ProxySyncroTarget {
00052
00053 public GenericProxySynchroTarget() {
00054 }
00055
00056
00057 public void executeOpenMSPCommande(Credential cred, String listenerName, ContainerMessage container, Message answer, UserTerminal terminal, String version, Profile profil, FileSystem fileSystem) throws OpenMSPException {
00058
00059 if (!this.validateProfilAccess(listenerName, profil)) {
00060 Status status = new Status (((AbstractCommand)(container.getElement())).getCmdId(), Status.STATUS_UNAUTHORIZED) ;
00061 answer.add(status);
00062 LogManager.traceInfo(0, "Error rubric not found in profil validation for synchro listener :"+listenerName);
00063 return;
00064 }
00065 OpenMSPSynchroTargetListener listener = SynchroTargerManager.getManager().getSynchroTargetListener(listenerName, version, terminal);
00066 if (listener != null) {
00067 SyncTargetAnswer listenerAnswer = listener.processCommand(cred, container);
00068
00069
00070 if (listenerAnswer.answerfiles != null) {
00071 int size = listenerAnswer.answerfiles.length;
00072 for (int i=0; i<size; i++) {
00073 try {
00074 fileSystem.addFile(listenerAnswer.answerfiles[i]);
00075 } catch (Exception ex) {
00076 LogManager.trace(new SynchroException("file not synchronized continue", ex));
00077 Status status = new Status (((AbstractCommand)(container.getElement())).getCmdId(), Status.STATUS_FAILED) ;
00078 answer.add(status);
00079 return;
00080 }
00081 }
00082 }
00083 if (listenerAnswer.containerMessage != null) {
00084 int size = listenerAnswer.containerMessage.length;
00085 for (int i=0; i<size; i++) {
00086 answer.add(listenerAnswer.containerMessage[i]);
00087 }
00088 }
00089 } else {
00090 throw new OpenMSPException("No synchro target defined for OpenMSP synchro target :"+listenerName);
00091 }
00092 }
00093
00094 protected boolean validateProfilAccess(String listenerName, Profile profil) {
00095 int size = profil.profilRubric.length;
00096 for (int i=0; i<size; i++) {
00097 if (listenerName.equals(profil.profilRubric[i].rubricName)) {
00098 return true;
00099 }
00100 }
00101 return false;
00102 }
00103 }