GenericProxySynchroTarget.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
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     // validate profil access
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); //no version
00066     if (listener != null) {
00067       SyncTargetAnswer listenerAnswer = listener.processCommand(cred, container);   
00068       
00069       // process send files if any
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 }

Generated on Mon Dec 4 11:03:27 2006 for OpenMobileIS by  doxygen 1.5.1-p1