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

TestOpenMSPSynchroTargetListener.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
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 package org.openmobileis.synchro.openmsp.protocol.test;
00026 
00027 import org.openmobileis.common.util.codec.GeneralCoder;
00028 import org.openmobileis.common.util.log.LogManager;
00029 import org.openmobileis.synchro.openmsp.OpenMSPException;
00030 import org.openmobileis.synchro.openmsp.protocol.Command;
00031 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00032 import org.openmobileis.synchro.openmsp.protocol.DataItem;
00033 import org.openmobileis.synchro.openmsp.protocol.Element;
00034 import org.openmobileis.synchro.openmsp.protocol.Item;
00035 import org.openmobileis.synchro.openmsp.protocol.RequestCommand;
00036 import org.openmobileis.synchro.openmsp.protocol.Result;
00037 import org.openmobileis.synchro.openmsp.protocol.Status;
00038 import org.openmobileis.synchro.openmsp.server.synctarget.DefaultOpenMSPSynchroTargetListener;
00039 import org.openmobileis.synchro.security.auth.Credential;
00040 
00048 public final class TestOpenMSPSynchroTargetListener extends DefaultOpenMSPSynchroTargetListener {
00049 
00053   public TestOpenMSPSynchroTargetListener() {
00054     super();
00055   }
00056   
00057   public String getTargetName() {
00058     return "testtarget";
00059   }
00060 
00061   /* (non-Javadoc)
00062    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processMapCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.ContainerMessage)
00063    */
00064   protected ContainerMessage processMapCommand(Credential cred, ContainerMessage mapContainer) {
00065     return null;
00066   }
00067 
00068   /* (non-Javadoc)
00069    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#notifySyncAction(long, org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.Command)
00070    */
00071   protected void notifySyncAction(long sessionId,Credential cred, Command syncCommand)  throws OpenMSPException  {
00072     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener notifySyncAction META DATA :"+syncCommand.getMetaInformation());
00073   }
00074 
00075   /* (non-Javadoc)
00076    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processResultCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.Result)
00077    */
00078   protected void processResultCommand(Credential cred, Result resultCommande) throws OpenMSPException {
00079     // TODO Auto-generated method stub
00080 
00081   }
00082 
00083   /* (non-Javadoc)
00084    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processStatusCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.Status)
00085    */
00086   protected void processStatusCommand(Credential cred, Status statusCommande) throws OpenMSPException {
00087     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processStatusCommand  status :"+statusCommande.getStatus()+" commandRef:"+statusCommande.getCmdRef());
00088   }
00089 
00090   /* (non-Javadoc)
00091    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processAddCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.ContainerMessage)
00092    */
00093   protected ContainerMessage[] processGetCommand(Credential cred, ContainerMessage getContainer)  throws OpenMSPException {
00094     RequestCommand getCommand = (RequestCommand)getContainer.getElement();
00095     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand META DATA :"+getCommand.getMetaInformation());
00096     DataItem item = (DataItem) getContainer.nextMessage().getElement();
00097     // get meta info
00098     // meta info are of type : AOUID:<PDAUID>contact
00099     try {
00100       String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00101       String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00102       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand ITEM META DATA :"+meta);
00103       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand ITEM DATA :"+data);     
00104     } catch (Throwable ex)  {
00105       LogManager.traceError(0, ex);
00106       Status status = new Status(getCommand.getCmdId(), Status.STATUS_FAILED);
00107       ContainerMessage[] containerms = new ContainerMessage[1];
00108       containerms[0] = new ContainerMessage(status);
00109       return containerms;
00110     }
00111     Status status = new Status(getCommand.getCmdId(), Status.STATUS_OK);
00112     ContainerMessage[] containerms = new ContainerMessage[2];
00113     containerms[0] = new ContainerMessage(status);
00114     Result result = new Result(getCommand.getCmdId(), "testtarget", "testlistener");
00115     result.setMetaInformation("RESULT META INFO");
00116     ContainerMessage newContainer = new ContainerMessage(result);
00117     Item newItem = new DataItem(
00118                 Element.ITEM
00119                 , new String("RESULT ITEM META")
00120                 , new String("RESULT ITEM CONTENT")
00121                 , null
00122                 , null
00123             );
00124     newContainer.add(newItem);
00125     containerms[1] = newContainer;
00126     return containerms;
00127  }
00128 
00129   /* (non-Javadoc)
00130    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processAddCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.ContainerMessage)
00131    */
00132   protected Status processAddCommand(Credential cred, ContainerMessage addContainer) throws OpenMSPException {
00133     RequestCommand addCommand = (RequestCommand)addContainer.getElement();
00134     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand META DATA :"+addCommand.getMetaInformation());
00135     DataItem item = (DataItem) addContainer.nextMessage().getElement();
00136     // get meta info
00137     // meta info are of type : AOUID:<PDAUID>contact
00138     try {
00139       String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00140       String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00141       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand ITEM META DATA :"+meta);
00142       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand ITEM DATA :"+data);     
00143     } catch (Throwable ex)  {
00144       LogManager.traceError(0, ex);
00145       return new Status(addCommand.getCmdId(), Status.STATUS_FAILED);
00146     }
00147     return new Status(addCommand.getCmdId(), Status.STATUS_OK);
00148   }
00149 
00150   /* (non-Javadoc)
00151    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processSyncItem(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.Item)
00152    */
00153   protected void processSyncItem(Credential cred, Item item) throws OpenMSPException {
00154     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processSyncItem ITEM :"+item.getCmdId());
00155   }
00156 
00157   /* (non-Javadoc)
00158    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processDeleteCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.ContainerMessage)
00159    */
00160   protected Status processDeleteCommand(Credential cred, ContainerMessage deleteContainer) throws OpenMSPException {
00161     RequestCommand deleteCommand = (RequestCommand)deleteContainer.getElement();
00162     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand META DATA :"+deleteCommand.getMetaInformation());
00163     DataItem item = (DataItem) deleteContainer.nextMessage().getElement();
00164     // get meta info
00165     // meta info are of type : AOUID:<PDAUID>contact
00166     try {
00167       String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00168       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand ITEM META DATA :"+meta);
00169     } catch (Throwable ex)  {
00170       LogManager.traceError(0, ex);
00171       return new Status(deleteCommand.getCmdId(), Status.STATUS_FAILED);
00172     }
00173     return new Status(deleteCommand.getCmdId(), Status.STATUS_OK);  
00174   }
00175 
00176   /* (non-Javadoc)
00177    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processReplaceCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.ContainerMessage)
00178    */
00179   protected Status processReplaceCommand(Credential cred, ContainerMessage replaceContainer) throws OpenMSPException {
00180     RequestCommand replaceCommand = (RequestCommand)replaceContainer.getElement();
00181     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand META DATA :"+replaceCommand.getMetaInformation());
00182     DataItem item = (DataItem) replaceContainer.nextMessage().getElement();
00183     // get meta info
00184     // meta info are of type : AOUID:<PDAUID>contact
00185     try {
00186       String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00187       String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00188       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM META DATA :"+meta);
00189       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM DATA :"+data);     
00190     } catch (Throwable ex)  {
00191       LogManager.traceError(0, ex);
00192       return new Status(replaceCommand.getCmdId(), Status.STATUS_FAILED);
00193     }
00194     return new Status(replaceCommand.getCmdId(), Status.STATUS_OK);  
00195   }
00196 
00197   /* (non-Javadoc)
00198    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#beginProcessSyncContainerMessage(org.openmobileis.synchro.security.auth.Credential)
00199    */
00200   protected void beginProcessOpenMSpCommand(Credential cred)  throws OpenMSPException {
00201     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener beginProcessSyncContainerMessage.");
00202   }
00203 
00204   /* (non-Javadoc)
00205    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#endProcessSyncContainerMessage()
00206    */
00207   protected ContainerMessage[] endProcessOpenMSpCommand()  throws OpenMSPException  {
00208     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener endProcessSyncContainerMessage.");
00209     ContainerMessage[] containerms = new ContainerMessage[1];
00210     Command getCommand = new Command(Element.GET, "testtarget", "testlistener");
00211     containerms[0] = new ContainerMessage(getCommand);
00212     return null;
00213   }
00214 
00215 }

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