KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > monitor > data > Headers


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  * This generated bean class Headers matches the DTD element Headers
22  *
23  * Generated on Thu Jan 11 18:34:12 PST 2001
24  */

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 JavaDoc PARAM = "Param"; // NOI18N
37

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     // Properties (see root bean comments for the bean graph)
45
this.createProperty("Param", PARAM, // NOI18N
46
Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY,
47                 Param.class);
48     this.createAttribute(PARAM, "name", "Name", // NOI18N
49
AttrProp.CDATA | AttrProp.REQUIRED,
50                  null, null);
51     this.createAttribute(PARAM, "value", "Value", // NOI18N
52
AttrProp.CDATA | AttrProp.IMPLIED,
53                  null, null);
54     this.initialize(options);
55     }
56
57     // Setting the default values of the properties
58
void initialize(int options) {
59
60     }
61
62     // This attribute is an array, possibly empty
63
public void setParam(int index, Param value) {
64     this.setValue(PARAM, index, value);
65     }
66
67     //
68
public Param getParam(int index) {
69     return (Param)this.getValue(PARAM, index);
70     }
71
72     // This attribute is an array, possibly empty
73
public void setParam(Param[] value) {
74     this.setValue(PARAM, value);
75     }
76
77     //
78
public Param[] getParam() {
79     return (Param[])this.getValues(PARAM);
80     }
81
82
83     //
84
public String JavaDoc getHeader(String JavaDoc 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     //
94
public boolean containsHeader(String JavaDoc 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     //
104
public Enumeration getHeaders(String JavaDoc 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     // Return the number of properties
115
public int sizeParam() {
116     return this.size(PARAM);
117     }
118
119     // Add a new element returning its index in the list
120
public int addParam(Param value) {
121     return this.addValue(PARAM, value);
122     }
123
124     /**
125      * Contingently adds a new header of name and value.
126      * We check if a header of the name already exists. If it doesn't,
127      * we return 0 and add a new header to the list. If one does
128      * exist, we check if the value is already in the list. If it
129      * isn't, we add it at the end and return 1. If it's already there
130      * we do nothing and return -1.
131      *
132      */

133     public int addParam(String JavaDoc name, String JavaDoc 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 JavaDoc oldValue = params[index].getValue();
149         StringTokenizer st = new StringTokenizer(oldValue, " ,");
150         while(st.hasMoreTokens()) {
151         String JavaDoc val = st.nextToken();
152         // This parameter was already added, return -1
153
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     //
163
// Remove an element using its reference
164
// Returns the index the element had in the list
165
//
166
public int removeParam(Param value) {
167     return this.removeValue(PARAM, value);
168     }
169
170     // This method verifies that the mandatory properties are set
171
public boolean verify() {
172     return true;
173     }
174
175     //
176
static public void addComparator(BeanComparator c) {
177     Headers.comparators.add(c);
178     }
179
180     //
181
static public void removeComparator(BeanComparator c) {
182     Headers.comparators.remove(c);
183     }
184     //
185
public void addPropertyChangeListener(PropertyChangeListener l) {
186     BeanProp p = this.beanProp();
187     if (p != null)
188         p.addPCListener(l);
189     }
190
191     //
192
public void removePropertyChangeListener(PropertyChangeListener l) {
193     BeanProp p = this.beanProp();
194     if (p != null)
195         p.removePCListener(l);
196     }
197
198     //
199
public void addPropertyChangeListener(String JavaDoc n,
200                       PropertyChangeListener l) {
201     BeanProp p = this.beanProp(n);
202     if (p != null)
203         p.addPCListener(l);
204     }
205
206     //
207
public void removePropertyChangeListener(String JavaDoc n,
208                          PropertyChangeListener l) {
209     BeanProp p = this.beanProp(n);
210     if (p != null)
211         p.removePCListener(l);
212     }
213
214     // Dump the content of this bean returning it as a String
215
public void dump(StringBuffer JavaDoc str, String JavaDoc indent) {
216     String JavaDoc s;
217     BaseBean n;
218     str.append(indent);
219     str.append("Param["+this.sizeParam()+"]"); // NOI18N
220
for(int i=0; i<this.sizeParam(); i++)
221         {
222         str.append(indent+"\t"); // NOI18N
223
str.append("#"+i+":"); // NOI18N
224
n = this.getParam(i);
225         if (n != null)
226             n.dump(str, indent + "\t"); // NOI18N
227
else
228             str.append(indent+"\tnull"); // NOI18N
229
this.dumpAttributes(PARAM, i, str, indent);
230         }
231
232     }
233
234     public String JavaDoc dumpBeanNode() {
235     StringBuffer JavaDoc str = new StringBuffer JavaDoc();
236     str.append("Headers\n"); // NOI18N
237
this.dump(str, "\n "); // NOI18N
238
return str.toString();
239     }
240
241     public String JavaDoc toString() {
242     StringBuffer JavaDoc buf = new StringBuffer JavaDoc("Request Headers\n"); // NOI18N
243

244     Param[] params = getParam();
245     buf.append(String.valueOf(params.length));
246     buf.append(" header lines\n"); // NOI18N
247
for(int i=0; i<params.length; ++i) {
248         buf.append(String.valueOf(i));
249         buf.append(". Attribute: "); // NOI18N
250
buf.append(params[i].getAttributeValue("name")); // NOI18N
251
buf.append(", Value: "); // NOI18N
252
buf.append(params[i].getAttributeValue("value")); // NOI18N
253
buf.append("\n"); // NOI18N
254
}
255     return buf.toString();
256     }
257 }
258
Popular Tags