TestFODBSync4JSource.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.database.fastobjectdb.db.test.synchro.sync4j;
00026 
00027 import java.io.ByteArrayOutputStream;
00028 import java.io.IOException;
00029 import java.io.ObjectOutputStream;
00030 import java.security.Principal;
00031 import java.sql.Timestamp;
00032 
00033 import org.openmobileis.common.util.log.LogManager;
00034 import org.openmobileis.synchro.sync4j.server.FODBSync4JSource;
00035 
00036 import sync4j.framework.engine.SyncItem;
00037 import sync4j.framework.engine.SyncItemImpl;
00038 import sync4j.framework.engine.SyncItemState;
00039 import sync4j.framework.engine.SyncProperty;
00040 import sync4j.framework.engine.source.SyncSourceException;
00041 
00048 public class TestFODBSync4JSource extends FODBSync4JSource {
00049   static final long serialVersionUID = 5521257935120563452L;
00050   
00051   private TestData data1 = new TestData("id1", "create_server");
00052   private TestData data2 = new TestData("id2", "create_server");
00053   private int idSynchro = 0;
00057   public TestFODBSync4JSource() {
00058     super();
00059   }
00060 
00066   public TestFODBSync4JSource(String arg0, String arg1, String arg2) {
00067     super(arg0, arg1, arg2);
00068   }
00069 
00073   public TestFODBSync4JSource(String arg0) {
00074     super(arg0);
00075   }
00076 
00077   /* (non-Javadoc)
00078    * @see org.openmobileis.database.fastobjectdb.synchro.server.sync4j.FODBSync4JSource#getSyncItems(java.security.Principal, java.lang.String, java.sql.Timestamp)
00079    */
00080   protected SyncItem[] getSyncItems(Principal principal, String type, Timestamp since) throws SyncSourceException {
00081     // TODO Auto-generated method stub
00082     return new SyncItem[0];
00083   }
00084 
00085   /* (non-Javadoc)
00086    * @see org.openmobileis.database.fastobjectdb.synchro.server.sync4j.FODBSync4JSource#getSyncItem(java.security.Principal, java.lang.String)
00087    */
00088   protected SyncItem getSyncItem(Principal principal, String itemId) throws SyncSourceException {
00089     try {
00090             SyncItemImpl item =  new SyncItemImpl(this, itemId, SyncItemState.NEW);
00091             Object data = data1;
00092             if (itemId.equals("client/id2")) data = data2;
00093             item.setProperty(
00094                 new SyncProperty(SyncItem.PROPERTY_BINARY_CONTENT,
00095                             this.encodeObject(data))
00096                 );
00097             return item;
00098     } catch (Exception ex)      {
00099       LogManager.traceError(0, ex);
00100       throw new SyncSourceException(ex);
00101     }
00102   }
00103   
00104   private byte[] encodeObject(Object obj) throws IOException    {
00105                         ByteArrayOutputStream bstr = new ByteArrayOutputStream();
00106                         ObjectOutputStream ostr = new ObjectOutputStream(bstr);
00107                         ostr.writeObject(obj);
00108                         byte[] b = bstr.toByteArray();
00109                         return b;
00110   }
00111 
00112 }

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