1 18 19 package sync4j.syncclient.spds.engine; 20 21 import java.io.*; 22 import java.util.Hashtable ; 23 24 import java.security.Principal ; 25 26 import sync4j.syncclient.common.StringTools; 27 28 29 36 public class SyncSourceDefinition { 37 38 40 public static final String CONFIG_NAME = "name" ; 41 public static final String CONFIG_CLASS = "sourceClass" ; 42 public static final String CONFIG_URI = "sourceURI" ; 43 public static final String CONFIG_TYPE = "type" ; 44 public static final String CONFIG_LAST = "last" ; 45 public static final String CONFIG_DEFAULT_SYNC = "sync" ; 46 public static final String CONFIG_SUPPORTED_SYNC_MODES = "syncModes" ; 47 48 50 private Hashtable properties = null; 51 52 public String getName() { 53 return (String )properties.get(CONFIG_NAME); 54 } 55 56 public String getSourceClass() { 57 return (String )properties.get(CONFIG_CLASS); 58 } 59 60 public String getSourceUri() { 61 return (String )properties.get(CONFIG_URI); 62 } 63 64 public String getType() { 65 return (String )properties.get(CONFIG_TYPE); 66 } 67 68 public String getDefaultSync() { 69 return (String )properties.get(CONFIG_DEFAULT_SYNC); 70 } 71 72 public String [] getSupportedSyncModes() { 73 return StringTools.split((String )properties.get(CONFIG_SUPPORTED_SYNC_MODES)); 74 } 75 76 public long getLastTimestamp() { 77 String last = (String )properties.get(CONFIG_LAST); 78 79 try { 80 return (last == null) ? 0 : Long.parseLong(last); 81 } catch (NumberFormatException e) { 82 return 0; 83 } 84 } 85 86 public Hashtable getProperties() { 87 return properties; 88 } 89 90 public SyncSourceDefinition (Hashtable properties) { 91 String sourceClass = (String )properties.get(CONFIG_CLASS ); 92 String uri = (String )properties.get(CONFIG_URI ); 93 String className = (String )properties.get(CONFIG_CLASS ); 94 String name = (String )properties.get(CONFIG_NAME ); 95 String type = (String )properties.get(CONFIG_TYPE ); 96 String defaultSync = (String )properties.get(CONFIG_DEFAULT_SYNC ); 97 String syncModes = (String )properties.get(CONFIG_SUPPORTED_SYNC_MODES); 98 99 100 if (sourceClass == null) { 101 throw new IllegalArgumentException ("Missing 'sourceClass' in properties!"); 102 } 103 104 if (uri == null) { 105 throw new IllegalArgumentException ("Missing 'uri' in properties!"); 106 } 107 108 if (name == null) { 109 throw new IllegalArgumentException ("Missing 'name' in properties!"); 110 } 111 112 if (type == null) { 113 throw new IllegalArgumentException ("Missing 'type' in properties!"); 114 } 115 116 if (defaultSync == null) { 117 properties.put(CONFIG_DEFAULT_SYNC, "two-way"); 118 } 119 120 if (syncModes == null) { 121 properties.put(CONFIG_SUPPORTED_SYNC_MODES, "two-way"); 122 } 123 124 this.properties = properties; 125 } 126 } | Popular Tags |