1 25 package org.jrobin.mrtg.server; 26 27 import java.util.Vector ; 28 29 class DeviceList { 30 private Vector routers = new Vector (); 31 32 DeviceList() { } 33 34 Vector getRouters() { 35 return routers; 36 } 37 38 void setRouters(Vector routers) { 39 this.routers = routers; 40 } 41 42 public String toString() { 43 StringBuffer buff = new StringBuffer (); 44 for(int i = 0; i < routers.size(); i++) { 45 buff.append(routers.get(i)); 46 } 47 return buff.toString(); 48 } 49 50 Device getRouterByHost(String host) { 51 for(int i = 0; i < routers.size(); i++) { 52 Device router = (Device) routers.get(i); 53 if(router.getHost().equalsIgnoreCase(host)) { 54 return router; 55 } 56 } 57 return null; 58 } 59 60 int addRouter(String host, String community, String descr, boolean active) { 61 Device router = getRouterByHost(host); 62 if(router == null) { 63 Device newRouter = new Device(); 65 newRouter.setHost(host); 66 newRouter.setCommunity(community); 67 newRouter.setDescr(descr); 68 newRouter.setActive(active); 69 routers.add(newRouter); 70 return 0; 72 } 73 return -1; 75 } 76 77 int updateRouter(String host, String community, String descr, boolean active) { 78 Device router = getRouterByHost(host); 79 if(router != null) { 80 router.setCommunity(community); 81 router.setDescr(descr); 82 router.setActive(active); 83 return 0; 84 } 85 return -1; 87 } 88 89 int removeRouter(String host) { 90 Device router = getRouterByHost(host); 91 if(router == null) { 92 return -1; 94 } 95 if(router.getLinkCount() > 0) { 97 return -2; 98 } 99 routers.remove(router); 100 return 0; 101 } 102 103 int addLink(String host, String ifDescr, String descr, int samplingInterval, boolean active) { 104 Device router = getRouterByHost(host); 105 if(router == null) { 106 return -1; 108 } 109 Port link = router.getLinkByIfDescr(ifDescr); 110 if(link != null) { 111 return -2; 113 } 114 Port newLink = new Port(); 115 newLink.setDescr(descr); 116 newLink.setIfDescr(ifDescr); 117 newLink.setSamplingInterval(samplingInterval); 118 newLink.setActive(active); 119 router.addLink(newLink); 120 return 0; 121 } 122 123 int updateLink(String host, String ifDescr, String descr, int samplingInterval, boolean active) { 124 Device router = getRouterByHost(host); 125 if(router == null) { 126 return -1; 128 } 129 Port link = router.getLinkByIfDescr(ifDescr); 130 if(link == null) { 131 return -2; 133 } 134 link.setDescr(descr); 135 link.setSamplingInterval(samplingInterval); 136 link.setActive(active); 137 return 0; 138 } 139 140 int removeLink(String host, String ifDescr) { 141 Device router = getRouterByHost(host); 142 if(router == null) { 143 return -1; 145 } 146 Port link = router.getLinkByIfDescr(ifDescr); 147 if(link == null) { 148 return -2; 150 } 151 router.removeLink(link); 152 return 0; 153 } 154 } 155 156 | Popular Tags |