1 18 19 package sync4j.framework.engine.source; 20 21 import java.util.logging.Logger ; 22 import java.util.logging.Level ; 23 import java.security.Principal ; 24 import java.sql.Timestamp ; 25 26 import sync4j.framework.logging.Sync4jLogger; 27 import sync4j.framework.engine.*; 28 import sync4j.framework.engine.source.SyncSource; 29 30 37 public abstract class AbstractSyncSource implements SyncSource, java.io.Serializable { 38 40 public static final String LOG_NAME = "engine.source"; 41 42 44 protected String name = null; 45 protected String type = null; 46 protected String sourceURI = null; 47 protected String sourceQuery= null; 48 protected SyncSourceInfo info = null; 49 50 53 protected long howManyAdded; 54 55 58 protected long howManyDeleted; 59 60 63 protected long howManyUpdated; 64 65 67 68 protected AbstractSyncSource() { 69 } 70 71 public AbstractSyncSource(String name, String type, String sourceURI) { 72 if (name == null) { 73 throw new NullPointerException ("name is null!"); 74 } 75 76 this.name = name; 77 this.type = (type == null) ? "unknown" : type; 78 setSourceURI(sourceURI); 79 } 80 81 public AbstractSyncSource(String name) { 82 this(name, null, null); 83 } 84 85 87 public String getName() { 88 return name; 89 } 90 91 public void setName(String name) { 92 this.name = name; 93 } 94 95 public String getType() { 96 return this.type; 97 } 98 99 public void setType(String type) { 100 this.type = type; 101 } 102 103 106 public String getSourceQuery() { 107 return sourceQuery; 108 } 109 110 113 public String getSourceURI() { 114 return sourceURI; 115 } 116 117 120 public void setSourceURI(String sourceURI) { 121 int qMark = sourceURI.indexOf('?'); 122 if (qMark == -1) { 123 this.sourceURI = sourceURI; 124 this.sourceQuery = ""; 125 } else { 126 this.sourceURI = sourceURI.substring(0, qMark); 127 this.sourceQuery = sourceURI.substring(qMark); 128 } 129 } 130 131 136 public SyncSourceInfo getInfo() { 137 return this.info; 138 } 139 140 143 public void setInfo(SyncSourceInfo info) { 144 this.info = info; 145 } 146 147 152 public String toString() { 153 StringBuffer sb = new StringBuffer (super.toString()); 154 155 sb.append(" - {name: ").append(getName() ); 156 sb.append(" type: " ).append(getType() ); 157 sb.append(" uri: " ).append(getSourceURI()); 158 sb.append("}" ); 159 160 return sb.toString(); 161 } 162 163 174 public void beginSync(Principal principal, int syncMode) throws SyncSourceException { 175 howManyAdded = howManyDeleted = howManyUpdated = 0; 176 } 177 178 188 public void endSync(Principal principal) throws SyncSourceException { 189 Logger log = Sync4jLogger.getLogger(LOG_NAME); 190 191 if (log.isLoggable(Level.INFO)) { 192 log.info(getSourceURI() 193 + ": " 194 + howManyAdded 195 + " new items added, " 196 + howManyUpdated 197 + " existing items updated, " 198 + howManyDeleted 199 + " items deleted." 200 ); 201 } 202 } 203 204 206 public abstract SyncItem[] getAllSyncItems(Principal principal) throws SyncSourceException; 207 208 public abstract SyncItemKey[] getDeletedSyncItemKeys(Principal principal, 209 Timestamp since ) throws SyncSourceException; 210 211 public abstract SyncItem[] getDeletedSyncItems(Principal principal, 212 Timestamp since ) throws SyncSourceException; 213 214 public abstract SyncItemKey[] getNewSyncItemKeys(Principal principal, 215 Timestamp since ) throws SyncSourceException; 216 217 public abstract SyncItem[] getNewSyncItems(Principal principal, 218 Timestamp since ) throws SyncSourceException; 219 220 public abstract SyncItem getSyncItemFromId(Principal principal, SyncItemKey syncItemKey) throws SyncSourceException; 221 222 public abstract SyncItem[] getSyncItemsFromIds(Principal principal, SyncItemKey[] syncItemKeys) throws SyncSourceException; 223 224 public abstract SyncItem[] getUpdatedSyncItems(Principal principal, 225 Timestamp since ) throws SyncSourceException; 226 227 public abstract void removeSyncItem(Principal principal, SyncItem syncItem) throws SyncSourceException; 228 229 public abstract void removeSyncItems(Principal principal, SyncItem[] syncItems) throws SyncSourceException; 230 231 public abstract SyncItem setSyncItem(Principal principal, SyncItem syncInstance) throws SyncSourceException; 232 233 public abstract SyncItem[] setSyncItems(Principal principal, SyncItem[] syncItems) throws SyncSourceException; 234 235 public abstract SyncItem getSyncItemFromTwin(Principal principal, SyncItem syncItem) throws SyncSourceException; 236 237 public abstract SyncItem[] getSyncItemsFromTwins(Principal principal, SyncItem[] syncItems) throws SyncSourceException; 238 } 239 | Popular Tags |