1 23 24 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 ; 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 43 public class ManagementRules extends ConfigBean implements Serializable 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 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 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 void initialize(int options) { 74 75 } 76 77 public void setManagementRule(int index, ManagementRule value) { 79 this.setValue(MANAGEMENT_RULE, index, value); 80 } 81 82 public ManagementRule getManagementRule(int index) { 84 return (ManagementRule)this.getValue(MANAGEMENT_RULE, index); 85 } 86 87 public void setManagementRule(ManagementRule[] value) { 89 this.setValue(MANAGEMENT_RULE, value); 90 } 91 92 public ManagementRule[] getManagementRule() { 94 return (ManagementRule[])this.getValues(MANAGEMENT_RULE); 95 } 96 97 public int sizeManagementRule() { 99 return this.size(MANAGEMENT_RULE); 100 } 101 102 public int addManagementRule(ManagementRule value) 104 throws ConfigException{ 105 return addManagementRule(value, true); 106 } 107 108 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 public int removeManagementRule(ManagementRule value){ 123 return this.removeValue(MANAGEMENT_RULE, value); 124 } 125 126 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 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 154 public boolean isEnabled() { 155 return toBoolean(getAttributeValue(ServerTags.ENABLED)); 156 } 157 162 public void setEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException { 163 setAttributeValue(ServerTags.ENABLED, ""+(v==true), overwrite); 164 } 165 169 public void setEnabled(boolean v) { 170 setAttributeValue(ServerTags.ENABLED, ""+(v==true)); 171 } 172 175 public static String getDefaultEnabled() { 176 return "true".trim(); 177 } 178 182 public ManagementRule newManagementRule() { 183 return new ManagementRule(); 184 } 185 186 191 protected String getRelativeXPath() { 192 String ret = null; 193 ret = "management-rules"; 194 return (null != ret ? ret.trim() : null); 195 } 196 197 200 public static String getDefaultAttributeValue(String 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 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 208 comparators.add(c); 209 } 210 211 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 public void dump(StringBuffer str, String indent){ 220 String s; 221 Object o; 222 org.netbeans.modules.schema2beans.BaseBean n; 223 str.append(indent); 224 str.append("ManagementRule["+this.sizeManagementRule()+"]"); 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"); else 233 str.append(indent+"\tnull"); this.dumpAttributes(MANAGEMENT_RULE, i, str, indent); 235 } 236 237 } 238 public String dumpBeanNode(){ 239 StringBuffer str = new StringBuffer (); 240 str.append("ManagementRules\n"); this.dump(str, "\n "); return str.toString(); 243 }} 244 245 247 | Popular Tags |