KickJava   Java API By Example, From Geeks To Geeks.

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


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 Clusters matches the DTD element clusters
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 Clusters 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 CLUSTER = "Cluster";
50
51     public Clusters() {
52         this(Common.USE_DEFAULT_VALUES);
53     }
54
55     public Clusters(int options)
56     {
57         super(comparators, runtimeVersion);
58         // Properties (see root bean comments for the bean graph)
59
initPropertyTables(1);
60         this.createProperty("cluster", CLUSTER,
61             Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY,
62             Cluster.class);
63         this.createAttribute(CLUSTER, "name", "Name",
64                         AttrProp.CDATA | AttrProp.REQUIRED,
65                         null, null);
66         this.createAttribute(CLUSTER, "config-ref", "ConfigRef",
67                         AttrProp.CDATA | AttrProp.REQUIRED,
68                         null, null);
69         this.createAttribute(CLUSTER, "heartbeat-port", "HeartbeatPort",
70                         AttrProp.CDATA | AttrProp.REQUIRED,
71                         null, null);
72         this.createAttribute(CLUSTER, "heartbeat-address", "HeartbeatAddress",
73                         AttrProp.CDATA | AttrProp.REQUIRED,
74                         null, null);
75         this.createAttribute(CLUSTER, "heartbeat-enabled", "HeartbeatEnabled",
76                         AttrProp.CDATA,
77                         null, "true");
78         this.initialize(options);
79     }
80
81     // Setting the default values of the properties
82
void initialize(int options) {
83
84     }
85
86     // This attribute is an array, possibly empty
87
public void setCluster(int index, Cluster value) {
88         this.setValue(CLUSTER, index, value);
89     }
90
91     // Get Method
92
public Cluster getCluster(int index) {
93         return (Cluster)this.getValue(CLUSTER, index);
94     }
95
96     // This attribute is an array, possibly empty
97
public void setCluster(Cluster[] value) {
98         this.setValue(CLUSTER, value);
99     }
100
101     // Getter Method
102
public Cluster[] getCluster() {
103         return (Cluster[])this.getValues(CLUSTER);
104     }
105
106     // Return the number of properties
107
public int sizeCluster() {
108         return this.size(CLUSTER);
109     }
110
111     // Add a new element returning its index in the list
112
public int addCluster(Cluster value)
113             throws ConfigException{
114         return addCluster(value, true);
115     }
116
117     // Add a new element returning its index in the list with a boolean flag
118
public int addCluster(Cluster value, boolean overwrite)
119             throws ConfigException{
120         Cluster old = getClusterByName(value.getName());
121         if(old != null) {
122             throw new ConfigException(StringManager.getManager(Clusters.class).getString("cannotAddDuplicate", "Cluster"));
123         }
124         return this.addValue(CLUSTER, value, overwrite);
125     }
126
127     //
128
// Remove an element using its reference
129
// Returns the index the element had in the list
130
//
131
public int removeCluster(Cluster value){
132         return this.removeValue(CLUSTER, value);
133     }
134
135     //
136
// Remove an element using its reference
137
// Returns the index the element had in the list
138
// with boolean overwrite
139
//
140
public int removeCluster(Cluster value, boolean overwrite)
141             throws StaleWriteConfigException{
142         return this.removeValue(CLUSTER, value, overwrite);
143     }
144
145     public Cluster getClusterByName(String JavaDoc id) {
146      if (null != id) { id = id.trim(); }
147     Cluster[] o = getCluster();
148      if (o == null) return null;
149
150      for (int i=0; i < o.length; i++) {
151          if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) {
152              return o[i];
153          }
154      }
155
156         return null;
157         
158     }
159     /**
160      * Create a new bean using it's default constructor.
161      * This does not add it to any bean graph.
162      */

163     public Cluster newCluster() {
164         return new Cluster();
165     }
166
167     /**
168     * get the xpath representation for this element
169     * returns something like abc[@name='value'] or abc
170     * depending on the type of the bean
171     */

172     protected String JavaDoc getRelativeXPath() {
173         String JavaDoc ret = null;
174         ret = "clusters";
175         return (null != ret ? ret.trim() : null);
176     }
177
178     /*
179     * generic method to get default value from dtd
180     */

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

227
Popular Tags