1 18 package sync4j.framework.protocol; 19 20 import sync4j.framework.core.*; 21 import sync4j.framework.protocol.Flags; 22 23 46 public abstract class SyncPackage 47 implements Flags { 48 49 protected SyncHdr syncHeader = null; 50 protected SyncBody syncBody = null; 51 52 58 public SyncPackage(final SyncHdr syncHeader, 59 final SyncBody syncBody ) { 60 this.syncHeader = syncHeader; 61 this.syncBody = syncBody ; 62 } 63 64 66 69 private boolean[] flags = new boolean[HOW_MANY_FLAGS]; 70 71 78 public void setFlagValue(int flag, boolean value) { 79 switch (flag) { 80 case FLAG_ALL: 81 for (int i=0; i<HOW_MANY_FLAGS; i++) { 82 flags[i] = value; 83 } 84 break; 85 case FLAG_ALL_RESPONSES_REQUIRED: 86 flags[FLAG_SYNC_RESPONSE_REQUIRED ] = 87 flags[FLAG_MODIFICATIONS_RESPONSE_REQUIRED] = 88 flags[FLAG_SYNC_STATUS_REQUIRED ] = value; 89 break; 90 default: 91 flags[flag] = value; 92 } 93 } 94 95 100 public void setFlag(int flag) { 101 setFlagValue(flag, true); 102 } 103 104 109 public void unsetFlag(int flag) { 110 setFlagValue(flag, false); 111 } 112 113 120 public boolean isFlag(int flag) { 121 return flags[flag]; 122 } 123 124 126 129 protected CommandIdGenerator idGenerator = null; 130 131 public CommandIdGenerator getIdGenerator() { 132 return this.idGenerator; 133 } 134 135 public void setIdGenerator(CommandIdGenerator idGenerator) { 136 if (idGenerator == null) { 137 throw new NullPointerException ("idGenerator cannot be null"); 138 } 139 this.idGenerator = idGenerator; 140 } 141 142 145 public String getSessionId() { 146 return syncHeader.getSessionID().getSessionID(); 147 } 148 149 152 public VerDTD getDTDVersion() { 153 return syncHeader.getVerDTD(); 154 } 155 156 159 public VerProto getProtocolVersion() { 160 return syncHeader.getVerProto(); 161 } 162 163 165 171 public void checkRequirements() 172 throws ProtocolException 173 { 174 checkHeaderRequirements(); 175 checkBodyRequirements(); 176 } 177 178 183 public SyncHdr getSyncHeader() { 184 return this.syncHeader; 185 } 186 187 192 public SyncBody getSyncBody() { 193 return this.syncBody; 194 } 195 196 198 204 abstract public void checkHeaderRequirements() throws ProtocolException; 205 206 212 abstract public void checkBodyRequirements() throws ProtocolException; 213 214 222 abstract public SyncML getResponseMessage(String msgId) throws ProtocolException; 223 } | Popular Tags |