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
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
00077
00078
00079 protected SyncItem[] getSyncItems(Principal principal, String type, Timestamp since) throws SyncSourceException {
00080
00081 return new SyncItem[0];
00082 }
00083
00084
00085
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 }