TestOpenMSPSynchroTargetListener.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 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     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener  processGetCommand V2");
00095     RequestCommand getCommand = (RequestCommand)getContainer.getElement();
00096     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand META DATA :"+getCommand.getMetaInformation());
00097     DataItem item = (DataItem) getContainer.nextMessage().getElement();
00098     // get meta info
00099     // meta info are of type : AOUID:<PDAUID>contact
00100     try {
00101       String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00102       String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00103       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand ITEM META DATA :"+meta);
00104       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand ITEM DATA :"+data);     
00105     } catch (Throwable ex)  {
00106       LogManager.traceError(0, ex);
00107       Status status = new Status(getCommand.getCmdId(), Status.STATUS_FAILED);
00108       ContainerMessage[] containerms = new ContainerMessage[1];
00109       containerms[0] = new ContainerMessage(status);
00110       return containerms;
00111     }
00112     Status status = new Status(getCommand.getCmdId(), Status.STATUS_OK);
00113     ContainerMessage[] containerms = new ContainerMessage[2];
00114     containerms[0] = new ContainerMessage(status);
00115     Result result = new Result(getCommand.getCmdId(), "testtarget", "testlistener");
00116     result.setMetaInformation("RESULT META INFO");
00117     ContainerMessage newContainer = new ContainerMessage(result);
00118     Item newItem = new DataItem(
00119                 Element.ITEM
00120                 , new String("RESULT ITEM META")
00121                 , new String("RESULT ITEM CONTENT")
00122                 , null
00123                 , null
00124             );
00125     newContainer.add(newItem);
00126     containerms[1] = newContainer;
00127     return containerms;
00128  }
00129 
00130   /* (non-Javadoc)
00131    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processAddCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.ContainerMessage)
00132    */
00133   protected Status processAddCommand(Credential cred, ContainerMessage addContainer) throws OpenMSPException {
00134     RequestCommand addCommand = (RequestCommand)addContainer.getElement();
00135     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand META DATA :"+addCommand.getMetaInformation());
00136     DataItem item = (DataItem) addContainer.nextMessage().getElement();
00137     // get meta info
00138     // meta info are of type : AOUID:<PDAUID>contact
00139     try {
00140       String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00141       String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00142       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand ITEM META DATA :"+meta);
00143       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand ITEM DATA :"+data);     
00144     } catch (Throwable ex)  {
00145       LogManager.traceError(0, ex);
00146       return new Status(addCommand.getCmdId(), Status.STATUS_FAILED);
00147     }
00148     return new Status(addCommand.getCmdId(), Status.STATUS_OK);
00149   }
00150 
00151   /* (non-Javadoc)
00152    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processDeleteCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.ContainerMessage)
00153    */
00154   protected Status processDeleteCommand(Credential cred, ContainerMessage deleteContainer) throws OpenMSPException {
00155     RequestCommand deleteCommand = (RequestCommand)deleteContainer.getElement();
00156     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand META DATA :"+deleteCommand.getMetaInformation());
00157     DataItem item = (DataItem) deleteContainer.nextMessage().getElement();
00158     // get meta info
00159     // meta info are of type : AOUID:<PDAUID>contact
00160     try {
00161       String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00162       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand ITEM META DATA :"+meta);
00163     } catch (Throwable ex)  {
00164       LogManager.traceError(0, ex);
00165       return new Status(deleteCommand.getCmdId(), Status.STATUS_FAILED);
00166     }
00167     return new Status(deleteCommand.getCmdId(), Status.STATUS_OK);  
00168   }
00169 
00170   /* (non-Javadoc)
00171    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#processReplaceCommand(org.openmobileis.synchro.security.auth.Credential, org.openmobileis.synchro.openmsp.protocol.ContainerMessage)
00172    */
00173   protected Status processReplaceCommand(Credential cred, ContainerMessage replaceContainer) throws OpenMSPException {
00174     RequestCommand replaceCommand = (RequestCommand)replaceContainer.getElement();
00175     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand META DATA :"+replaceCommand.getMetaInformation());
00176     DataItem item = (DataItem) replaceContainer.nextMessage().getElement();
00177     // get meta info
00178     // meta info are of type : AOUID:<PDAUID>contact
00179     try {
00180       String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00181       String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00182       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM META DATA :"+meta);
00183       LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM DATA :"+data);     
00184     } catch (Throwable ex)  {
00185       LogManager.traceError(0, ex);
00186       return new Status(replaceCommand.getCmdId(), Status.STATUS_FAILED);
00187     }
00188     return new Status(replaceCommand.getCmdId(), Status.STATUS_OK);  
00189   }
00190 
00191   /* (non-Javadoc)
00192    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#beginProcessSyncContainerMessage(org.openmobileis.synchro.security.auth.Credential)
00193    */
00194   protected void beginProcessOpenMSpCommand(Credential cred)  throws OpenMSPException {
00195     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener beginProcessSyncContainerMessage.");
00196   }
00197 
00198   /* (non-Javadoc)
00199    * @see org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener#endProcessSyncContainerMessage()
00200    */
00201   protected ContainerMessage[] endProcessOpenMSpCommand()  throws OpenMSPException  {
00202     LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener endProcessSyncContainerMessage.");
00203     ContainerMessage[] containerms = new ContainerMessage[1];
00204     Command getCommand = new Command(Element.GET, "testtarget", "testlistener");
00205     containerms[0] = new ContainerMessage(getCommand);
00206     return containerms;
00207   }
00208 
00209 }

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