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

ConfigBeanHelper

public class ConfigBeanHelper extends Object

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

        
    
        m_baseConfigBean = cb;
        m_mbean = mbean;
//        if(!descriptor.isConfigBeanRetrospected())
//        {
//        }
    
Methods Summary
public static booleancheckIfAttributesAndPropertiesAreResolvable(com.sun.enterprise.config.ConfigBean element, java.lang.String instanceName)
this method tests if all attributes and properties of the tested config element are fully resolvable (not consist of unresolvable ${...} - varibles inside

param
element The testing config element bean
param
appserver instance name
throws
ConfigException

        final PropertyResolver resolver = new PropertyResolver(element.getConfigContext(), instanceName);
        final String[] attrNames = element.getAttributeNames();
        //first - check attributes;
        if(attrNames!=null)
        {
            for(int i=0; i<attrNames.length; i++)
            {
               String value = element.getAttributeValue(attrNames[i]);
               if(value!=null && !resolver.isResolvable(value, true))
               {
                   return false;
               }
            }
        }
        //then - properties;
        ElementProperty[] props = getElementProperties(element);
        if(props!=null)
        {
            for(int i=0; i<props.length; i++)
            {
               String value = props[i].getValue();
               if(value!=null && !resolver.isResolvable(value, true))
               {
                   return false;
               }
            }
        }
           
        return true;
    
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);
    
private static com.sun.enterprise.config.serverbeans.ElementProperty[]getElementProperties(com.sun.enterprise.config.ConfigBean element)


        Class cl = element.getClass();
        ElementProperty[] props = null;
        try
        {
           Method method = cl.getDeclaredMethod("getElementProperty");
           props = (ElementProperty[])method.invoke(element);
        }
        catch (Exception e)
        {
        }
        return props;
    
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);
    
protected static booleanisDebugEnabled()
/ public String getAttributeValue(String name) throws MBeanException,AttributeNotFoundException { //FIXME change to CoinfigMBeanBase implementation if(m_baseConfigBean==null) return null; if(name.startsWith(PROPERTY_NAME_PREFIX)) { // get property value return (String)getPropertyElementValue(name.substring(PROPERTY_NAME_PREFIX.length())); } else return m_baseConfigBean.getAttributeValue(name); } public String setAttributeValue(String name, String value) throws MBeanException,AttributeNotFoundException { //FIXME change to CoinfigMBeanBase implementation if(m_baseConfigBean==null) return null; if(name.startsWith(PROPERTY_NAME_PREFIX)) { // set property value setPropertyElementValue(new Attribute(name.substring(PROPERTY_NAME_PREFIX.length()), value), false); } else m_baseConfigBean.setAttributeValue(name, value); return value; } /** call app server logging

        return true;
    
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()));
        }
*/