FileDocCategorySizeDatePackage
ConfigMBeanHelper.javaAPI DocGlassfish v2 API20880Fri May 04 22:25:34 BST 2007com.sun.enterprise.admin.config

ConfigMBeanHelper

public class ConfigMBeanHelper extends com.sun.enterprise.admin.MBeanHelper

Fields Summary
private static final String
XPATH_SEPARATOR
public static final String
PROPERTY_NAME_PREFIX
public static final String
PROPERTY_SPECIAL_EMPTY_VALUE
private com.sun.enterprise.config.ConfigBean
m_baseConfigBean
private BaseConfigMBean
m_mbean
Constructors Summary
public ConfigMBeanHelper(BaseConfigMBean mbean, com.sun.enterprise.config.ConfigBean cb)

        
    
        m_baseConfigBean = cb;
        m_mbean = mbean;
//        if(!descriptor.isConfigBeanRetrospected())
//        {
//        }
    
Methods Summary
public static java.lang.ObjectconverConfigBeansToObjectNames(com.sun.enterprise.admin.meta.MBeanRegistry registry, javax.management.modelmbean.ModelMBeanInfo parentInfo, java.lang.Object ret)

        if(ret!=null)
        {
            if(ret instanceof ConfigBean)
                return (Object)getChildObjectName(registry, parentInfo, (ConfigBean)ret);
            if(ret instanceof ConfigBean[])
                return (Object)getChildObjectNames(registry, parentInfo, (ConfigBean[])ret);
        }
        return ret;
    
public static java.lang.StringconvertTagName(java.lang.String name)
Convert a DTD name into a bean name: Any - or _ character is removed. The letter following - and _ is changed to be upper-case. If the user mixes upper-case and lower-case, the case is not changed. If the Word is entirely in upper-case, the word is changed to lower-case (except the characters following - and _) The first letter is always upper-case.

        CharacterIterator  ci;
        StringBuffer    n = new StringBuffer();
        boolean    up = true;
        boolean    keepCase = false;
        char    c;
        
        ci = new StringCharacterIterator(name);
        c = ci.first();
        
        // If everything is uppercase, we'll lowercase the name.
        while (c != CharacterIterator.DONE)
        {
            if (Character.isLowerCase(c))
            {
                keepCase = true;
                break;
            }
            c = ci.next();
        }
        
        c = ci.first();
        while (c != CharacterIterator.DONE)
        {
            if (c == '-" || c == '_")
                up = true;
            else
            {
                if (up)
                    c = Character.toUpperCase(c);
                else
                    if (!keepCase)
                        c = Character.toLowerCase(c);
                n.append(c);
                up = false;
            }
            c = ci.next();
        }
        return n.toString();
    
protected static voiddebug(java.lang.String s)

        //TODO: change this to app server logging
        System.out.println(s);
    
protected static voiderror(java.lang.String s)

        //TODO: change this to app server logging
        System.out.println(s);
    
public com.sun.enterprise.config.ConfigBeangetChildElementByName(java.lang.String methodName, java.lang.String name)
Gets MBean's child element.

param
childName the MBean's child element name.
return
The value of the property retrieved.
throws
MBeanException exception
throws
AttributeNotFoundException exception


        Class cl = m_baseConfigBean.getClass();
        ConfigBean bean;
        try
        {
           Method method = cl.getDeclaredMethod(methodName, new Class[]{Class.forName("java.lang.String")});
           return (ConfigBean)method.invoke(m_baseConfigBean, new Object[]{name});
        }
        catch (Exception e)
        {
			String msg = /*localStrings.getString*/( "admin.server.core.mbean.config.getattribute.undefined_childelement_in_base_element"+ name );
            throw new MBeanException(new MBeanConfigException( msg ));
        }
    
public static java.lang.String[]getChildNamesList(com.sun.enterprise.config.ConfigBean[] beans)

        String[] names = new String[beans.length];
        for(int i=0; i<beans.length; i++)
        {
            String xpath = beans[i].getAbsoluteXPath("");
            names[i] = MBeanMetaHelper.getMultipleElementKeyValue(xpath);
        }
        return names;
    
public static javax.management.ObjectNamegetChildObjectName(com.sun.enterprise.admin.meta.MBeanRegistry registry, javax.management.modelmbean.ModelMBeanInfo parentInfo, com.sun.enterprise.config.ConfigBean childBean)

        Descriptor descr = parentInfo.getMBeanDescriptor();
        return getConfigBeanObjectName(registry, (String)descr.getFieldValue(DOMAIN_FIELD_NAME), childBean);
    
public static javax.management.ObjectName[]getChildObjectNames(com.sun.enterprise.admin.meta.MBeanRegistry registry, javax.management.modelmbean.ModelMBeanInfo parentInfo, com.sun.enterprise.config.ConfigBean[] children)

        Descriptor descr = parentInfo.getMBeanDescriptor();
        return getConfigBeansObjectNames(registry, (String)descr.getFieldValue(DOMAIN_FIELD_NAME), children);
    
public static java.lang.ClassgetConfigBeanClass(java.lang.String xPath)

        // get ConfigBean classname from XPath
        String beanName = ConfigBeansFactory.getConfigBeanNameByXPath(xPath);
        //getting the class object
        try
        {
            Class cl = Class.forName("com.sun.enterprise.config.serverbeans."+beanName);
            return cl;
        }
        catch(Exception e)
        {
            return null;
        }
    
public static javax.management.ObjectNamegetConfigBeanObjectName(com.sun.enterprise.admin.meta.MBeanRegistry registry, java.lang.String domainName, com.sun.enterprise.config.ConfigBean childBean)

        String xpath = childBean.getAbsoluteXPath("");
        MBeanRegistryEntry entry = registry.findMBeanRegistryEntryByXPath(xpath);
        MBeanNamingDescriptor namingDescr = entry.getNamingDescriptor();
        String[] location = namingDescr.extractParmListFromXPath(xpath);
        location[0] = domainName;
        return namingDescr.createObjectName((Object[])location);
    
public static javax.management.ObjectName[]getConfigBeansObjectNames(com.sun.enterprise.admin.meta.MBeanRegistry registry, java.lang.String domainName, com.sun.enterprise.config.ConfigBean[] beans)

        ObjectName[] objNames = new ObjectName[beans.length];
        for(int i=0; i<beans.length; i++)
            objNames[i] = getConfigBeanObjectName(registry, domainName, beans[i]);
        return objNames;
    
public static javax.management.AttributeListgetDefaultAttributeValues(com.sun.enterprise.admin.meta.naming.MBeanNamingDescriptor descr, java.lang.String[] attrNames)

        if(attrNames==null || attrNames.length<1)
            return null;
        AttributeList attrs = new AttributeList();
        Class cl = getConfigBeanClass(descr.getXPathPattern());
        if(cl==null)
            return null;
        Method method = cl.getDeclaredMethod("getDefaultAttributeValue", new Class[]{Class.forName("java.lang.String")});
        for(int i=0; i<attrNames.length; i++)
        {
            try {
                Object value = (String)method.invoke(null, new Object[]{MBeanMetaHelper.mapToConfigBeanAttributeName(attrNames[i])});
                if(value!=null)
                    attrs.add(new Attribute(attrNames[i], value));
            } catch(Exception e) {};
        }
        return attrs;
    
public static javax.management.ObjectNamegetOwnObjectName(com.sun.enterprise.admin.meta.MBeanRegistry registry, javax.management.modelmbean.ModelMBeanInfo parentInfo)

        Descriptor descr = parentInfo.getMBeanDescriptor();
        String type = (String)descr.getFieldValue(NMTYPE_FIELD_NAME);
        String[] location = (String[])descr.getFieldValue(NMLOCATION_FIELD_NAME);
        MBeanRegistryEntry entry = registry.findMBeanRegistryEntryByType(type);
        MBeanNamingDescriptor namingDescr = entry.getNamingDescriptor();
        return namingDescr.createObjectName(location);
    
public java.lang.ObjectgetPropertyElementValue(java.lang.String propertyName)
Gets MBean's property value.

param
externalName the MBean's property name.
return
The value of the property retrieved.
throws
MBeanException exception
throws
AttributeNotFoundException exception


        Class cl = m_baseConfigBean.getClass();
        ElementProperty prop;
        try
        {
           Method method = cl.getDeclaredMethod("getElementPropertyByName", new Class[]{Class.forName("java.lang.String")});
           prop = (ElementProperty)method.invoke(m_baseConfigBean, new Object[]{propertyName});
        }
        catch (Exception e)
        {
			String msg = /*localStrings.getString*/( "admin.server.core.mbean.config.getattribute.undefined_properties_in_base_element"+ propertyName );
            throw new MBeanException(new MBeanConfigException( msg ));
        }
        if(prop==null) {
			String msg = /*localStrings.getString*/( "admin.server.core.mbean.config.getattribute_properties_not_found_in_base_element"+ propertyName );
            throw new MBeanException(new MBeanConfigException( msg ));
		}
        return prop.getValue();
    
protected static voidinfo(java.lang.String s)

        //TODO: change this to app server logging
        System.out.println(s);
    
public voidsetPropertyElementValue(javax.management.Attribute attr, boolean bAllowsEmptyValue)
Sets MBean's property value.

param
attr The identification of the property to be set and the value it is to be set to.
throws
MBeanException exception
throws
AttributeNotFoundException exception

        String propertyName = attr.getName();
        String value = (String)attr.getValue();
        
        Class cl = m_baseConfigBean.getClass();
        ElementProperty prop;
        try
        {
           Method method = cl.getDeclaredMethod("getElementPropertyByName", new Class[]{Class.forName("java.lang.String")});
           prop = (ElementProperty)method.invoke(m_baseConfigBean, new Object[]{propertyName});
        }
        catch (Exception e)
        {
			String msg = /*localStrings.getString*/( "admin.server.core.mbean.config.setattribute_undefined_properties_in_base_element"+ propertyName );
            throw new MBeanException(new MBeanConfigException( msg ));
        }
        if(prop==null && value!=null && (bAllowsEmptyValue || !value.equals("")))
        {
            prop = new ElementProperty();
            prop.setName(propertyName);
            prop.setValue(value);
            try
            {
                Method method = cl.getDeclaredMethod("addElementProperty", new Class[]{prop.getClass()});
                method.invoke(m_baseConfigBean, new Object[]{prop});
            }
            catch (Exception e)
            {
				String msg = /*localStrings.getString*/( "admin.server.core.mbean.config.setproperty_invoke_error"+propertyName );
                throw new MBeanException(new MBeanConfigException( msg ));
            }
        }
        else
        {
            if(value==null || (!bAllowsEmptyValue && value.equals("")))
            {
                try
                {
                    Method method = cl.getDeclaredMethod("removeElementProperty", new Class[]{prop.getClass()});
                    method.invoke(m_baseConfigBean, new Object[]{prop});
                }
                catch (Exception e)
                {
					String msg = /*localStrings.getString*/( "admin.server.core.mbean.config.setproperty_could_not_remove_propery"+ propertyName );
                    throw new MBeanException(new MBeanConfigException( msg ));
                }
            }
            else
                prop.setValue(value);
        }
        
/*        try
        {
            m_configContext.flush();
        }
        catch (ConfigException e)
        {
            throw new MBeanException(new MBeanConfigException(e.getMessage()));
        }
*/