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 ExternalJndiResource 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 DESCRIPTION = "Description"; 50 static public final String ELEMENT_PROPERTY = "ElementProperty"; 51 52 public ExternalJndiResource() { 53 this(Common.USE_DEFAULT_VALUES); 54 } 55 56 public ExternalJndiResource(int options) 57 { 58 super(comparators, runtimeVersion); 59 initPropertyTables(2); 61 this.createProperty("description", DESCRIPTION, 62 Common.TYPE_0_1 | Common.TYPE_STRING | Common.TYPE_KEY, 63 String .class); 64 this.createProperty("property", ELEMENT_PROPERTY, 65 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 66 ElementProperty.class); 67 this.createAttribute(ELEMENT_PROPERTY, "name", "Name", 68 AttrProp.CDATA | AttrProp.REQUIRED, 69 null, null); 70 this.createAttribute(ELEMENT_PROPERTY, "value", "Value", 71 AttrProp.CDATA | AttrProp.REQUIRED, 72 null, null); 73 this.initialize(options); 74 } 75 76 void initialize(int options) { 78 79 } 80 81 84 public String getDescription() { 85 return (String ) getValue(ServerTags.DESCRIPTION); 86 } 87 91 public void setDescription(String v){ 92 setValue(ServerTags.DESCRIPTION, (null != v ? v.trim() : null)); 93 } 94 public void setElementProperty(int index, ElementProperty value) { 96 this.setValue(ELEMENT_PROPERTY, index, value); 97 } 98 99 public ElementProperty getElementProperty(int index) { 101 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 102 } 103 104 public void setElementProperty(ElementProperty[] value) { 106 this.setValue(ELEMENT_PROPERTY, value); 107 } 108 109 public ElementProperty[] getElementProperty() { 111 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 112 } 113 114 public int sizeElementProperty() { 116 return this.size(ELEMENT_PROPERTY); 117 } 118 119 public int addElementProperty(ElementProperty value) 121 throws ConfigException{ 122 return addElementProperty(value, true); 123 } 124 125 public int addElementProperty(ElementProperty value, boolean overwrite) 127 throws ConfigException{ 128 ElementProperty old = getElementPropertyByName(value.getName()); 129 if(old != null) { 130 throw new ConfigException(StringManager.getManager(ExternalJndiResource.class).getString("cannotAddDuplicate", "ElementProperty")); 131 } 132 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 133 } 134 135 public int removeElementProperty(ElementProperty value){ 140 return this.removeValue(ELEMENT_PROPERTY, value); 141 } 142 143 public int removeElementProperty(ElementProperty value, boolean overwrite) 149 throws StaleWriteConfigException{ 150 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 151 } 152 153 public ElementProperty getElementPropertyByName(String id) { 154 if (null != id) { id = id.trim(); } 155 ElementProperty[] o = getElementProperty(); 156 if (o == null) return null; 157 158 for (int i=0; i < o.length; i++) { 159 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 160 return o[i]; 161 } 162 } 163 164 return null; 165 166 } 167 171 public String getJndiName() { 172 return getAttributeValue(ServerTags.JNDI_NAME); 173 } 174 179 public void setJndiName(String v, boolean overwrite) throws StaleWriteConfigException { 180 setAttributeValue(ServerTags.JNDI_NAME, v, overwrite); 181 } 182 186 public void setJndiName(String v) { 187 setAttributeValue(ServerTags.JNDI_NAME, v); 188 } 189 193 public String getJndiLookupName() { 194 return getAttributeValue(ServerTags.JNDI_LOOKUP_NAME); 195 } 196 201 public void setJndiLookupName(String v, boolean overwrite) throws StaleWriteConfigException { 202 setAttributeValue(ServerTags.JNDI_LOOKUP_NAME, v, overwrite); 203 } 204 208 public void setJndiLookupName(String v) { 209 setAttributeValue(ServerTags.JNDI_LOOKUP_NAME, v); 210 } 211 215 public String getResType() { 216 return getAttributeValue(ServerTags.RES_TYPE); 217 } 218 223 public void setResType(String v, boolean overwrite) throws StaleWriteConfigException { 224 setAttributeValue(ServerTags.RES_TYPE, v, overwrite); 225 } 226 230 public void setResType(String v) { 231 setAttributeValue(ServerTags.RES_TYPE, v); 232 } 233 237 public String getFactoryClass() { 238 return getAttributeValue(ServerTags.FACTORY_CLASS); 239 } 240 245 public void setFactoryClass(String v, boolean overwrite) throws StaleWriteConfigException { 246 setAttributeValue(ServerTags.FACTORY_CLASS, v, overwrite); 247 } 248 252 public void setFactoryClass(String v) { 253 setAttributeValue(ServerTags.FACTORY_CLASS, v); 254 } 255 259 public String getObjectType() { 260 return getAttributeValue(ServerTags.OBJECT_TYPE); 261 } 262 267 public void setObjectType(String v, boolean overwrite) throws StaleWriteConfigException { 268 setAttributeValue(ServerTags.OBJECT_TYPE, v, overwrite); 269 } 270 274 public void setObjectType(String v) { 275 setAttributeValue(ServerTags.OBJECT_TYPE, v); 276 } 277 280 public static String getDefaultObjectType() { 281 return "user".trim(); 282 } 283 287 public boolean isEnabled() { 288 return toBoolean(getAttributeValue(ServerTags.ENABLED)); 289 } 290 295 public void setEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException { 296 setAttributeValue(ServerTags.ENABLED, ""+(v==true), overwrite); 297 } 298 302 public void setEnabled(boolean v) { 303 setAttributeValue(ServerTags.ENABLED, ""+(v==true)); 304 } 305 308 public static String getDefaultEnabled() { 309 return "true".trim(); 310 } 311 315 public ElementProperty newElementProperty() { 316 return new ElementProperty(); 317 } 318 319 324 protected String getRelativeXPath() { 325 String ret = null; 326 ret = "external-jndi-resource" + (canHaveSiblings() ? "[@jndi-name='" + getAttributeValue("jndi-name") +"']" : "") ; 327 return (null != ret ? ret.trim() : null); 328 } 329 330 333 public static String getDefaultAttributeValue(String attr) { 334 if(attr == null) return null; 335 attr = attr.trim(); 336 if(attr.equals(ServerTags.OBJECT_TYPE)) return "user".trim(); 337 if(attr.equals(ServerTags.ENABLED)) return "true".trim(); 338 return null; 339 } 340 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 342 comparators.add(c); 343 } 344 345 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 347 comparators.remove(c); 348 } 349 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 350 } 351 352 public void dump(StringBuffer str, String indent){ 354 String s; 355 Object o; 356 org.netbeans.modules.schema2beans.BaseBean n; 357 str.append(indent); 358 str.append("Description"); str.append(indent+"\t"); str.append("<"); o = this.getDescription(); 362 str.append((o==null?"null":o.toString().trim())); str.append(">\n"); this.dumpAttributes(DESCRIPTION, 0, str, indent); 365 366 str.append(indent); 367 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 369 { 370 str.append(indent+"\t"); 371 str.append("#"+i+":"); 372 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 373 if (n != null) 374 n.dump(str, indent + "\t"); else 376 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 378 } 379 380 } 381 public String dumpBeanNode(){ 382 StringBuffer str = new StringBuffer (); 383 str.append("ExternalJndiResource\n"); this.dump(str, "\n "); return str.toString(); 386 }} 387 388 390 | Popular Tags |