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

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