FileDocCategorySizeDatePackage
ConfigBeanHelper.javaAPI DocGlassfish v2 API20437Fri May 04 22:23:40 BST 2007com.sun.enterprise.management.offline

ConfigBeanHelper

public abstract class ConfigBeanHelper extends Object

Fields Summary
private final com.sun.enterprise.config.ConfigBean
mConfigBean
private final String
mXPath
private final com.sun.enterprise.config.ConfigContext
mConfigContext
private final String
mType
private final String
mName
private static final String
NAME_ATTR
private static final String
VALUE_ATTR
private static final String
DESCRIPTION_ATTR
protected static final String[]
EMPTY_STRING_ARRAY
Constructors Summary
ConfigBeanHelper(com.sun.enterprise.config.ConfigContext configContext, com.sun.enterprise.config.ConfigBean configBean)

    
    
          
              
    
        if ( configBean == null )
        {
            throw new IllegalArgumentException( "null configBean" );
        }
        if ( configContext == null )
        {
            throw new IllegalArgumentException( "null configContext" );
        }
        
        // why does configBean.getConfigContext() return null?
        mConfigContext  = configContext;
        
        mConfigBean     = configBean;
        mXPath          = mConfigBean.getXPath();
        assert( mXPath != null );
        
        mType   = _getType( mXPath );
        mName   = _getName();
        
    
Methods Summary
protected java.util.Set_getAttributeNames()

        final Set<String>   attrNames =
            GSetUtil.newSet( mConfigBean.getAttributeNames() );
        
        // it does this sometimes!
        assert( ! attrNames.contains( null ) );
        attrNames.remove( null );
            
        if ( hasDescription() )
        {
            attrNames.add( DESCRIPTION_ATTR );
        }
        
        return attrNames;
    
private java.lang.String_getName()

        String  name    = null;
        
        final Set<String>  attrNames   = GSetUtil.newStringSet( getAttributeNames() );
                    
        for( final String nameKey : OldProps.getPossibleNameKeys() )
        {
            final String    camelized   = mConfigBean.camelize( nameKey );
            
            if ( attrNames.contains( camelized ) )
            {
                try
                {
                    name    = (String)getAttribute( camelized );
                    if ( name != null )
                    {
                        break;
                    }
                }
                catch( AttributeNotFoundException e )
                {
                    throw new RuntimeException( e );
                }
            }
        }
        
        return name;
    
static java.lang.String_getType(java.lang.String xPath)

    	return ConfigXPathHelper.getLastNodeName( xPath );
    
protected voiddebug(java.lang.Object o)

	    sdebug( o );
	    
	    final String    xpath   = "" + mXPath;
	    AMXDebug.getInstance().getOutput( "ConfigBeanHelper" ).println( xpath + ": " + o );
	
public java.util.ListgetAllChildren()

        final List<ConfigBeanHelper>  children    = new ArrayList<ConfigBeanHelper>();
        
        final ConfigBean[]  configBeans    = mConfigBean.getAllChildBeans();
        if ( configBeans != null )
        {
            for( final ConfigBean configBean : configBeans )
            {
                if ( configBean != null )
                {
                    final ConfigBeanHelper  helper =
                        ConfigBeanHelperFactory.getInstance( getConfigContext() ).getHelper( configBean );
                    
                    children.add( helper );
                }
            }
        }
        
        return children; 
    
public java.util.ListgetAllChildrenOfType(java.lang.String desiredType)

        final List<ConfigBeanHelper>  children  = getAllChildren();
        final List<ConfigBeanHelper>  propertyChildren = new ArrayList<ConfigBeanHelper>();
        
        for( final ConfigBeanHelper helper : children )
        {
            if ( desiredType.equals( helper.getType() ) )
            {
                propertyChildren.add( helper );
            }
        }
        
        return propertyChildren; 
    
public java.util.ListgetAllObjectNameProps(java.util.Set ignoreTypes)

        final List<String[]>   props   = new ArrayList<String[]>();
        
        //debug( "\n--------------------------------------" );
       // debug( xPath );
        String[] pair    = getTypeAndName();
        props.add( pair );
        
        String  curXPath = ConfigXPathHelper.getParentXPath( getXPath() );
        String  lastXPath    = null;
        while ( ! curXPath.equals( lastXPath ) )
        {
            final ConfigBeanHelper  helper  =
                ConfigBeanHelperFactory.getInstance( getConfigContext() ).getHelper( curXPath );
            
            pair    = helper.getTypeAndName();
            
            if ( ! ignoreTypes.contains( pair[ 0 ] ) )
            {
                props.add( pair );
            }
            
            lastXPath   = curXPath;
            curXPath    = helper.getParentXPath();
        }
        
        return props;
    
public java.lang.ObjectgetAttribute(java.lang.String attrName)

        Object  result  = null;
        
        if ( DESCRIPTION_ATTR.equals( attrName ) )
        {
            result  = getDescription();
        }
        else
        {
            try
            {
        	    result   = mConfigBean.getAttributeValue( attrName );
    	    }
    	    catch( RuntimeException e )
    	    {
        	    debug( "ATTR FAILED: " + attrName );
        	    throw e;
    	    }
	    }
	    return result;
    
protected java.lang.ClassgetAttributeClass(java.lang.String attrName)
Subclass may override this for special cases that are non-String.

        return String.class;
    
public final java.lang.String[]getAttributeNames()

        return GSetUtil.toStringArray( _getAttributeNames() );
    
public com.sun.enterprise.config.ConfigBeangetConfigBean()

        return mConfigBean;
    
public com.sun.enterprise.config.ConfigContextgetConfigContext()

        return mConfigContext;
    
public java.lang.StringgetDescription()

        String  result  = (String)getValue( DESCRIPTION_ATTR );
        
        return result;
    
protected javax.management.MBeanAttributeInfogetMBeanAttributeInfo(java.lang.String attrName)
Subclass may override this, or alternatly, just specify the Class of the Attribute by overriding {@link #getAttributeClass}.

        final String    description = "";
        final boolean   isReadable  = true;
        final boolean   isWriteable  = true;
        final boolean   isIs  = false;
        
        assert( attrName != null );
        final MBeanAttributeInfo    info = new MBeanAttributeInfo(
            attrName,
            getAttributeClass( attrName ).getName(),
            description,
            isReadable,
            isWriteable,
            isIs );
        
        return info;
    
public javax.management.MBeanInfogetMBeanInfo()

        final List<String>  attrNames   = ListUtil.newListFromArray( getAttributeNames() );
        
        final MBeanOperationInfo[]  operationInfos  = new MBeanOperationInfo[0];
        final MBeanAttributeInfo[]  attributeInfos  = new MBeanAttributeInfo[ attrNames.size() ];
        
        int i = 0;
        for( final String name : attrNames )
        {
            assert( name != null );
            attributeInfos[ i ] = getMBeanAttributeInfo( name );
            assert attributeInfos[ i ].getName() != null;
            
            ++i;
        }
                    
        final MBeanInfo	info	=
            new MBeanInfo( this.getClass().getName(),
                "exposes Attributes from ConfigBean",
                attributeInfos,
                null,
                operationInfos,
                null );
        
        for( final MBeanAttributeInfo xxx  : info.getAttributes() )
        {
            assert( xxx.getName() != null );
        }

		return info;
    
public java.lang.StringgetName()

return
name, possibly null if no name

        return mName;
    
public java.lang.StringgetParentXPath()

    	return ConfigXPathHelper.getParentXPath( getXPath() );
    
public javax.management.AttributeListgetProperties()

see
com.sun.enterprise.management.config.OldPropertiesImpl

        final Map<String,ConfigBeanHelper>  children =
            getSpecialChildMap( "element-property" );
        
        final AttributeList attrs   = new AttributeList();
        
        for( final String name : children.keySet() )
        {
            final ConfigBeanHelper  helper  = children.get( name );
            
            final String value  = getValueAttributeValue( helper );
            
            attrs.add( new Attribute( name, value ) );
        }
        
        return attrs;
    
public java.lang.StringgetPropertyValue(java.lang.String propertyName)

see
com.sun.enterprise.management.config.OldPropertiesImpl

        final Map<String,ConfigBeanHelper>  children =
            getSpecialChildMap( "element-property" );
        if ( ! children.containsKey( propertyName ) )
        {
            final String msg    = "No such property: " +
                StringUtil.quote( propertyName );
                
            throw new IllegalArgumentException( msg );
        }
        
        return getValueAttributeValue( children.get( propertyName ) );
    
public java.util.MapgetSpecialChildMap(java.lang.String type)

        if ( ! ("element-property".equals( type ) ||
            "system-property".equals( type )) ||
            "jvm-option".equals( type ) )
        {
            throw new IllegalArgumentException( type );
        }

        final List<ConfigBeanHelper> children = getAllChildrenOfType( type );
        final Map<String,ConfigBeanHelper>  m   = new HashMap<String,ConfigBeanHelper>();
        
        for( final ConfigBeanHelper helper : children )
        {
            try
            {
                final String name   = (String)helper.getAttribute( NAME_ATTR );
                
                m.put( name, helper );
            }
            catch( Exception e )
            {
                throw new RuntimeException(
                    "FAILURE getting Name Attribute for property element", e );
            }
        }
        
        return m;
    
public javax.management.AttributeListgetSystemProperties()

see
com.sun.enterprise.management.config.OldPropertiesImpl

        final Map<String,ConfigBeanHelper>  children =
            getSpecialChildMap( "system-property" );
        
        final AttributeList attrs   = new AttributeList();
        for( final String name : children.keySet() )
        {
            final ConfigBeanHelper  helper  = children.get( name );
            
            final String value  = getValueAttributeValue( helper );
            
            attrs.add( new Attribute( name, value ) );
        }
        
        return attrs;
    
public java.lang.StringgetSystemPropertyValue(java.lang.String propertyName)

see
com.sun.enterprise.management.config.OldPropertiesImpl

        final Map<String,ConfigBeanHelper>  children =
            getSpecialChildMap( "system-property" );
        if ( ! children.containsKey( propertyName ) )
        {
            throw new IllegalArgumentException( propertyName );
        }
        
        return getValueAttributeValue( children.get( propertyName ) );
    
public java.lang.StringgetType()

return
type, always non-null

    	return mType;
    
public java.lang.String[]getTypeAndName()

return
String[2], where [0] is the type and [1] is the name

        return new String[] { getType(), getName() };
    
protected java.lang.ObjectgetValue(java.lang.String valueName)
When the ConfigBean is called for an array value that can potentially exist, but doesn't, it tries to access an array illegally. Not much we can do except return null.

Here's the stack trace: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.RangeCheck(ArrayList.java:547) at java.util.ArrayList.get(ArrayList.java:322) at org.netbeans.modules.schema2beans.BeanProp.getValue(BeanProp.java:474) at org.netbeans.modules.schema2beans.BaseBean.getValue(BaseBean.java:353) at com.sun.enterprise.config.ConfigBean.getValue(ConfigBean.java:383)

        Object  value  = null;
        
        try
        {
            value = mConfigBean.getValue( valueName );
        }
        catch( Exception e )
        {
            debug( "ConfigBeanHelper.getValue: Exception accessing value: " + valueName );
            //e.printStackTrace();
        }
        
        return value;
    
protected static java.lang.StringgetValueAttributeValue(com.sun.enterprise.management.offline.ConfigBeanHelper helper)

        try
        {
            final String value  = (String)helper.getAttribute( VALUE_ATTR );
            return value;
        }
        catch( Exception e )
        {
            throw new RuntimeException(
                "FAILURE getting Value Attribute for property element ", e );
        }
    
public java.lang.StringgetXPath()

    	return mXPath;
    
public abstract java.lang.ObjecthandleInvoke(java.lang.String operationName, java.lang.Object[] args, java.lang.String[] types)

private booleanhasDescription()

        return hasValue( DESCRIPTION_ATTR );
    
protected booleanhasValue(java.lang.String valueName)

        boolean hasValue  = false;
        
        try
        {
            final Object    value   = mConfigBean.getValue( valueName );
            // value may be null, but it still indicates that the value is possible
            hasValue  = true;
            //sdebug( "HAS VALUE " + valueName + "=" + value );
        }
        catch( Exception e )
        {
        }
        
        return hasValue;
    
protected voidsdebug(java.lang.Object o)

	    System.out.println( "" + o );
	
public voidsetAttribute(javax.management.Attribute attr)

        final Object    value   = attr.getValue();
        
    	setAttribute( attr.getName(), value );
    
public voidsetAttribute(java.lang.String name, java.lang.Object value)

        if ( DESCRIPTION_ATTR.equals( name ) )
        {
            setDescription( (String)value );
        }
        else
        {
            // Config API wants strings (only)
            final String valueString   = (value == null) ? null : ("" + value);
    	    mConfigBean.setAttributeValue( name, valueString );
    	}
    
public voidsetDescription(java.lang.String description)

        mConfigBean.setValue( DESCRIPTION_ATTR, description );
    
public voidsetProperty(javax.management.Attribute attr)

see
com.sun.enterprise.management.config.OldPropertiesImpl

        final Map<String,ConfigBeanHelper>  children =
            getSpecialChildMap( "element-property" );
        
        // this won't work for creating a new property!
        final ConfigBeanHelper helper = children.get( attr.getName() );
        if ( helper == null )
        {
            throw new IllegalArgumentException( attr.getName() );
        }
        
        setValueAttributeValue( helper, (String)attr.getValue() );
    
public voidsetSystemProperty(javax.management.Attribute attr)

see
com.sun.enterprise.management.config.OldPropertiesImpl

        final Map<String,ConfigBeanHelper>  children =
            getSpecialChildMap( "system-property" );
        
        // this won't work for creating a new property!
        final ConfigBeanHelper helper = children.get( attr.getName() );
        if ( helper == null )
        {
            throw new IllegalArgumentException( attr.getName() );
        }
        
        setValueAttributeValue( helper, (String)attr.getValue() );
    
private static voidsetValueAttributeValue(com.sun.enterprise.management.offline.ConfigBeanHelper helper, java.lang.String value)

        try
        {
            helper.setAttribute( VALUE_ATTR, value );
        }
        catch( Exception e )
        {
            throw new RuntimeException(
                "FAILURE setting Value Attribute for property element ", e );
        }
    
public voidunsupportedOperation(java.lang.String operationName, java.lang.Object[] args, java.lang.String[] types)

        throw new IllegalArgumentException(
            "invoke() unknown operation " + operationName + "()" );