1 23 24 package com.sun.enterprise.admin.server.core.mbean.config; 25 26 import java.text.CharacterIterator ; 27 import java.text.StringCharacterIterator ; 28 import java.util.Hashtable ; 29 import java.lang.reflect.Method ; 30 import java.util.Iterator ; 31 import java.util.Enumeration ; 32 import java.util.ArrayList ; 33 import java.util.logging.Level ; 34 import java.util.logging.Logger ; 35 36 import javax.management.*; 38 39 import com.sun.enterprise.instance.InstanceEnvironment; 41 import com.sun.enterprise.config.ConfigException; 42 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 44 import com.sun.enterprise.config.serverbeans.ServerTags; 45 import com.sun.enterprise.config.ConfigContext; 46 import com.sun.enterprise.config.ConfigFactory; 47 import com.sun.enterprise.config.ConfigBean; 48 import com.sun.enterprise.config.ConfigBeansFactory; 49 import com.sun.enterprise.config.serverbeans.ElementProperty; 50 51 import com.sun.enterprise.admin.AdminContext; 53 import com.sun.enterprise.admin.server.core.mbean.config.naming.ConfigMBeanNamingInfo; 54 55 import com.sun.enterprise.admin.server.core.mbean.meta.MBeanEasyConfig; 56 import com.sun.enterprise.admin.common.constant.AdminConstants; 57 import com.sun.enterprise.admin.common.constant.ConfigAttributeName; 58 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 59 61 import com.sun.enterprise.util.i18n.StringManager; 63 64 65 69 public class ConfigMBeanBase extends AdminBase { 71 public static final Logger sLogger = Logger.getLogger(AdminConstants.kLoggerName); 72 private final static String MSG_BASE_GET_ATTRIBUTE = "mbean.config.base_get_attribute"; 73 private final static String MSG_BASE_SET_ATTRIBUTE = "mbean.config.base_set_attribute"; 74 private final static String MSG_BASE_GOT_ATTRIBUTE = "mbean.config.base_got_attribute"; 75 private final static String MSG_BASE_GET_PROPERTY = "mbean.config.base_get_property"; 76 private final static String MSG_BASE_SET_PROPERTY = "mbean.config.base_set_property"; 77 private final static String MSG_BASE_GET_DEF_ATTR_VALUE = "mbean.config.get_def_attr_value"; 78 private final static String MSG_GET_CONFBEANBYXPATH = "mbean.config.get_confbeanbyxpath"; 79 private final static String MSG_LOG_CONF_CTX = "mbean.config.log_config_id"; 80 public static final char ATTRIBUTE_CHAR = '@'; public static final char ALLOWS_EMPTY_CHAR = '@'; public static final String ATTRIBUTE = ""+ATTRIBUTE_CHAR; public static final String E_ATTRIBUTE = "" + ATTRIBUTE_CHAR + ALLOWS_EMPTY_CHAR; public static final String PROPERTY = ServerTags.ELEMENT_PROPERTY+ ServerXPathHelper.XPATH_SEPARATOR+ATTRIBUTE; public static final String E_PROPERTY = ServerTags.ELEMENT_PROPERTY+ ServerXPathHelper.XPATH_SEPARATOR+E_ATTRIBUTE; public static final String ELEMENT_CONTENT = ""; public static final String PSEUDO_ATTR_DESCRIPTION = ServerTags.DESCRIPTION; 88 89 private AdminContext m_AdminContext; 90 private ConfigContext m_configContext; 91 private String m_BasePath; private Hashtable m_Attrs; 93 private MBeanInfo m_MBeanInfo; 94 private String m_ServerInstanceName; 95 private ConfigMBeanNamingInfo m_MBeanNamingInfo; 96 97 private static StringManager localStrings = 99 StringManager.getManager( ConfigMBeanBase.class ); 100 101 102 107 public void initialize(ConfigMBeanNamingInfo namingInfo) throws MBeanConfigException 108 { 109 String instanceName = namingInfo.getServerInstanceName(); 110 ConfigContext configContext; 111 if (m_AdminContext != null) { 112 configContext = m_AdminContext.getAdminConfigContext(); 113 } else { 114 try 115 { 116 InstanceEnvironment instanceEnvironment = new InstanceEnvironment(instanceName); 117 119 String fileUrl = instanceEnvironment.getConfigFilePath(); 120 configContext = ConfigFactory.createConfigContext(fileUrl); 121 } 122 catch(ConfigException e) 123 { 124 String msg = localStrings.getString( "admin.server.core.mbean.config.error_locating_server_node", e.getMessage() ); 126 throw new MBeanConfigException( msg ); 127 } 128 } 129 130 sLogger.log(Level.FINEST, MSG_LOG_CONF_CTX, new Object [] { 131 this.getClass().getName(), new Long (configContext.hashCode())}); 132 m_ServerInstanceName = instanceName; 133 m_configContext = configContext; 134 m_MBeanNamingInfo = namingInfo; 135 m_BasePath = namingInfo.getXPath(); 136 } 137 140 public void initialize(String mbeanType, String [] locations) throws MBeanConfigException 141 { 142 ConfigMBeanNamingInfo namingInfo; 143 try 144 { 145 namingInfo = new ConfigMBeanNamingInfo(mbeanType, locations); 146 } 147 catch (MBeanConfigException mce) 148 { 149 throw mce; 150 } 151 catch (Exception e) 152 { 153 throw new MBeanConfigException(e.getMessage()); 154 } 155 156 initialize(namingInfo); 157 } 158 159 162 public void initialize(String dottedName) throws MBeanConfigException 163 { 164 ConfigMBeanNamingInfo namingInfo; 165 try 166 { 167 namingInfo = new ConfigMBeanNamingInfo(dottedName); 168 } 169 catch (MBeanConfigException mce) 170 { 171 throw mce; 172 } 173 catch (Exception e) 174 { 175 throw new MBeanConfigException(e.getMessage()); 176 } 177 178 initialize(namingInfo); 179 } 180 181 184 public void initialize(ObjectName objectName) throws MBeanConfigException 185 { 186 ConfigMBeanNamingInfo namingInfo; 187 try 188 { 189 namingInfo = new ConfigMBeanNamingInfo(objectName); 190 } 191 catch (MBeanConfigException mce) 192 { 193 throw mce; 194 } 195 catch (Exception e) 196 { 197 throw new MBeanConfigException(e.getMessage()); 198 } 199 200 initialize(namingInfo); 201 } 202 203 204 205 225 public void setDescriptions(String attrsMapList[][], String [] attrDescriptions, String [] operDescriptions) throws MBeanConfigException 226 { 227 m_Attrs = createAttrsDescriptors(attrsMapList); 228 MBeanEasyConfig easyConfig = new MBeanEasyConfig(getClass(), attrDescriptions, operDescriptions, null); 229 m_MBeanInfo = easyConfig.getMBeanInfo(); 230 } 231 232 public void setAdminContext(AdminContext adminContext) { 233 m_AdminContext = adminContext; 234 } 235 236 public AdminContext getAdminContext() { 237 return m_AdminContext; 238 } 239 240 242 public ConfigContext getConfigContext() 243 { 244 return m_configContext; 245 } 246 247 249 public String getServerInstanceName() 250 { 251 return m_ServerInstanceName; 252 } 253 254 256 public ConfigMBeanNamingInfo getConfigMBeanNamingInfo() 257 { 258 return m_MBeanNamingInfo; 259 } 260 261 265 public String getBasePath() 266 { 267 return m_BasePath; 268 } 269 270 274 public ConfigBean getBaseConfigBean() 275 { 276 try 277 { 278 return getConfigBeanByXPath(m_BasePath); 279 } 280 catch (Exception e) 281 { 282 return null; 283 } 284 } 285 286 290 public MBeanInfo getMBeanInfo() 291 { 292 return m_MBeanInfo; 293 } 294 299 public ConfigBean getConfigBean(String externalName) 300 { 301 AttrDescriptor descr = getDescriptor(externalName); 303 try 304 { 305 return descr.getConfigBean(); 306 } 307 catch (Exception e) 308 { 309 return null; 310 } 311 } 312 313 318 public ConfigBean getConfigBeanByXPath(String xPath) throws ConfigException 319 { 320 sLogger.log(Level.FINEST, MSG_GET_CONFBEANBYXPATH, xPath); 321 return ConfigBeansFactory.getConfigBeanByXPath(m_configContext, xPath); 322 } 323 324 331 public Object getAttribute(String externalName) throws MBeanException,AttributeNotFoundException 332 { 333 sLogger.log(Level.FINEST, MSG_BASE_GET_ATTRIBUTE, externalName); 334 MBeanAttributeInfo ai = getAttrInfo(externalName); 335 boolean isProperty = externalName.startsWith(ConfigAttributeName.PROPERTY_NAME_PREFIX); 336 337 338 if(ai==null && !isProperty) 339 { 340 String msg = localStrings.getString( "admin.server.core.mbean.config.attribute_not_defined", externalName ); 341 throw new AttributeNotFoundException( msg ); 342 } 343 if(ai!=null && !ai.isReadable()) 344 { 345 String msg = localStrings.getString( "admin.server.core.mbean.config.attribute_not_readable", externalName ); 346 throw new AttributeNotFoundException( msg ); 347 } 348 349 350 351 try 352 { 353 if(isProperty) 354 { 355 return getPropertyElementValue(externalName.substring(ConfigAttributeName.PROPERTY_NAME_PREFIX.length())); 357 } 358 else 359 { 360 AttrDescriptor descr = getDescriptor(externalName); 361 ConfigBean bean = getConfigBean(externalName); 362 String value = null; 363 if(descr.isElement()) 364 { 365 String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_not_implemented_for_xml" ); 368 throw new MBeanException(new MBeanConfigException( msg )); 369 } 370 else 371 { 372 value = bean.getRawAttributeValue(descr.getAttributeName()); 373 374 } 376 sLogger.log(Level.FINEST, MSG_BASE_GOT_ATTRIBUTE, new Object []{externalName,value, MBeanEasyConfig.convertStringValueToProperType(value, ai.getType())}); 377 return MBeanEasyConfig.convertStringValueToProperType(value, ai.getType()); 378 } 379 } 380 catch (MBeanConfigException e) 381 { 382 String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_attribute_exception", externalName, e.getMessage() ); 383 throw new MBeanException(new MBeanConfigException( msg )); 384 } 385 386 } 387 388 395 public Object getPropertyElementValue(String propertyName) throws MBeanException,AttributeNotFoundException 396 { 397 sLogger.log(Level.FINEST, MSG_BASE_GET_PROPERTY, propertyName); 398 399 ConfigBean baseBean = getBaseConfigBean(); 400 Class cl = baseBean.getClass(); 401 ElementProperty prop; 402 try 403 { 404 Method method = cl.getDeclaredMethod("getElementPropertyByName", new Class []{Class.forName("java.lang.String")}); 405 prop = (ElementProperty)method.invoke(baseBean, new Object []{propertyName}); 406 } 407 catch (Exception e) 408 { 409 String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute.undefined_properties_in_base_element", propertyName ); 410 throw new MBeanException(new MBeanConfigException( msg )); 411 } 412 if(prop==null) { 413 String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_properties_not_found_in_base_element", propertyName ); 414 throw new MBeanException(new MBeanConfigException( msg )); 415 } 416 return prop.getValue(); 417 } 418 424 public void setPropertyElementValue(Attribute attr, boolean bAllowsEmptyValue) throws MBeanException,AttributeNotFoundException 425 { 426 String propertyName = attr.getName(); 427 String value = (String )attr.getValue(); 428 sLogger.log(Level.FINEST, MSG_BASE_SET_PROPERTY, new Object []{propertyName, value}); 429 430 ConfigBean baseBean = getBaseConfigBean(); 431 432 Class cl = baseBean.getClass(); 433 ElementProperty prop; 434 try 435 { 436 Method method = cl.getDeclaredMethod("getElementPropertyByName", new Class []{Class.forName("java.lang.String")}); 437 prop = (ElementProperty)method.invoke(baseBean, new Object []{propertyName}); 438 } 439 catch (Exception e) 440 { 441 String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_undefined_properties_in_base_element", propertyName ); 442 throw new MBeanException(new MBeanConfigException( msg )); 443 } 444 if(prop==null && value!=null && (bAllowsEmptyValue || !value.equals(""))) 445 { 446 prop = new ElementProperty(); 447 prop.setName(propertyName); 448 prop.setValue(value); 449 try 450 { 451 Method method = cl.getDeclaredMethod("addElementProperty", new Class []{prop.getClass()}); 452 method.invoke(baseBean, new Object []{prop}); 453 } 454 catch (Exception e) 455 { 456 String msg = localStrings.getString( "admin.server.core.mbean.config.setproperty_invoke_error", propertyName ); 457 throw new MBeanException(new MBeanConfigException( msg )); 458 } 459 } 460 else 461 { 462 if(value==null || (!bAllowsEmptyValue && value.equals(""))) 463 { 464 try 465 { 466 Method method = cl.getDeclaredMethod("removeElementProperty", new Class []{prop.getClass()}); 467 method.invoke(baseBean, new Object []{prop}); 468 } 469 catch (Exception e) 470 { 471 String msg = localStrings.getString( "admin.server.core.mbean.config.setproperty_could_not_remove_propery", propertyName ); 472 throw new MBeanException(new MBeanConfigException( msg )); 473 } 474 } 475 else 476 prop.setValue(value); 477 } 478 479 try 480 { 481 m_configContext.flush(); 482 } 483 catch (ConfigException e) 484 { 485 throw new MBeanException(new MBeanConfigException(e.getMessage())); 486 } 487 } 488 489 490 497 public Object getDefaultAttributeValue(String externalName) throws AttributeNotFoundException,MBeanConfigException 498 { 499 sLogger.log(Level.FINEST, MSG_BASE_GET_DEF_ATTR_VALUE, externalName); 500 MBeanAttributeInfo ai = getAttrInfo(externalName); 501 if(ai==null) { 502 String msg = localStrings.getString( "admin.server.core.mbean.config.getdefaultattribute_undefined_attribute", externalName ); 503 throw new AttributeNotFoundException( msg ); 504 } 505 { 507 AttrDescriptor descr = getDescriptor(externalName); 508 String value = descr.getDefaultValue(); 509 return MBeanEasyConfig.convertStringValueToProperType(value, ai.getType()); 510 } 511 517 } 518 519 525 public void setAttribute(Attribute attr) throws MBeanException,AttributeNotFoundException 526 { 527 String externalName = attr.getName(); 528 Object value = attr.getValue(); 529 sLogger.log(Level.FINEST, MSG_BASE_SET_ATTRIBUTE, new Object []{externalName, value}); 530 MBeanAttributeInfo ai = getAttrInfo(externalName); 531 boolean isProperty = externalName.startsWith(ConfigAttributeName.PROPERTY_NAME_PREFIX); 532 if(ai==null && !isProperty) 533 { 534 String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_undefined_attribute", externalName ); 535 throw new AttributeNotFoundException( msg ); 536 } 537 if(ai!=null && !ai.isWritable()) 538 { 539 String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_attribute_not_writable", externalName ); 540 throw new MBeanException(new MBeanConfigException( msg )); 541 } 542 543 try 544 { 545 if(isProperty) 546 { 547 boolean bAllowsEmptyValue = true; 548 if(ai!=null) 549 { 550 AttrDescriptor descr = getDescriptor(externalName); 551 if(descr!=null) 552 { 553 bAllowsEmptyValue = descr.isEmptyValueAllowed(); 554 } 555 } 556 setPropertyElementValue(new Attribute(externalName.substring(ConfigAttributeName.PROPERTY_NAME_PREFIX.length()), value), bAllowsEmptyValue); 558 return; 559 } 560 else 561 { 566 AttrDescriptor descr = getDescriptor(externalName); 567 ConfigBean bean = getConfigBean(externalName); 568 if(descr.isElement()) 569 { 570 String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_not_implemented_for_xml" ); 573 throw new MBeanException(new MBeanConfigException( msg )); 574 575 } 578 else 579 { 580 581 if(value==null || (value.equals("") && !descr.isEmptyValueAllowed()) ) 583 bean.setAttributeValue(descr.getAttributeName(), null); 584 else 585 bean.setAttributeValue(descr.getAttributeName(), value.toString()); 586 m_configContext.flush(); 587 } 588 } 589 590 } 591 catch (ConfigException e) 597 { 598 String msg = localStrings.getString( "admin.server.core.mbean.config.setAttribute_exception_for_externalname_basexpath", externalName, m_BasePath, e.getMessage() ); 599 throw new MBeanException(new MBeanConfigException( msg )); 600 } 601 } 602 603 608 public AttributeList getAttributes(String [] attributeNames) 609 { 610 AttributeList attrs = new AttributeList(); 611 for(int i=0; i<attributeNames.length; i++) 612 { 613 { 615 if(attributeNames[i].length()==0) 616 { 617 String [] names = getAllAttributeNames(); 618 if(names!=null) 619 attrs.addAll(getAttributes(names)); 620 } 621 else 622 { 623 if(attributeNames[i].equals(ConfigAttributeName.PROPERTY_NAME_PREFIX)) 624 { 625 String [] names = getAllPropertyNames(true); 626 if(names!=null) 627 attrs.addAll(getAttributes(names)); 628 } 629 else 630 { 631 try 632 { 633 Object value = getAttribute(attributeNames[i]); 634 attrs.add(new Attribute(attributeNames[i], value)); 635 } 636 catch (MBeanException ce) 637 { 638 attrs.add(new Attribute(attributeNames[i], null)); 639 } 640 catch (AttributeNotFoundException ce) 641 { 642 attrs.add(new Attribute(attributeNames[i], null)); 643 } 644 catch (NullPointerException npe) { 646 attrs.add(new Attribute(attributeNames[i], null)); 647 } 648 } 649 } 650 } 651 } 655 return attrs; 656 } 657 658 663 public AttributeList setAttributes(AttributeList attrList) 664 { 665 AttributeList attrs = new AttributeList(); 666 Iterator it = attrList.iterator(); 667 while (it.hasNext()) 668 { 669 try 670 { 671 Attribute attribute = (Attribute) it.next(); 672 setAttribute(attribute); 673 attrs.add(attribute); 674 } 675 catch (MBeanException mbe) 676 { 677 } 678 catch (AttributeNotFoundException anfe) 679 { 680 } 681 catch (NullPointerException npe) 682 { 683 } 684 } 685 return attrs; 686 } 687 691 public Object invoke(String methodName, Object [] methodParams, 692 String [] methodSignature) throws MBeanException, ReflectionException 693 { 694 698 return ( super.invoke(methodName, methodParams, methodSignature) ); 699 } 700 701 private Hashtable createAttrsDescriptors(String [][] attrs) throws MBeanConfigException 703 { 704 Hashtable ht = new Hashtable (); 705 if (attrs != null) 706 { 707 for(int i=0; i<attrs.length; i++) 708 { 709 ht.put(attrs[i][0], 710 new AttrDescriptor(attrs[i][1])); 711 } 712 } 713 return ht; 714 } 715 716 private AttrDescriptor getDescriptor(String externalName) 718 { 719 return (AttrDescriptor)m_Attrs.get(externalName); 720 } 721 722 734 public static String convertName(String name) 735 { 736 CharacterIterator ci; 737 StringBuffer n = new StringBuffer (); 738 boolean up = true; 739 boolean keepCase = false; 740 char c; 741 742 ci = new StringCharacterIterator (name); 743 c = ci.first(); 744 745 while (c != CharacterIterator.DONE) 747 { 748 if (Character.isLowerCase(c)) 749 { 750 keepCase = true; 751 break; 752 } 753 c = ci.next(); 754 } 755 756 c = ci.first(); 757 while (c != CharacterIterator.DONE) 758 { 759 if (c == '-' || c == '_') 760 up = true; 761 else 762 { 763 if (up) 764 c = Character.toUpperCase(c); 765 else 766 if (!keepCase) 767 c = Character.toLowerCase(c); 768 n.append(c); 769 up = false; 770 } 771 c = ci.next(); 772 } 773 return n.toString(); 774 } 775 776 private MBeanAttributeInfo getAttrInfo(String attrName) 778 { 779 if(attrName==null || m_MBeanInfo==null) 780 return null; 781 782 MBeanAttributeInfo[] ai = m_MBeanInfo.getAttributes(); 783 if(ai!=null) 784 for(int i=0; i<ai.length; i++) 785 { 786 String name = ai[i].getName(); 787 if(attrName.equals(ai[i].getName())) 788 return ai[i]; 789 } 790 return null; 791 } 792 793 private String [] getAllAttributeNames() 795 { 796 if(m_Attrs==null ) 797 return null; 798 Enumeration keys = m_Attrs.keys(); 799 ArrayList list = new ArrayList (); 800 while(keys.hasMoreElements()) 801 { 802 list.add(keys.nextElement()); 803 } 804 return (String [])list.toArray(new String [list.size()]); 805 } 806 807 private String [] getAllPropertyNames(boolean bAddPropertyPrefix) 809 { 810 811 ConfigBean baseBean = getBaseConfigBean(); 812 Class cl = baseBean.getClass(); 813 ElementProperty[] props; 814 try 815 { 816 Method method = cl.getDeclaredMethod("getElementProperty", null); 817 props = (ElementProperty[])method.invoke(baseBean, null); 818 String [] names = new String [props.length]; 819 for(int i=0; i<props.length; i++) 820 { 821 if(bAddPropertyPrefix) 822 names[i] = ConfigAttributeName.PROPERTY_NAME_PREFIX+props[i].getName(); 823 else 824 names[i] = props[i].getName(); 825 } 826 return names; 827 } 828 catch (java.lang.NoSuchMethodException nsme) 829 { 830 return null; 831 } 832 catch (java.lang.IllegalAccessException iae) 833 { 834 return null; 835 } 836 catch (java.lang.reflect.InvocationTargetException ite) 837 { 838 return null; 839 } 840 } 841 842 847 static Object [] MergeAttributesWithAnotherMbean( 848 String [][] maplist1, String [] attributes1, 849 String [][] maplist2, String [] attributes2, 850 String relativeXPath2, String attrNamesPrefix2) 851 { 852 int size = 0; 853 if(maplist1!=null) 854 size += maplist1.length; 855 if(maplist2!=null) 856 size += maplist2.length; 857 String [][] new_maplist = new String [size][]; 858 String [] new_attributes = new String [size]; 859 String [] mapelem; 860 int i = 0; 861 if(maplist1!=null) 862 for(i=0; i<maplist1.length; i++) 863 { 864 new_maplist[i] = (String [])maplist1[i].clone(); 865 new_attributes[i] = attributes1[i]; 866 } 867 if(maplist2!=null) 868 for(int j=0; j<maplist2.length; j++) 869 { 870 mapelem = (String [])maplist2[j].clone(); 871 new_attributes[i+j] = attributes2[j]; 872 if(attrNamesPrefix2!=null) 873 { 874 mapelem[0] = attrNamesPrefix2 + mapelem[0]; 875 new_attributes[i+j] = attrNamesPrefix2 + attributes2[j].trim(); 876 } 877 mapelem[1] = relativeXPath2 + "/" + mapelem[1]; 878 new_maplist[i+j] = mapelem; 879 } 880 return new Object []{new_maplist, new_attributes}; 881 882 } 883 884 private static Class getConfigBeanClass(String xPath) 886 { 887 String beanName = ConfigBeansFactory.getConfigBeanNameByXPath(xPath); 889 try 891 { 892 Class cl = Class.forName("com.sun.enterprise.config.serverbeans."+beanName); 893 return cl; 894 } 895 catch(Exception e) 896 { 897 return null; 898 } 899 } 900 901 904 protected Class getImplementingClass() { 905 return ( this.getClass() ); 906 } 907 908 909 protected Object getImplementingMBean() { 910 return ( this ); 911 } 912 913 private class AttrDescriptor 915 { 916 public String m_xPath = ""; 917 public String m_attributeName; 918 public boolean m_bAllowsEmptyValue = false; 919 920 public AttrDescriptor(String description) throws MBeanConfigException 922 { 923 try 924 { 925 int lastSlashIdx = description.lastIndexOf(ServerXPathHelper.XPATH_SEPARATOR); 927 if(description.charAt(lastSlashIdx+1)==ATTRIBUTE_CHAR) 928 { if(description.charAt(lastSlashIdx+2)==ALLOWS_EMPTY_CHAR) 930 { 931 m_attributeName = description.substring(lastSlashIdx+3); 932 m_bAllowsEmptyValue = true; 933 } 934 else 935 m_attributeName = description.substring(lastSlashIdx+2); 936 937 if(lastSlashIdx>0) 938 m_xPath = description.substring(0,lastSlashIdx); 939 } 940 else 941 { m_attributeName = null; } 944 } 945 catch (Throwable e) 946 { 947 String msg = localStrings.getString( "admin.server.core.mbean.config.attrdescriptor_constructor_exception", description, e.getMessage() ); 948 throw new MBeanConfigException( msg ); 949 } 950 } 951 952 public String getAttributeName() 954 { 955 return m_attributeName; 956 } 957 958 public String getXPath() 960 { 961 if(m_BasePath==null || m_BasePath.length()==0 || 962 m_xPath.indexOf(ServerXPathHelper.XPATH_SEPARATOR)==0) 963 return m_xPath; 964 if(m_xPath.length()==0) 965 return m_BasePath; 966 return m_BasePath + ServerXPathHelper.XPATH_SEPARATOR + m_xPath; 967 } 968 969 public boolean isEmptyValueAllowed() 971 { 972 return m_bAllowsEmptyValue; 973 } 974 public ConfigBean getConfigBean() throws Exception 976 { 977 return getConfigBeanByXPath(getXPath()); 978 } 979 980 public String getDefaultValue() 982 { 983 Class cl = getConfigBeanClass(getXPath()); 984 try 986 { 987 Method method = cl.getMethod("getDefaultAttributeValue", new Class [] {Class.forName("java.lang.String")} ); 988 return (String )method.invoke(null, new Object [] {m_attributeName}); 989 } 990 catch(Exception e) 991 { 992 return null; 993 } 994 } 995 1001 public boolean isElement() 1003 { 1004 return (m_attributeName==null); 1005 } 1006 } 1007 1008} 1009 | Popular Tags |