00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00078
00079
00080 protected SyncItem[] getSyncItems(Principal principal, String type, Timestamp since) throws SyncSourceException {
00081
00082 return new SyncItem[0];
00083 }
00084
00085
00086
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 }