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 ClientModificationsRequirements 34 extends BasicRequirements 35 implements Errors { 36 37 39 41 48 static public void checkSync(Sync cmd) throws ProtocolException { 49 try { 53 checkCommandId(cmd.getCmdID()); 54 } catch (ProtocolException e) { 55 String [] args = new String [] { e.getMessage() }; 56 throw new ProtocolException(ERRMSG_INVALID_SYNC_COMMAND, args); 57 } 58 59 AbstractCommand[] modifications = 63 (AbstractCommand[])cmd.getCommands().toArray(new AbstractCommand[0]); 64 65 for (int i=0; ((modifications != null) && (i<modifications.length)); ++i) { 66 checkModification((ItemizedCommand)modifications[i]); 67 } } 69 70 77 static public void checkModification(ItemizedCommand cmd) 78 throws ProtocolException { 79 try { 83 checkCommandId(cmd.getCmdID()); 84 85 86 Item[] items = (Item[])cmd.getItems().toArray(new Item[0]); 87 88 Meta meta = cmd.getMeta(); 96 97 boolean checkType = false; 98 if (meta.getType() != null) { 99 checkType = true; 100 } 101 102 for(int i=0; ((items != null) && (i<items.length)); ++i) { 103 checkModificationItem(items[i], checkType, !cmd.getName().equals("Delete")); 108 } 109 110 } catch (ProtocolException e) { 111 String [] args = new String [] { e.getMessage() }; 112 throw new ProtocolException(ERRMSG_INVALID_MODIFICATION_COMMAND, args); 113 } 114 } 115 116 126 static public void checkModificationItem(final Item item , 127 final boolean checkType, 128 final boolean checkData) 129 throws ProtocolException { 130 checkSource(item.getSource()); 131 132 if (checkType) { 133 Meta meta = item.getMeta(); 134 if (meta.getType() == null) { 135 String [] args = new String [] { item.toString() }; 136 throw new ProtocolException(ERRMSG_MISSING_TYPE, args); 137 } 138 } 139 140 if (checkData) { 141 if (item.getData() == null) { 142 String [] args = new String [] { item.toString() }; 143 throw new ProtocolException(ERRMSG_MISSING_DATA, args); 144 } 145 } 146 } 147 148 } | Popular Tags |