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

TestFODBSync4JSource.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.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   
00050   private TestData data1 = new TestData("id1", "create_server");
00051   private TestData data2 = new TestData("id2", "create_server");
00052   private int idSynchro = 0;
00056   public TestFODBSync4JSource() {
00057     super();
00058   }
00059 
00065   public TestFODBSync4JSource(String arg0, String arg1, String arg2) {
00066     super(arg0, arg1, arg2);
00067   }
00068 
00072   public TestFODBSync4JSource(String arg0) {
00073     super(arg0);
00074   }
00075 
00076   /* (non-Javadoc)
00077    * @see org.openmobileis.database.fastobjectdb.synchro.server.sync4j.FODBSync4JSource#getSyncItems(java.security.Principal, java.lang.String, java.sql.Timestamp)
00078    */
00079   protected SyncItem[] getSyncItems(Principal principal, String type, Timestamp since) throws SyncSourceException {
00080     // TODO Auto-generated method stub
00081     return new SyncItem[0];
00082   }
00083 
00084   /* (non-Javadoc)
00085    * @see org.openmobileis.database.fastobjectdb.synchro.server.sync4j.FODBSync4JSource#getSyncItem(java.security.Principal, java.lang.String)
00086    */
00087   protected SyncItem getSyncItem(Principal principal, String itemId) throws SyncSourceException {
00088     try {
00089             SyncItemImpl item =  new SyncItemImpl(this, itemId, SyncItemState.NEW);
00090             Object data = data1;
00091             if (itemId.equals("client/id2")) data = data2;
00092             item.setProperty(
00093                 new SyncProperty(SyncItem.PROPERTY_BINARY_CONTENT,
00094                             this.encodeObject(data))
00095                 );
00096             return item;
00097     } catch (Exception ex)      {
00098       LogManager.traceError(0, ex);
00099       throw new SyncSourceException(ex);
00100     }
00101   }
00102   
00103   private byte[] encodeObject(Object obj) throws IOException    {
00104                         ByteArrayOutputStream bstr = new ByteArrayOutputStream();
00105                         ObjectOutputStream ostr = new ObjectOutputStream(bstr);
00106                         ostr.writeObject(obj);
00107                         byte[] b = bstr.toByteArray();
00108                         return b;
00109   }
00110 
00111 }

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