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, Profile profil, FileSystem fileSystem) throws OpenMSPException  {
00058     // validate profil access
00059         String[] versions = this.validateProfilAccessAndVersion(listenerName, profil);
00060     if (versions == null)  {
00061       Status status = new  Status (((AbstractCommand)(container.getElement())).getCmdId(), Status.STATUS_UNAUTHORIZED) ;
00062       answer.add(status);
00063       LogManager.traceInfo(0, "Error rubric not found in profil validation for synchro listener :"+listenerName);
00064       return;
00065     }
00066     
00067     LogManager.traceDebug(0, "GenericSynchroProxyTarget executeOpenMSPCommande target version :"+versions[0]);
00068     
00069     OpenMSPSynchroTargetListener listener = SynchroTargerManager.getManager().getSynchroTargetListener(listenerName, versions[0], terminal); //no version
00070     if (listener != null) {
00071       SyncTargetAnswer listenerAnswer = listener.processCommand(cred, container);   
00072       
00073       // process send files if any
00074       if (listenerAnswer.answerfiles != null)  {
00075           int size = listenerAnswer.answerfiles.length;
00076           for (int i=0; i<size; i++)  {
00077             try {
00078               fileSystem.addFile(listenerAnswer.answerfiles[i]);
00079             } catch (Exception ex) {
00080               LogManager.trace(new SynchroException("file not synchronized continue", ex));
00081               Status status = new  Status (((AbstractCommand)(container.getElement())).getCmdId(), Status.STATUS_FAILED) ;
00082               answer.add(status);
00083               return;
00084             }
00085           }
00086         }
00087         if (listenerAnswer.containerMessage != null)  {
00088           int size = listenerAnswer.containerMessage.length;
00089           for (int i=0; i<size; i++)  {
00090             answer.add(listenerAnswer.containerMessage[i]);
00091           }
00092        }
00093     } else {
00094       throw new OpenMSPException("No synchro target defined for OpenMSP synchro target :"+listenerName);
00095     }
00096   }
00097 
00098   private String[] validateProfilAccessAndVersion(String listenerName, Profile profil) {
00099     int size = profil.ProfileServices.length;
00100     for (int i=0; i<size; i++)  {
00101       if (listenerName.equals(profil.ProfileServices[i].serviceName)) {
00102         String version = profil.ProfileServices[i].version;
00103         return new String[]{version};
00104      }
00105     }
00106     return null;
00107   }
00108 }

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