1 19 20 25 26 package org.netbeans.modules.web.monitor.data; 27 import org.w3c.dom.*; 28 import org.netbeans.modules.schema2beans.*; 29 import java.beans.*; 30 import java.util.*; 31 32 public class Headers extends BaseBean { 33 34 static Vector comparators = new Vector(); 35 36 static public final String PARAM = "Param"; 38 public Headers() { 39 this(Common.USE_DEFAULT_VALUES); 40 } 41 42 public Headers(int options) { 43 super(Headers.comparators, new org.netbeans.modules.schema2beans.Version(1, 0, 6)); 44 this.createProperty("Param", PARAM, Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 47 Param.class); 48 this.createAttribute(PARAM, "name", "Name", AttrProp.CDATA | AttrProp.REQUIRED, 50 null, null); 51 this.createAttribute(PARAM, "value", "Value", AttrProp.CDATA | AttrProp.IMPLIED, 53 null, null); 54 this.initialize(options); 55 } 56 57 void initialize(int options) { 59 60 } 61 62 public void setParam(int index, Param value) { 64 this.setValue(PARAM, index, value); 65 } 66 67 public Param getParam(int index) { 69 return (Param)this.getValue(PARAM, index); 70 } 71 72 public void setParam(Param[] value) { 74 this.setValue(PARAM, value); 75 } 76 77 public Param[] getParam() { 79 return (Param[])this.getValues(PARAM); 80 } 81 82 83 public String getHeader(String name) { 85 int len = this.size(PARAM); 86 for(int i=0; i<len; ++i) { 87 if(getParam(i).getName().equalsIgnoreCase(name)) 88 return getParam(i).getValue(); 89 } 90 return ""; 91 } 92 93 public boolean containsHeader(String name) { 95 int len = this.size(PARAM); 96 for(int i=0; i<len; ++i) { 97 if(getParam(i).getName().equalsIgnoreCase(name)) 98 return true; 99 } 100 return false; 101 } 102 103 public Enumeration getHeaders(String name) { 105 int len = this.size(PARAM); 106 Vector v = new Vector(); 107 for(int i=0; i<len; ++i) { 108 if(getParam(i).getName().equalsIgnoreCase(name)) 109 v.add(getParam(i).getValue()); 110 } 111 return v.elements(); 112 } 113 114 public int sizeParam() { 116 return this.size(PARAM); 117 } 118 119 public int addParam(Param value) { 121 return this.addValue(PARAM, value); 122 } 123 124 133 public int addParam(String name, String value) { 134 Param[] params = getParam(); 135 int len = params.length; 136 int index = -1; 137 for(int i=0; i<len; ++i) { 138 if(name.equals(params[i].getName())) { 139 index = i; 140 break; 141 } 142 } 143 if(index == -1) { 144 addParam(new Param(name, value)); 145 return 0; 146 } 147 else { 148 String oldValue = params[index].getValue(); 149 StringTokenizer st = new StringTokenizer(oldValue, " ,"); 150 while(st.hasMoreTokens()) { 151 String val = st.nextToken(); 152 if(value.equals(val)) return -1; 154 } 155 Param p = new Param(name, oldValue.concat(", ").concat(value)); 156 setParam(index, p); 157 return 1; 158 } 159 } 160 161 162 public int removeParam(Param value) { 167 return this.removeValue(PARAM, value); 168 } 169 170 public boolean verify() { 172 return true; 173 } 174 175 static public void addComparator(BeanComparator c) { 177 Headers.comparators.add(c); 178 } 179 180 static public void removeComparator(BeanComparator c) { 182 Headers.comparators.remove(c); 183 } 184 public void addPropertyChangeListener(PropertyChangeListener l) { 186 BeanProp p = this.beanProp(); 187 if (p != null) 188 p.addPCListener(l); 189 } 190 191 public void removePropertyChangeListener(PropertyChangeListener l) { 193 BeanProp p = this.beanProp(); 194 if (p != null) 195 p.removePCListener(l); 196 } 197 198 public void addPropertyChangeListener(String n, 200 PropertyChangeListener l) { 201 BeanProp p = this.beanProp(n); 202 if (p != null) 203 p.addPCListener(l); 204 } 205 206 public void removePropertyChangeListener(String n, 208 PropertyChangeListener l) { 209 BeanProp p = this.beanProp(n); 210 if (p != null) 211 p.removePCListener(l); 212 } 213 214 public void dump(StringBuffer str, String indent) { 216 String s; 217 BaseBean n; 218 str.append(indent); 219 str.append("Param["+this.sizeParam()+"]"); for(int i=0; i<this.sizeParam(); i++) 221 { 222 str.append(indent+"\t"); str.append("#"+i+":"); n = this.getParam(i); 225 if (n != null) 226 n.dump(str, indent + "\t"); else 228 str.append(indent+"\tnull"); this.dumpAttributes(PARAM, i, str, indent); 230 } 231 232 } 233 234 public String dumpBeanNode() { 235 StringBuffer str = new StringBuffer (); 236 str.append("Headers\n"); this.dump(str, "\n "); return str.toString(); 239 } 240 241 public String toString() { 242 StringBuffer buf = new StringBuffer ("Request Headers\n"); 244 Param[] params = getParam(); 245 buf.append(String.valueOf(params.length)); 246 buf.append(" header lines\n"); for(int i=0; i<params.length; ++i) { 248 buf.append(String.valueOf(i)); 249 buf.append(". Attribute: "); buf.append(params[i].getAttributeValue("name")); buf.append(", Value: "); buf.append(params[i].getAttributeValue("value")); buf.append("\n"); } 255 return buf.toString(); 256 } 257 } 258 | Popular Tags |