Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

GenericProxySynchroTarget.java

00001 /*
00002  *        OpenMobileIS - a free Java Framework for mobile applications
00003  *
00004  *   Copyright (C) 2002  Philippe Delrieu.
00005  *
00006  *   This program is free software; you can redistribute it and/or
00007  *   modify it under the terms of the GNU General Public
00008  *   License as published by the Free Software Foundation; either
00009  *   version 2 of the License, or (at your option) any later version.
00010  *
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *   General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU Library General Public
00017  *   License along with this library; if not, write to the Free
00018  *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  * 
00020  * Philippe Delrieu kept the rigth to distribute all code Copyrighted by philippe Delrieu
00021  *  under other licence term even commercial one.
00022  *  
00023  *  Modifications :
00024  *  2002 Creation P.Delrieu
00025  * 
00026  */
00027 
00028 package org.openmobileis.synchro.openmsp.server.synctarget.proxy;
00029 
00030 import org.openmobileis.common.user.profil.Profil;
00031 import org.openmobileis.common.util.exception.SynchroException;
00032 import org.openmobileis.common.util.log.*;
00033 import org.openmobileis.synchro.openmsp.OpenMSPException;
00034 import org.openmobileis.synchro.openmsp.protocol.AbstractCommand;
00035 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00036 import org.openmobileis.synchro.openmsp.protocol.Message;
00037 import org.openmobileis.synchro.openmsp.protocol.Status;
00038 import org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener;
00039 import org.openmobileis.synchro.openmsp.server.synctarget.SyncTargetAnswer;
00040 import org.openmobileis.synchro.openmsp.server.synctarget.SynchroTargerManager;
00041 import org.openmobileis.synchro.openmsp.server.util.FileSystem;
00042 import org.openmobileis.synchro.security.auth.Credential;
00043 import org.openmobileis.common.context.*;
00044 
00053 public class GenericProxySynchroTarget implements ProxySyncroTarget {
00054   
00055   public GenericProxySynchroTarget() {
00056   }
00057   
00058   
00059   public void executeOpenMSPCommande(Credential cred, String listenerName, ContainerMessage container, Message answer, UserTerminal terminal, String version, Profil profil, FileSystem fileSystem) throws OpenMSPException  {
00060     // validate profil access
00061     if (!this.validateProfilAccess(listenerName, profil))  {
00062       Status status = new  Status (((AbstractCommand)(container.getElement())).getCmdId(), Status.STATUS_UNAUTHORIZED) ;
00063       answer.add(status);
00064       LogManager.traceInfo(0, "Error rubric not found in profil validation for synchro listener :"+listenerName);
00065       return;
00066     }
00067     OpenMSPSynchroTargetListener listener = SynchroTargerManager.getManager().getSynchroTargetListener(listenerName, version, terminal); //no version
00068     SyncTargetAnswer listenerAnswer = listener.processCommand(cred, container);   
00069     
00070     // process send files if any
00071     if (listenerAnswer.answerfiles != null)  {
00072         int size = listenerAnswer.answerfiles.length;
00073         for (int i=0; i<size; i++)  {
00074           try {
00075             fileSystem.addFile(listenerAnswer.answerfiles[i]);
00076           } catch (Exception ex) {
00077             LogManager.trace(new SynchroException("file not synchronized continue", ex));
00078             Status status = new  Status (((AbstractCommand)(container.getElement())).getCmdId(), Status.STATUS_FAILED) ;
00079             answer.add(status);
00080             return;
00081           }
00082         }
00083       }
00084       if (listenerAnswer.containerMessage != null)  {
00085         int size = listenerAnswer.containerMessage.length;
00086         for (int i=0; i<size; i++)  {
00087           answer.add(listenerAnswer.containerMessage[i]);
00088         }
00089      }
00090   }
00091 
00092   protected boolean validateProfilAccess(String listenerName, Profil profil) {
00093     int size = profil.profilRubric.length;
00094     for (int i=0; i<size; i++)  {
00095       if (listenerName.equals(profil.profilRubric[i].rubricName)) {
00096         return true;
00097       }
00098     }
00099     return false;
00100   }
00101 }

Generated on Wed Dec 14 21:05:33 2005 for OpenMobileIS by  doxygen 1.4.4