1 18 19 package sync4j.syncclient.spds.engine; 20 21 import java.util.Hashtable ; 22 import java.util.Enumeration ; 23 24 import sync4j.syncclient.spds.engine.*; 25 26 33 public class SyncItemImpl implements SyncItem { 34 35 37 40 protected SyncItemKey key = null; 41 public SyncItemKey getKey() { 42 return this.key; 43 } 44 45 49 protected char state = SyncItemState.UNKNOWN; 50 51 public char getState(){ 52 return state; 53 } 54 55 public void setState(char state){ 56 this.state = state; 57 } 58 59 62 protected Hashtable properties = new Hashtable (); 63 64 70 public Hashtable getProperties() { 71 return this.properties; 72 } 73 74 80 public void setProperties(Hashtable properties){ 81 this.properties.clear(); 82 83 String name = null; 84 85 Enumeration i = properties.keys(); 86 while(i.hasMoreElements()) { 87 name = (String )i.nextElement(); 88 this.properties.put( 89 name, 90 new SyncItemProperty(name, properties.get(name)) 91 ); 92 } 93 } 94 95 99 public void setProperty(SyncItemProperty property) { 100 properties.put(property.getName(), property); 101 } 102 103 109 public SyncItemProperty getProperty(String propertyName) { 110 return (SyncItemProperty)properties.get(propertyName); 111 } 112 113 116 protected SyncSource syncSource = null; 117 118 122 public SyncSource getSyncSource() { 123 return syncSource; 124 } 125 126 130 public void setSyncSource(SyncSource syncSource) { 131 if (syncSource == null) { 132 throw new NullPointerException ("syncSource cannot be null"); 133 } 134 135 this.syncSource = syncSource; 136 } 137 138 140 public SyncItemImpl(SyncSource syncSource, Object key) { 141 this(syncSource, key, SyncItemState.UNKNOWN); 142 } 143 144 152 public SyncItemImpl(SyncSource syncSource, Object key, char state) { 153 this.syncSource = syncSource ; 154 this.key = new SyncItemKey(key); 155 this.state = state ; 156 } 157 158 160 161 166 public void setPropertyValue(String propertyName, String propertyValue) { 167 SyncItemProperty property = (SyncItemProperty)properties.get(propertyName); 168 169 if (property != null) { 170 property.setValue(propertyValue); 171 } 172 } 173 174 181 public Object getPropertyValue(String propertyName) { 182 SyncItemProperty property = (SyncItemProperty)properties.get(propertyName); 183 184 return (property == null) ? null 185 : property.getValue() 186 ; 187 } 188 189 197 public boolean equals(Object o) { 198 if (!(o instanceof SyncItem)) return false; 199 200 return ((SyncItem)o).getKey().equals(key); 201 } 202 203 210 public static SyncItem getNotExistingSyncItem(SyncSource syncSource) { 211 SyncItem notExisting = new SyncItemImpl(syncSource, "NOT_EXISTING"); 212 213 notExisting.setState(SyncItemState.NOT_EXISTING); 214 215 return notExisting; 216 } 217 } | Popular Tags |