KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > LoadBalancers


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24 /**
25  * This generated bean class LoadBalancers matches the DTD element load-balancers
26  *
27  */

28
29 package com.sun.enterprise.config.serverbeans;
30
31 import org.w3c.dom.*;
32 import org.netbeans.modules.schema2beans.*;
33 import java.beans.*;
34 import java.util.*;
35 import java.io.Serializable JavaDoc;
36 import com.sun.enterprise.config.ConfigBean;
37 import com.sun.enterprise.config.ConfigException;
38 import com.sun.enterprise.config.StaleWriteConfigException;
39 import com.sun.enterprise.util.i18n.StringManager;
40
41 // BEGIN_NOI18N
42

43 public class LoadBalancers extends ConfigBean implements Serializable JavaDoc
44 {
45
46     static Vector comparators = new Vector();
47     private static final org.netbeans.modules.schema2beans.Version runtimeVersion = new org.netbeans.modules.schema2beans.Version(4, 2, 0);
48
49     static public final String JavaDoc LOAD_BALANCER = "LoadBalancer";
50
51     public LoadBalancers() {
52         this(Common.USE_DEFAULT_VALUES);
53     }
54
55     public LoadBalancers(int options)
56     {
57         super(comparators, runtimeVersion);
58         // Properties (see root bean comments for the bean graph)
59
initPropertyTables(1);
60         this.createProperty("load-balancer", LOAD_BALANCER,
61             Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY,
62             LoadBalancer.class);
63         this.createAttribute(LOAD_BALANCER, "name", "Name",
64                         AttrProp.CDATA | AttrProp.REQUIRED,
65                         null, null);
66         this.createAttribute(LOAD_BALANCER, "lb-config-name", "LbConfigName",
67                         AttrProp.CDATA | AttrProp.REQUIRED,
68                         null, null);
69         this.createAttribute(LOAD_BALANCER, "auto-apply-enabled", "AutoApplyEnabled",
70                         AttrProp.CDATA,
71                         null, "false");
72         this.initialize(options);
73     }
74
75     // Setting the default values of the properties
76
void initialize(int options) {
77
78     }
79
80     // This attribute is an array, possibly empty
81
public void setLoadBalancer(int index, LoadBalancer value) {
82         this.setValue(LOAD_BALANCER, index, value);
83     }
84
85     // Get Method
86
public LoadBalancer getLoadBalancer(int index) {
87         return (LoadBalancer)this.getValue(LOAD_BALANCER, index);
88     }
89
90     // This attribute is an array, possibly empty
91
public void setLoadBalancer(LoadBalancer[] value) {
92         this.setValue(LOAD_BALANCER, value);
93     }
94
95     // Getter Method
96
public LoadBalancer[] getLoadBalancer() {
97         return (LoadBalancer[])this.getValues(LOAD_BALANCER);
98     }
99
100     // Return the number of properties
101
public int sizeLoadBalancer() {
102         return this.size(LOAD_BALANCER);
103     }
104
105     // Add a new element returning its index in the list
106
public int addLoadBalancer(LoadBalancer value)
107             throws ConfigException{
108         return addLoadBalancer(value, true);
109     }
110
111     // Add a new element returning its index in the list with a boolean flag
112
public int addLoadBalancer(LoadBalancer value, boolean overwrite)
113             throws ConfigException{
114         LoadBalancer old = getLoadBalancerByName(value.getName());
115         if(old != null) {
116             throw new ConfigException(StringManager.getManager(LoadBalancers.class).getString("cannotAddDuplicate", "LoadBalancer"));
117         }
118         return this.addValue(LOAD_BALANCER, value, overwrite);
119     }
120
121     //
122
// Remove an element using its reference
123
// Returns the index the element had in the list
124
//
125
public int removeLoadBalancer(LoadBalancer value){
126         return this.removeValue(LOAD_BALANCER, value);
127     }
128
129     //
130
// Remove an element using its reference
131
// Returns the index the element had in the list
132
// with boolean overwrite
133
//
134
public int removeLoadBalancer(LoadBalancer value, boolean overwrite)
135             throws StaleWriteConfigException{
136         return this.removeValue(LOAD_BALANCER, value, overwrite);
137     }
138
139     public LoadBalancer getLoadBalancerByName(String JavaDoc id) {
140      if (null != id) { id = id.trim(); }
141     LoadBalancer[] o = getLoadBalancer();
142      if (o == null) return null;
143
144      for (int i=0; i < o.length; i++) {
145          if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) {
146              return o[i];
147          }
148      }
149
150         return null;
151         
152     }
153     /**
154      * Create a new bean using it's default constructor.
155      * This does not add it to any bean graph.
156      */

157     public LoadBalancer newLoadBalancer() {
158         return new LoadBalancer();
159     }
160
161     /**
162     * get the xpath representation for this element
163     * returns something like abc[@name='value'] or abc
164     * depending on the type of the bean
165     */

166     protected String JavaDoc getRelativeXPath() {
167         String JavaDoc ret = null;
168         ret = "load-balancers";
169         return (null != ret ? ret.trim() : null);
170     }
171
172     /*
173     * generic method to get default value from dtd
174     */

175     public static String JavaDoc getDefaultAttributeValue(String JavaDoc attr) {
176         if(attr == null) return null;
177         attr = attr.trim();
178     return null;
179     }
180     //
181
public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
182         comparators.add(c);
183     }
184
185     //
186
public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
187         comparators.remove(c);
188     }
189     public void validate() throws org.netbeans.modules.schema2beans.ValidateException {
190     }
191
192     // Dump the content of this bean returning it as a String
193
public void dump(StringBuffer JavaDoc str, String JavaDoc indent){
194         String JavaDoc s;
195         Object JavaDoc o;
196         org.netbeans.modules.schema2beans.BaseBean n;
197         str.append(indent);
198         str.append("LoadBalancer["+this.sizeLoadBalancer()+"]"); // NOI18N
199
for(int i=0; i<this.sizeLoadBalancer(); i++)
200         {
201             str.append(indent+"\t");
202             str.append("#"+i+":");
203             n = (org.netbeans.modules.schema2beans.BaseBean) this.getLoadBalancer(i);
204             if (n != null)
205                 n.dump(str, indent + "\t"); // NOI18N
206
else
207                 str.append(indent+"\tnull"); // NOI18N
208
this.dumpAttributes(LOAD_BALANCER, i, str, indent);
209         }
210
211     }
212     public String JavaDoc dumpBeanNode(){
213         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
214         str.append("LoadBalancers\n"); // NOI18N
215
this.dump(str, "\n "); // NOI18N
216
return str.toString();
217     }}
218
219 // END_NOI18N
220

221
Popular Tags