ProfilManagerSyncTarget.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.module.profiles.server;
00029 
00030 import org.openmobileis.common.user.User;
00031 import org.openmobileis.common.user.UserManager;
00032 import org.openmobileis.common.user.profile.Profile;
00033 import org.openmobileis.common.user.profile.ProfileDataManager;
00034 import org.openmobileis.common.util.codec.GeneralCoder;
00035 import org.openmobileis.common.context.*;
00036 import org.openmobileis.module.profiles.terminal.OpenMSPProfileSyncListener;
00037 import org.openmobileis.synchro.openmsp.OpenMSPException;
00038 import org.openmobileis.synchro.openmsp.protocol.Command;
00039 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00040 import org.openmobileis.synchro.openmsp.protocol.DataItem;
00041 import org.openmobileis.synchro.openmsp.protocol.Element;
00042 import org.openmobileis.synchro.openmsp.protocol.Result;
00043 import org.openmobileis.synchro.openmsp.protocol.Status;
00044 import org.openmobileis.synchro.openmsp.server.synctarget.DefaultOpenMSPSynchroTargetListener;
00045 import org.openmobileis.synchro.security.auth.Credential;
00046 
00047 
00048 
00058 public class ProfilManagerSyncTarget extends DefaultOpenMSPSynchroTargetListener {
00059 
00060   public ProfilManagerSyncTarget() {
00061   }
00062 
00063   public String getTargetName() {
00064     return OpenMSPProfileSyncListener.profilSynchroTargetName;
00065    }
00066 
00067   protected ContainerMessage processMapCommand(Credential cred,ContainerMessage mapContainer)   throws OpenMSPException {
00068     throw new OpenMSPException("MAP command not implemented.");
00069   }
00070   
00071   protected void notifySyncAction(long sessionId,Credential cred, Command syncCommand)  throws OpenMSPException {
00072     //do nothing. Sync action is managed in the GET command.
00073   }
00074 
00075   protected  void processResultCommand(Credential cred,Result resultCommande)  throws OpenMSPException  {
00076     throw new OpenMSPException("RESULT command not implemented.");
00077   }
00078 
00079   protected void processStatusCommand(Credential cred,Status statusCommande)  throws OpenMSPException   {
00080     throw new OpenMSPException("STATUS not implemented.");
00081   }
00082 
00083   protected Status processAddCommand(Credential cred, ContainerMessage addContainer) throws OpenMSPException    {
00084     throw new OpenMSPException("ADD command not implemented.");
00085   }
00086 
00087   protected Status processDeleteCommand(Credential cred, ContainerMessage deleteContainer) throws OpenMSPException  {
00088     throw new OpenMSPException("DELETE command not implemented.");
00089   }
00090  
00091   protected Status processReplaceCommand(Credential cred, ContainerMessage replaceContainer) throws OpenMSPException    {
00092     throw new OpenMSPException("REPLACE command not implemented.");
00093   }
00094 
00095   protected void beginProcessOpenMSpCommand(Credential cred)  throws OpenMSPException   {
00096   }
00097 
00098   protected ContainerMessage[] endProcessOpenMSpCommand()  throws OpenMSPException  {
00099     //do nothing.
00100     return null;
00101   }
00102 
00103   protected ContainerMessage[] processGetCommand(Credential cred, ContainerMessage getContainer)  throws OpenMSPException   {
00104     try {
00105       Element getCommand = getContainer.getElement(); //getCommand is a RequestCommand
00106    //   long sessionID = getCommand.getSourceSessionID();
00107       Result resultCommand = new Result(getCommand.getCmdId(), this.getTargetName(), OpenMSPProfileSyncListener.profilSynchroSourceName);
00108    //   resultCommand.setMetaInformation(Long.toString(newSessionId));
00109       ContainerMessage resultContainer = new ContainerMessage(resultCommand);
00110       SessionContext context = SessionContextManager.getManager().getSessionContext();
00111       User user = UserManager.getManager().getUser(context.getUserGroup(), context.getUserId());
00112       Profile profil = ProfileDataManager.getManager().getProfil(context.getUserGroup(), user.getProfil());
00113       String encodedProfil =  new String(GeneralCoder.encodeBase64(profil.toXML().getBytes()));
00114       DataItem newItem = new DataItem(Element.ITEM, "xmlprofil", encodedProfil, null, null);
00115       resultContainer.add(newItem);
00116       return new ContainerMessage[]{resultContainer};
00117     } catch (Throwable ex)  {
00118       throw new OpenMSPException(ex);
00119     }
00120 
00121   }
00122 
00123 }

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