1 18 19 20 package sync4j.framework.core; 21 22 import java.util.*; 23 24 25 32 public final class Sync 33 extends AbstractCommand 34 implements java.io.Serializable { 35 36 public static String COMMAND_NAME = "Sync"; 38 39 private Target target; 41 private Source source; 42 private ArrayList commands = new ArrayList(); 43 private Long numberOfChanges; 44 45 47 48 protected Sync(){} 49 50 68 public Sync(final CmdID cmdID, 69 final boolean noResp, 70 final Cred cred, 71 final Target target, 72 final Source source, 73 final Meta meta, 74 final Long numberOfChanges, 75 final AbstractCommand[] commands) { 76 super(cmdID, noResp, meta); 77 78 setCommands(commands); 79 setCred(cred); 80 81 this.noResp = (noResp) ? new Boolean (noResp) : null; 82 this.target = target; 83 this.source = source; 84 this.numberOfChanges = numberOfChanges; 85 } 86 87 89 94 public Target getTarget() { 95 return target; 96 } 97 98 104 public void setTarget(Target target) { 105 this.target = target; 106 } 107 108 113 public Source getSource() { 114 return source; 115 } 116 117 122 public void setSource(Source source) { 123 this.source = source; 124 } 125 126 132 public ArrayList getCommands() { 133 return this.commands; 134 } 135 136 144 public void setCommands(AbstractCommand[] commands) { 145 if (commands == null) { 146 throw new IllegalArgumentException ("commands cannot be null"); 147 } 148 149 for (int i = 0; i < commands.length; i++) { 150 if (commands[i] == null) { 151 throw new IllegalArgumentException ("commands[" + i +"] cannot be null"); 152 } else if ((!(commands[i] instanceof Add)) 153 && (!(commands[i] instanceof Replace)) 154 && (!(commands[i] instanceof Delete)) 155 && (!(commands[i] instanceof Copy)) 156 && (!(commands[i] instanceof Atomic)) 157 && (!(commands[i] instanceof Map)) 158 && (!(commands[i] instanceof Sync))) { 159 throw new IllegalArgumentException ( 160 "commands[" + i + "] cannot be a " + commands[i].getName() 161 ); 162 } 163 } 164 this.commands.clear(); 165 this.commands.addAll(Arrays.asList(commands)); 166 } 167 168 173 public Long getNumberOfChanges() { 174 return numberOfChanges; 175 } 176 177 182 public void setNumberOfChanges(long numberOfChanges) { 183 this.numberOfChanges = new Long (numberOfChanges); 184 } 185 186 191 public void setNumberOfChanges(Long numberOfChanges) { 192 this.numberOfChanges = numberOfChanges; 193 } 194 195 public String getName() { 196 return Sync.COMMAND_NAME; 197 } 198 } | Popular Tags |