1 23 24 54 55 package com.sun.enterprise.admin.monitor.stats.lb; 56 57 public class LoadBalancerStats implements com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStatsInterface, com.sun.enterprise.admin.monitor.stats.lb.CommonBean { 58 private java.util.List _ClusterStats = new java.util.ArrayList (); 60 public LoadBalancerStats() { 61 } 62 63 public LoadBalancerStats(com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats source) { 65 for (java.util.Iterator it = source._ClusterStats.iterator(); 66 it.hasNext(); ) { 67 _ClusterStats.add(new com.sun.enterprise.admin.monitor.stats.lb.ClusterStats((com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it.next())); 68 } 69 } 70 71 public void setClusterStats(com.sun.enterprise.admin.monitor.stats.lb.ClusterStats[] value) { 73 if (value == null) 74 value = new ClusterStats[0]; 75 _ClusterStats.clear(); 76 for (int i = 0; i < value.length; ++i) { 77 _ClusterStats.add(value[i]); 78 } 79 } 80 81 public void setClusterStats(int index, com.sun.enterprise.admin.monitor.stats.lb.ClusterStats value) { 82 _ClusterStats.set(index, value); 83 } 84 85 public com.sun.enterprise.admin.monitor.stats.lb.ClusterStats[] getClusterStats() { 86 ClusterStats[] arr = new ClusterStats[_ClusterStats.size()]; 87 return (ClusterStats[]) _ClusterStats.toArray(arr); 88 } 89 90 public java.util.List fetchClusterStatsList() { 91 return _ClusterStats; 92 } 93 94 public com.sun.enterprise.admin.monitor.stats.lb.ClusterStats getClusterStats(int index) { 95 return (ClusterStats)_ClusterStats.get(index); 96 } 97 98 public int sizeClusterStats() { 100 return _ClusterStats.size(); 101 } 102 103 public int addClusterStats(com.sun.enterprise.admin.monitor.stats.lb.ClusterStats value) { 104 _ClusterStats.add(value); 105 return _ClusterStats.size()-1; 106 } 107 108 public int removeClusterStats(com.sun.enterprise.admin.monitor.stats.lb.ClusterStats value) { 110 int pos = _ClusterStats.indexOf(value); 111 if (pos >= 0) { 112 _ClusterStats.remove(pos); 113 } 114 return pos; 115 } 116 117 public void write(java.io.OutputStream out) throws java.io.IOException { 118 write(out, null); 119 } 120 121 public void write(java.io.OutputStream out, String encoding) throws java.io.IOException { 122 java.io.Writer w; 123 if (encoding == null) { 124 encoding = "UTF-8"; } 126 w = new java.io.BufferedWriter (new java.io.OutputStreamWriter (out, encoding)); 127 write(w, encoding); 128 w.flush(); 129 } 130 131 public void write(java.io.Writer out, String encoding) throws java.io.IOException { 134 out.write("<?xml version='1.0'"); if (encoding != null) 136 out.write(" encoding='"+encoding+"'"); out.write(" ?>\n"); writeNode(out, "load-balancer-stats", ""); } 140 141 public void writeNode(java.io.Writer out, String nodeName, String indent) throws java.io.IOException { 142 out.write(indent); 143 out.write("<"); 144 out.write(nodeName); 145 out.write(">\n"); 146 String nextIndent = indent + " "; 147 for (java.util.Iterator it = _ClusterStats.iterator(); 148 it.hasNext(); ) { 149 com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element = (com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it.next(); 150 if (element != null) { 151 element.writeNode(out, "cluster-stats", nextIndent); 152 } 153 } 154 out.write(indent); 155 out.write("</"+nodeName+">\n"); 156 } 157 158 public static LoadBalancerStats read(java.io.InputStream in) throws javax.xml.parsers.ParserConfigurationException , org.xml.sax.SAXException , java.io.IOException { 159 return read(new org.xml.sax.InputSource (in), false, null, null); 160 } 161 162 public static LoadBalancerStats readNoEntityResolver(java.io.InputStream in) throws javax.xml.parsers.ParserConfigurationException , org.xml.sax.SAXException , java.io.IOException { 167 return read(new org.xml.sax.InputSource (in), false, 168 new org.xml.sax.EntityResolver () { 169 public org.xml.sax.InputSource resolveEntity(String publicId, String systemId) { 170 java.io.ByteArrayInputStream bin = new java.io.ByteArrayInputStream (new byte[0]); 171 return new org.xml.sax.InputSource (bin); 172 } 173 } 174 , null); 175 } 176 177 public static LoadBalancerStats read(org.xml.sax.InputSource in, boolean validate, org.xml.sax.EntityResolver er, org.xml.sax.ErrorHandler eh) throws javax.xml.parsers.ParserConfigurationException , org.xml.sax.SAXException , java.io.IOException { 178 javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); 179 dbf.setValidating(validate); 180 javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); 181 if (er != null) db.setEntityResolver(er); 182 if (eh != null) db.setErrorHandler(eh); 183 org.w3c.dom.Document doc = db.parse(in); 184 return read(doc); 185 } 186 187 public static LoadBalancerStats read(org.w3c.dom.Document document) { 188 LoadBalancerStats aLoadBalancerStats = new LoadBalancerStats(); 189 aLoadBalancerStats.readNode(document.getDocumentElement()); 190 return aLoadBalancerStats; 191 } 192 193 public void readNode(org.w3c.dom.Node node) { 194 org.w3c.dom.NodeList children = node.getChildNodes(); 195 for (int i = 0, size = children.getLength(); i < size; ++i) { 196 org.w3c.dom.Node childNode = children.item(i); 197 String childNodeName = (childNode.getLocalName() == null ? childNode.getNodeName().intern() : childNode.getLocalName().intern()); 198 String childNodeValue = ""; 199 if (childNode.getFirstChild() != null) { 200 childNodeValue = childNode.getFirstChild().getNodeValue(); 201 } 202 if (childNodeName == "cluster-stats") { 203 ClusterStats aClusterStats = new com.sun.enterprise.admin.monitor.stats.lb.ClusterStats(); 204 aClusterStats.readNode(childNode); 205 _ClusterStats.add(aClusterStats); 206 } 207 else { 208 } 210 } 211 } 212 213 public static void writeXML(java.io.Writer out, String msg) throws java.io.IOException { 216 writeXML(out, msg, true); 217 } 218 219 public static void writeXML(java.io.Writer out, String msg, boolean attribute) throws java.io.IOException { 220 if (msg == null) 221 return; 222 int msgLength = msg.length(); 223 for (int i = 0; i < msgLength; ++i) { 224 char c = msg.charAt(i); 225 writeXML(out, c, attribute); 226 } 227 } 228 229 public static void writeXML(java.io.Writer out, char msg, boolean attribute) throws java.io.IOException { 230 if (msg == '&') 231 out.write("&"); 232 else if (msg == '<') 233 out.write("<"); 234 else if (msg == '>') 235 out.write(">"); 236 else if (attribute && msg == '"') 237 out.write("""); 238 else if (attribute && msg == '\'') 239 out.write("'"); 240 else if (attribute && msg == '\n') 241 out.write("
"); 242 else if (attribute && msg == '\t') 243 out.write("	"); 244 else 245 out.write(msg); 246 } 247 248 public static class ValidateException extends Exception { 249 private com.sun.enterprise.admin.monitor.stats.lb.CommonBean failedBean; 250 private String failedPropertyName; 251 public ValidateException(String msg, String failedPropertyName, com.sun.enterprise.admin.monitor.stats.lb.CommonBean failedBean) { 252 super(msg); 253 this.failedBean = failedBean; 254 this.failedPropertyName = failedPropertyName; 255 } 256 public String getFailedPropertyName() {return failedPropertyName;} 257 public com.sun.enterprise.admin.monitor.stats.lb.CommonBean getFailedBean() {return failedBean;} 258 } 259 260 public void validate() throws com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats.ValidateException { 261 boolean restrictionFailure = false; 262 for (int _index = 0; _index < sizeClusterStats(); ++_index) { 264 com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element = getClusterStats(_index); 265 if (element != null) { 266 element.validate(); 267 } 268 } 269 } 270 271 public void changePropertyByName(String name, Object value) { 272 if (name == null) return; 273 name = name.intern(); 274 if (name == "clusterStats") 275 addClusterStats((ClusterStats)value); 276 else if (name == "clusterStats[]") 277 setClusterStats((ClusterStats[]) value); 278 else 279 throw new IllegalArgumentException (name+" is not a valid property name for LoadBalancerStats"); 280 } 281 282 public Object fetchPropertyByName(String name) { 283 if (name == "clusterStats[]") 284 return getClusterStats(); 285 throw new IllegalArgumentException (name+" is not a valid property name for LoadBalancerStats"); 286 } 287 288 public com.sun.enterprise.admin.monitor.stats.lb.CommonBean[] childBeans(boolean recursive) { 290 java.util.List children = new java.util.LinkedList (); 291 childBeans(recursive, children); 292 com.sun.enterprise.admin.monitor.stats.lb.CommonBean[] result = new com.sun.enterprise.admin.monitor.stats.lb.CommonBean[children.size()]; 293 return (com.sun.enterprise.admin.monitor.stats.lb.CommonBean[]) children.toArray(result); 294 } 295 296 public void childBeans(boolean recursive, java.util.List beans) { 298 for (java.util.Iterator it = _ClusterStats.iterator(); 299 it.hasNext(); ) { 300 com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element = (com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it.next(); 301 if (element != null) { 302 if (recursive) { 303 element.childBeans(true, beans); 304 } 305 beans.add(element); 306 } 307 } 308 } 309 310 public boolean equals(Object o) { 311 if (o == this) 312 return true; 313 if (!(o instanceof com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats)) 314 return false; 315 com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats inst = (com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats) o; 316 if (sizeClusterStats() != inst.sizeClusterStats()) 317 return false; 318 for (java.util.Iterator it = _ClusterStats.iterator(), it2 = inst._ClusterStats.iterator(); 320 it.hasNext() && it2.hasNext(); ) { 321 com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element = (com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it.next(); 322 com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element2 = (com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it2.next(); 323 if (!(element == null ? element2 == null : element.equals(element2))) 324 return false; 325 } 326 return true; 327 } 328 329 public int hashCode() { 330 int result = 17; 331 result = 37*result + (_ClusterStats == null ? 0 : _ClusterStats.hashCode()); 332 return result; 333 } 334 335 public String toString() { 336 java.io.StringWriter sw = new java.io.StringWriter (); 337 try { 338 writeNode(sw, "LoadBalancerStats", ""); 339 } catch (java.io.IOException e) { 340 } 343 return sw.toString(); 344 } 345 } 346 347 348 417 | Popular Tags |