1 18 package sync4j.framework.protocol.v11; 19 20 import sync4j.framework.core.*; 21 22 import sync4j.framework.protocol.ProtocolException; 23 import sync4j.framework.protocol.v11.BasicRequirements; 24 import sync4j.framework.protocol.v11.Errors; 25 26 33 public class SyncModificationsRequirements extends BasicRequirements implements Errors { 34 35 37 39 46 static public void checkSync(Sync cmd) throws ProtocolException { 47 try { 51 checkCommandId(cmd.getCmdID()); 52 } catch (ProtocolException e) { 53 String [] args = new String [] { e.getMessage() }; 54 throw new ProtocolException(ERRMSG_INVALID_SYNC_COMMAND, args); 55 } 56 57 AbstractCommand[] modifications = 61 (AbstractCommand[])cmd.getCommands().toArray(new AbstractCommand[0]); 62 63 for (int i=0; ((modifications != null) && (i<modifications.length)); ++i) { 64 checkModification((ItemizedCommand)modifications[i]); 65 } } 67 68 75 static public void checkModification(ItemizedCommand cmd) 76 throws ProtocolException { 77 try { 81 checkCommandId(cmd.getCmdID()); 82 83 84 Item[] items = (Item[])cmd.getItems().toArray(new Item[0]); 85 86 Meta meta = cmd.getMeta(); 94 95 boolean checkType = false; 96 if (meta.getType() != null) { 97 checkType = true; 98 } 99 100 for(int i=0; ((items != null) && (i<items.length)); ++i) { 101 checkModificationItem(items[i], checkType, !cmd.getName().equals("Delete")); 106 } 107 108 } catch (ProtocolException e) { 109 String [] args = new String [] { e.getMessage() }; 110 throw new ProtocolException(ERRMSG_INVALID_MODIFICATION_COMMAND, args); 111 } 112 } 113 114 124 static public void checkModificationItem(final Item item , 125 final boolean checkType, 126 final boolean checkData) 127 throws ProtocolException { 128 checkSource(item.getSource()); 129 130 if (checkType) { 131 Meta meta = item.getMeta(); 132 if (meta.getType() == null) { 133 String [] args = new String [] { item.toString() }; 134 throw new ProtocolException(ERRMSG_MISSING_TYPE, args); 135 } 136 } 137 138 if (checkData) { 139 if (item.getData() == null) { 140 String [] args = new String [] { item.toString() }; 141 throw new ProtocolException(ERRMSG_MISSING_DATA, args); 142 } 143 } 144 } 145 146 } | Popular Tags |