1 18 19 package sync4j.framework.protocol.v11; 20 21 import sync4j.framework.core.*; 22 23 import sync4j.framework.protocol.ProtocolException; 24 import sync4j.framework.protocol.v11.BasicRequirements; 25 import sync4j.framework.protocol.v11.Errors; 26 27 35 public class InitializationRequirements 36 extends BasicRequirements 37 implements Errors { 38 39 41 43 static public void checkAlertCommand(Alert alert) throws ProtocolException { 44 try { 45 BasicRequirements.checkAlertCommand(alert); 46 } catch (ProtocolException e) { 47 String [] args = new String [] { e.getMessage() }; 48 throw new ProtocolException(ERRMSG_INVALID_ALERT, args); 49 } 50 51 if (!AlertCode.isInitializationCode(alert.getData())) { 55 String [] args = new String [] { String.valueOf(alert.getData()) }; 56 throw new ProtocolException(ERRMSG_INVALID_ALERT_CODE, args); 57 } 58 59 Item[] items = (Item[])alert.getItems().toArray(new Item[0]); 63 64 if ((items == null) || (items.length ==0)) { 65 throw new ProtocolException(ERRMSG_MISSING_ITEM); 66 } 67 68 try { 69 checkSource(items[0].getSource()); 70 } catch (ProtocolException e) { 71 String [] args = new String [] { "source" }; 72 throw new ProtocolException(ERRMSG_INVALID_ALERT, args); 73 } 74 75 try { 76 checkTarget(items[0].getTarget()); 77 } catch (ProtocolException e) { 78 String [] args = new String [] { "target" }; 79 throw new ProtocolException(ERRMSG_INVALID_ALERT, args); 80 } 81 82 Meta meta = items[0].getMeta(); 86 87 if (meta == null || meta.getAnchor() == null) { 88 throw new ProtocolException(ERRMSG_MISSING_SYNC_ANCHOR); 89 } 90 } 91 92 99 static public void checkCapabilitiesRequest(Get cmd) 100 throws ProtocolException { 101 try { 105 checkCommandId(cmd.getCmdID()); 106 } catch (ProtocolException e) { 107 String [] args = new String [] { e.getMessage() }; 108 throw new ProtocolException(ERRMSG_INVALID_CAPABILITIES, args); 109 } 110 111 Item[] items = (Item[])cmd.getItems().toArray(new Item[0]); 112 113 if ((items == null) || (items.length ==0)) { 114 String [] args = new String [] {ERRMSG_MISSING_ITEM}; 115 throw new ProtocolException(ERRMSG_INVALID_CAPABILITIES_REQUEST, args); 116 } 117 118 try { 119 checkTarget(items[0].getTarget()); 120 } catch (ProtocolException e) { 121 String [] args = new String [] { "missing target" }; 122 throw new ProtocolException(ERRMSG_INVALID_CAPABILITIES_REQUEST, args); 123 } 124 } 125 } | Popular Tags |