KickJava   Java API By Example, From Geeks To Geeks.

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


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

154     public boolean isEnabled() {
155         return toBoolean(getAttributeValue(ServerTags.ENABLED));
156     }
157     /**
158     * Modify the Enabled of the Element management-rules
159     * @param v the new value
160     * @throws StaleWriteConfigException if overwrite is false and file changed on disk
161     */

162     public void setEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException {
163         setAttributeValue(ServerTags.ENABLED, ""+(v==true), overwrite);
164     }
165     /**
166     * Modify the Enabled of the Element management-rules
167     * @param v the new value
168     */

169     public void setEnabled(boolean v) {
170         setAttributeValue(ServerTags.ENABLED, ""+(v==true));
171     }
172     /**
173     * Get the default value of Enabled from dtd
174     */

175     public static String JavaDoc getDefaultEnabled() {
176         return "true".trim();
177     }
178     /**
179      * Create a new bean using it's default constructor.
180      * This does not add it to any bean graph.
181      */

182     public ManagementRule newManagementRule() {
183         return new ManagementRule();
184     }
185
186     /**
187     * get the xpath representation for this element
188     * returns something like abc[@name='value'] or abc
189     * depending on the type of the bean
190     */

191     protected String JavaDoc getRelativeXPath() {
192         String JavaDoc ret = null;
193         ret = "management-rules";
194         return (null != ret ? ret.trim() : null);
195     }
196
197     /*
198     * generic method to get default value from dtd
199     */

200     public static String JavaDoc getDefaultAttributeValue(String JavaDoc attr) {
201         if(attr == null) return null;
202         attr = attr.trim();
203         if(attr.equals(ServerTags.ENABLED)) return "true".trim();
204     return null;
205     }
206     //
207
public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
208         comparators.add(c);
209     }
210
211     //
212
public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
213         comparators.remove(c);
214     }
215     public void validate() throws org.netbeans.modules.schema2beans.ValidateException {
216     }
217
218     // Dump the content of this bean returning it as a String
219
public void dump(StringBuffer JavaDoc str, String JavaDoc indent){
220         String JavaDoc s;
221         Object JavaDoc o;
222         org.netbeans.modules.schema2beans.BaseBean n;
223         str.append(indent);
224         str.append("ManagementRule["+this.sizeManagementRule()+"]"); // NOI18N
225
for(int i=0; i<this.sizeManagementRule(); i++)
226         {
227             str.append(indent+"\t");
228             str.append("#"+i+":");
229             n = (org.netbeans.modules.schema2beans.BaseBean) this.getManagementRule(i);
230             if (n != null)
231                 n.dump(str, indent + "\t"); // NOI18N
232
else
233                 str.append(indent+"\tnull"); // NOI18N
234
this.dumpAttributes(MANAGEMENT_RULE, i, str, indent);
235         }
236
237     }
238     public String JavaDoc dumpBeanNode(){
239         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
240         str.append("ManagementRules\n"); // NOI18N
241
this.dump(str, "\n "); // NOI18N
242
return str.toString();
243     }}
244
245 // END_NOI18N
246

247
Popular Tags