1 18 19 package sync4j.syncclient.test; 20 21 import java.security.Principal ; 22 import java.util.Date ; 23 24 import sync4j.syncclient.spds.engine.*; 25 import sync4j.syncclient.spds.SyncException; 26 27 28 37 public class DummySyncSource implements SyncSource { 38 39 private String name = null; 40 private String type = null; 41 private String sourceURI = null; 42 43 private SyncItem[] allItems = null; 44 private SyncItem[] newItems = null; 45 private SyncItem[] deletedItems = null; 46 private SyncItem[] updatedItems = null; 47 48 50 51 public DummySyncSource() { 52 newItems = new SyncItem[] { 53 createItem("10", "This is a new item", SyncItemState.NEW) 54 }; 55 deletedItems = new SyncItem[] { 56 createItem("20", "This is a deleted item", SyncItemState.DELETED) 57 }; 58 updatedItems = new SyncItem[] { 59 createItem("30", "This is an updated item", SyncItemState.UPDATED) 60 }; 61 62 allItems = new SyncItem[newItems.length + updatedItems.length + 1]; 63 64 allItems[0] = createItem("40", "This is an unchanged item", SyncItemState.SYNCHRONIZED); 65 allItems[1] = newItems[0]; 66 allItems[2] = updatedItems[0]; 67 } 68 69 70 72 public String getName() { 73 return name; 74 } 75 76 public void setName(String name) { 77 System.out.println("setName(" + name + ")"); 78 this.name = name; 79 } 80 81 public String getType() { 82 return this.type; 83 } 84 85 public void setType(String type) { 86 System.out.println("setType(" + type + ")"); 87 this.type = type; 88 } 89 90 93 public String getSourceURI() { 94 return sourceURI; 95 } 96 97 100 public void setSourceURI(String sourceURI) { 101 System.out.println("setSourceURI(" + sourceURI + ")"); 102 this.sourceURI = sourceURI; 103 } 104 105 108 public void setParam1(String value) { 109 System.out.println("setParam1(" + value + ")"); 110 } 111 112 117 public String toString() { 118 StringBuffer sb = new StringBuffer (super.toString()); 119 120 sb.append(" - {name: ").append(getName() ); 121 sb.append(" type: " ).append(getType() ); 122 sb.append(" uri: " ).append(getSourceURI()); 123 sb.append("}" ); 124 125 return sb.toString(); 126 } 127 128 129 public void beginSync(int type) throws SyncException { 130 System.out.println("beginSync(" + type + ")"); 131 } 132 133 public void endSync() throws SyncException { 134 System.out.println("endSync()"); 135 } 136 137 public SyncItem[] getAllSyncItems(Principal principal) throws SyncException { 138 System.out.println("getAllSyncItems(" + principal + ")"); 139 return allItems; 140 } 141 142 143 public SyncItem[] getDeletedSyncItems(Principal principal, 144 Date since ) throws SyncException { 145 System.out.println("getDeletedSyncItems(" + principal + " , " + since + ")"); 146 147 return deletedItems; 148 149 } 150 151 152 public SyncItem[] getNewSyncItems(Principal principal, 153 Date since ) throws SyncException { 154 System.out.println("getNewSyncItems(" + principal + " , " + since + ")"); 155 156 return newItems; 157 158 } 159 160 public SyncItem[] getUpdatedSyncItems(Principal principal, 161 Date since ) throws SyncException { 162 System.out.println("getUpadtedSyncItems(" + principal + " , " + since + ")"); 163 164 return updatedItems; 165 166 } 167 168 public void removeSyncItem(Principal principal, SyncItem syncItem) throws SyncException { 169 System.out.println("removeSyncItem(" + principal + " , " + syncItem.getKey().getKeyAsString() + ")"); 170 } 171 172 public SyncItem setSyncItem(Principal principal, SyncItem syncItem) throws SyncException { 173 System.out.println("setSyncItem(" + principal + " , " + syncItem.getKey().getKeyAsString() + ")"); 174 return new SyncItemImpl(this, syncItem.getKey().getKeyAsString()+"-1"); 175 } 176 177 public void beginSync() { 178 } 179 180 public void commitSync() { 181 } 182 183 185 private SyncItem createItem(String id, String content, char state) { 186 SyncItem item = new SyncItemImpl(this, id, state); 187 188 item.setProperty( 189 new SyncItemProperty(SyncItem.PROPERTY_BINARY_CONTENT, content.getBytes()) 190 ); 191 192 return item; 193 } 194 } | Popular Tags |