KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

224
Popular Tags