1 18 package sync4j.framework.core; 19 20 import java.util.*; 21 22 30 public final class SyncBody 31 implements java.io.Serializable { 32 private ArrayList commands = new ArrayList(); 34 private Boolean finalMsg; 35 36 38 39 protected SyncBody() {} 40 41 53 public SyncBody( final AbstractCommand[] commands, final boolean finalMsg) { 54 55 setCommands(commands); 56 this.finalMsg = (finalMsg) ? new Boolean (finalMsg) : null; 57 } 58 59 61 67 public ArrayList getCommands() { 68 return this.commands; 69 } 70 71 72 79 public ArrayList getEmptyCommands() { 80 return new ArrayList(); 81 } 82 83 95 public void addAllCommands(List commands) { 96 if (commands == null) { 97 return; 98 } 99 for (int i = 0; i < commands.size(); i++) { 100 if (commands.get(i) == null) { 101 throw new IllegalArgumentException ("commands[" + i +"] cannot be null"); 102 } else if ( (!(commands.get(i) instanceof Alert)) 103 && (!(commands.get(i) instanceof Add)) 104 && (!(commands.get(i) instanceof Atomic)) 105 && (!(commands.get(i) instanceof Copy)) 106 && (!(commands.get(i) instanceof Delete)) 107 && (!(commands.get(i) instanceof Exec)) 108 && (!(commands.get(i) instanceof Get)) 109 && (!(commands.get(i) instanceof Map)) 110 && (!(commands.get(i) instanceof Put)) 111 && (!(commands.get(i) instanceof Replace)) 112 && (!(commands.get(i) instanceof Results)) 113 && (!(commands.get(i) instanceof Search)) 114 && (!(commands.get(i) instanceof Sequence)) 115 && (!(commands.get(i) instanceof Status)) 116 && (!(commands.get(i) instanceof Sync))) { 117 throw new IllegalArgumentException ( 118 "commands[" + i + "] cannot be a " + ((AbstractCommand)commands.get(i)).getName() 119 ); 120 } 121 } 122 123 this.commands.addAll(commands); 124 } 125 126 134 public void setCommands(AbstractCommand[] commands) { 135 if (commands == null) { 136 throw new IllegalArgumentException ("commands cannot be null"); 137 } 138 this.commands.clear(); 139 addAllCommands(Arrays.asList(commands)); 140 } 141 142 147 public void setFinalMsg(Boolean finalMsg) { 148 this.finalMsg = (finalMsg.booleanValue()) ? finalMsg : null; 149 } 150 151 157 public boolean isFinalMsg() { 158 return (finalMsg != null); 159 } 160 161 167 public Boolean getFinalMsg() { 168 if (!finalMsg.booleanValue()) { 169 return null; 170 } 171 return finalMsg; 172 } 173 } | Popular Tags |