FileDocCategorySizeDatePackage
DottedNameGetSetMBeanBase.javaAPI DocGlassfish v2 API23271Fri May 04 22:24:10 BST 2007com.sun.enterprise.admin.mbeans

DottedNameGetSetMBeanBase

public abstract class DottedNameGetSetMBeanBase extends Object

Fields Summary
final MBeanServerConnection
mConn
final DottedNameRegistry
mRegistry
protected final ValueAccessor
mValueAccessor
final DottedNameServerInfo
mServerInfo
public static final char
ASSIGNMENT_DELIM
private static final char
BACKSLASH
Constructors Summary
public DottedNameGetSetMBeanBase(MBeanServerConnection conn, DottedNameRegistry registry, DottedNameServerInfo serverInfo)


    /*
        Instantiate with a reference to an MBeanServerConnection which will be used
        as the server when searching for required objects (which is possibly different
        than the MBeanServer in which this object will be registered).

        Due to a bug in the server startup sequence, this is the only allowed
        constructor; avoiding the bug requires the SunoneInterceptor as 'conn'.com
        Ideally the only constructor would be one that takes no arguments, and obtains
        its MBeanServerConnection from preRegister().
     */
        
    
         		
         		
         		 
    
        mConn			= conn;

        mRegistry		= registry;

        mValueAccessor	= new AnyValueAccessor( mConn );

        mServerInfo		= serverInfo;
    
Methods Summary
protected static java.lang.StringconvertWildcardStringToJavaFormat(java.lang.String wildcardString)

    /*
        We support only '*" and '?'-- the '.' is a literal character
     */
          
        
    
        final int 			length	= wildcardString.length();
        final StringBuffer	buf	= new StringBuffer();

        for( int i = 0; i < length; ++i )
        {
            final char	theChar	= wildcardString.charAt( i );

            if ( theChar == '." )
            {
                buf.append( "[.]" );
            }
            else if ( theChar == '*" )
            {
                buf.append( ".*" );
            }
            else if ( theChar == BACKSLASH )
            {
                buf.append( "" + BACKSLASH + BACKSLASH );
            }
            else
            {
                buf.append( theChar );
            }
        }
        return( buf.toString() );
    
abstract DottedNameQuerycreateQuery()

public voiddoGet(java.util.Set dottedNames, javax.management.AttributeList attrsOut)

        final Iterator	iter	= dottedNames.iterator();

        while ( iter.hasNext() )
        {
            try
            {
                doGet( (String)iter.next(), attrsOut );
            }
            catch( Exception e )
            {
                // propogate up up if it's a single item
                if ( dottedNames.size() == 1 )
                {
                    throw e;
                }
                else
                {
                    // do not log the exception if the attribute wasn't found;
                    // this is very common with wildcards
                    if ( ! (e instanceof AttributeNotFoundException) )
                    {
                        logException( e );
                    }
                }
            }
        }
    
protected voiddoGet(java.lang.String dottedNameString, javax.management.AttributeList attrsOut)

        // NOTE: this name includes the value-name
        final DottedName			dn	= getDottedName( dottedNameString );
        final DottedNameForValue	dnv	= new DottedNameForValue( dn );

        final ObjectName			target		= getTarget( dnv, getResolver( ) );
        final String				valueName	= dnv.getValueName();

        final Attribute	attr	= mValueAccessor.getValue( target, valueName);

        if ( attr != null )
        {
            // emit the name in its full form
            attrsOut.add( formAttribute( dnv.getPrefix(), valueName, attr.getValue() ) );
        }
    
protected java.util.SetdoList(java.lang.String[] namePrefixes)

        final Set	all	= new HashSet();

        for( int i = 0; i < namePrefixes.length; ++i )
        {
            final String	dottedNamePrefix	= namePrefixes[ i ];

            Set	resolved	= null;
            if ( DottedName.isWildcardName( dottedNamePrefix ) )
            {
                resolved	= resolveWildcardPrefix( dottedNamePrefix );
            }
            else
            {
                // no wildcard means to list all immediate children of the prefix
                resolved	= getAllImmediateChildren( dottedNamePrefix );
            }

            all.addAll( resolved );
        }

        return( all );
    
java.lang.Object[]dottedNameGet(java.lang.String[] names)

        final Object []	results	= new Object[ names.length ];

        for( int i = 0; i < names.length; ++i )
        {
            results[ i ]	= dottedNameGet( names[ i ] );
        }

        return( results );
    
java.lang.ObjectdottedNameGet(java.lang.String name)

        Object	result	= null;

        try
        {
            final Set	all	= resolveInputNames( new String [] { name } );

            final AttributeList	attrs	= new AttributeList();
            doGet( all, attrs );

            if ( ! DottedName.isWildcardName( name )  )
            {
                // return an Attribute if the input was a single dotted-name
                assert( attrs.size() == 1 );
                result	= (Attribute)attrs.get( 0 );
            }
            else
            {
                result	= sortAttributeList( attrs );
            }
        }
        catch( Exception e )
        {
            logException( e );
            // the result will be the exception itself
            result	= e;
        }

        assert( result != null );
        return( result );
    
public java.lang.String[]dottedNameList(java.lang.String[] namePrefixes)

        Set	all	= Collections.EMPTY_SET;

        try
        {
            // if nothing specified, get top-level names
            all	= (namePrefixes.length == 0) ?
                    getAllTopLevelNames() : doList( namePrefixes );
        }
        catch( Exception e )
        {
            logException( e );
        }

        final String []	allArray	= new String [ all.size() ];
        all.toArray( allArray );

        Arrays.sort( allArray );
        return( allArray );
    
javax.management.AttributeformAttribute(DottedName prefix, java.lang.String valueName, java.lang.Object value)

        return( new Attribute( prefix + "." + valueName, value ) );
    
protected static java.util.SetgenerateDottedNamesForValues(java.util.Set valueNames, java.lang.String prefix, java.lang.String suffix)

        final Iterator	iter	= valueNames.iterator();
        final Set		allDottedNameStrings	= new HashSet();

        final Pattern	pattern	= Pattern.compile( convertWildcardStringToJavaFormat( suffix ) );

        while ( iter.hasNext() )
        {
            final String	valueName	= (String)iter.next();

            if ( pattern.matcher( valueName ).matches() )
            {
                allDottedNameStrings.add( prefix + "." + valueName );
            }
        }

        return( allDottedNameStrings );
    
protected java.util.SetgetAllDescendants(java.lang.String namePrefix)

        final Set	searchSet	= getSearchSet( namePrefix );

        // a child must be prefix.xxx
        final String searchPrefix	= namePrefix + ".";

        final Set	resultSet	= new HashSet();
        final Iterator	iter	= searchSet.iterator();
        while ( iter.hasNext() )
        {
            final String	candidateString	= (String)iter.next();

            if ( candidateString.startsWith( searchPrefix ) )
            {
                resultSet.add( candidateString );
            }
        }

        return( resultSet );
    
protected java.util.SetgetAllImmediateChildren(java.lang.String namePrefix)

        final Set	allChildren	= getAllDescendants( namePrefix );

        final int			numParentParts	= getDottedName( namePrefix ).getParts().size();
        final Iterator		iter			= allChildren.iterator();

        final Set	resultSet	= new HashSet();
        while ( iter.hasNext() )
        {
            final String	descendant	= (String)iter.next();

            if ( getDottedName( descendant ).getParts().size() == numParentParts + 1 )
            {
                resultSet.add( descendant );
            }
        }

        return( resultSet );
    
protected static java.util.SetgetAllPropertyNames(PropertyValueAccessorBase accessor, javax.management.ObjectName objectName)

        final Set		allNames	= new HashSet();

        // add the property names
        final String []	propNames	= accessor.getAllPropertyNames( objectName, true );
        for( int i = 0; i < propNames.length; ++i )
        {
            // prepend the "properties." prefix
            allNames.add( propNames[ i ] );
        }

        return( allNames );
    
protected java.util.SetgetAllTopLevelNames()

        final Set	all	= new HashSet();
        final Set	searchSet	= createQuery().allDottedNameStrings();

        // a child must be prefix.xxx
        final Iterator	iter	= searchSet.iterator();
        while ( iter.hasNext() )
        {
            final String		candidateString	= (String)iter.next();
            final DottedName	dn	= getDottedName( candidateString );

            if ( dn.getParts().size() == 0 )
            {
                all.add( candidateString );
            }
        }
        return( all );
    
protected static java.util.SetgetAllValueNames(javax.management.MBeanServerConnection conn, javax.management.ObjectName objectName)

        final Set		allNames	= new HashSet();

        allNames.addAll(getAllPropertyNames( new PropertyValueAccessor(conn), objectName ));
        allNames.addAll(getAllPropertyNames( new SystemPropertyValueAccessor(conn), objectName ));
        allNames.addAll( AttributeValueAccessor.getAllAttributeNames( conn, objectName ) );

        return( allNames );
    
protected DottedNamegetDottedName(java.lang.String s)

        return( DottedNameFactory.getInstance().get( s ) );
    
protected javax.management.MBeanServerConnectiongetMBS()

        return( mConn );
    
protected DottedNameRegistrygetRegistry()

        return( mRegistry );
    
abstract DottedNameResolvergetResolver()

protected java.util.SetgetSearchSet(java.lang.String dottedNameExpr)

        final DottedName	dn		= getDottedName( dottedNameExpr );
        final String		scope	= dn.getScope();
        Set					s	= null;

        // consider it to be a domain if it starts with "domain"
        final boolean	isDomain	= scope.startsWith( DottedNameAliasSupport.DOMAIN_SCOPE );

        // consider it to be a config if it starts with a config name
        boolean	isConfig	= startsWithConfigName( dottedNameExpr );

        if ( isDomain || isConfig )
        {
            s	= getRegistry().allDottedNameStrings();
        }
        else
        {
            // this will create a search set consisting of everything "server."
            s	= createQuery().allDottedNameStrings();
        }

        return( s );
    
protected DottedNameServerInfogetServerInfo()

        return( mServerInfo );
    
protected static javax.management.ObjectNamegetTarget(DottedNameForValue dottedName, DottedNameResolver resolver)

        final DottedName	prefixDN	= dottedName.getPrefix();

        final ObjectName theObject	= resolver.resolveDottedName( prefixDN.toString() );

        if ( theObject == null )
        {
            final String	msg	= DottedNameStrings.getString(
                    DottedNameStrings.OBJECT_INSTANCE_NOT_FOUND_KEY, dottedName.toString() );

            throw new InstanceNotFoundException( msg );
        }

        return( theObject );
    
protected static voidlogException(java.lang.Exception e)

        DottedNameLogger.logException( e );
    
java.lang.StringnormalizeWildcardName(java.lang.String name)

        String	normalizedName	= name;

        if ( name.equals( "*" ) )
        {
            normalizedName	= "*.*";
        }
        return( normalizedName );
    
protected java.util.SetprefixToValueDottedNamesWild(DottedNameResolver resolver, java.lang.String prefix, java.lang.String suffix)

        final Set			all	= new HashSet();

        try
        {
            final ObjectName	objectName	= resolver.resolveDottedName( prefix );

            if ( objectName != null )
            {
                Set	allValueNames	= null;
                PropertyValueAccessorBase prop_accessor = null;
                // wildcarded properties must not wildcard the "property" part
                // eg "property.<regex>"
                if ( suffix.equals( "*" ) )
                {
                    // all attributes *and* all properties
                    allValueNames	= getAllPropertyNames( new PropertyValueAccessor(getMBS()), objectName );
                    allValueNames.addAll(getAllPropertyNames( new SystemPropertyValueAccessor(getMBS()), objectName ));
                    allValueNames.addAll( getAllValueNames( getMBS(), objectName ) );
                }
                else if ((prop_accessor=(new PrefixedValueSupport(getMBS()).getPrefixedValueAccessor(suffix)))!=null)
                {
                    allValueNames	= getAllPropertyNames( prop_accessor, objectName );
                }
                else
                {
                    // any other expression should match just attributes
                    allValueNames	= getAllValueNames( getMBS(), objectName );
                }

                final Set	valuesDottedNames	= generateDottedNamesForValues( allValueNames, prefix, suffix );

                all.addAll( valuesDottedNames );
            }
        }
        catch( Exception e )
        {
            logException( e );
        }

        return( all );
    
java.util.SetprefixesToValueDottedNames(DottedNameResolver resolver, java.util.Set prefixes, java.lang.String suffix)

        final Set			all		= new HashSet();
        final Iterator		iter	= prefixes.iterator();

        while ( iter.hasNext() )
        {
            final String	prefix	= (String)iter.next();

            if ( DottedName.isWildcardName( suffix ) )
            {
                all.addAll( prefixToValueDottedNamesWild( resolver, prefix, suffix ) );
            }
            else
            {
                // a fixed non-wildcard value-name--just append it
                final String	dottedName	= prefix + "." + suffix;
                all.add( dottedName );

            }
        }

        return( all );
    
protected java.util.SetresolveInputNames(java.lang.String[] names)

        final Set			all	= new HashSet();

        for( int i = 0; i < names.length; ++i )
        {
            String	name	= names[ i ];

            if ( DottedName.isWildcardName( name ) )
            {
                name	= normalizeWildcardName( name );

                final DottedName			dn		= getDottedName( name );
                final DottedNameForValue	dnv	= new DottedNameForValue( dn );

                final String	prefix		= dnv.getPrefix().toString();
                final String	valueName	= dnv.getValueName();

                final Set		resolvedPrefixes	= resolveWildcardPrefix( prefix );


                final Set	newDottedNames	= prefixesToValueDottedNames( getResolver( ),
                                                    resolvedPrefixes, valueName );


                all.addAll( newDottedNames );
            }
            else
            {
                all.add( name );
            }

        }

        return( all );
    
protected java.util.SetresolveWildcardPrefix(java.lang.String dottedNamePrefix)

        Set	resolvedSet	= Collections.EMPTY_SET;

        if ( DottedName.isWildcardName( dottedNamePrefix ) )
        {
            if ( dottedNamePrefix.equals( "*" ) )	// optimization
            {
                resolvedSet	= createQuery().allDottedNameStrings();
            }
            else
            {
                final Set	searchSet	= getSearchSet( dottedNamePrefix );

                final String	regex	= convertWildcardStringToJavaFormat( dottedNamePrefix );

                final DottedNameWildcardMatcher matcher	=
                        new DottedNameWildcardMatcherImpl( searchSet );

                resolvedSet	= matcher.matchDottedNames( regex );
            }
        }
        else
        {
            resolvedSet	= Collections.singleton( dottedNamePrefix );
        }

        return( resolvedSet );
    
java.lang.StringsetToString(java.util.Set s)

        final Iterator	iter	= s.iterator();
        final StringBuffer	buf	= new StringBuffer();

        while ( iter.hasNext() )
        {
            buf.append( (String)iter.next() + "\n" );
        }

        return( buf.toString() );
    
protected javax.management.Attribute[]sortAttributeList(javax.management.AttributeList attrsIn)

        final Attribute []	attrs	= new Attribute[ attrsIn.size() ];
        attrsIn.toArray( attrs );

        Arrays.sort( attrs, new AttributeComparator() );

        return( attrs );
    
protected booleanstartsWithConfigName(java.lang.String dottedNameExpr)

        boolean	startsWithConfig	= false;

        try
        {
            final Iterator	iter	= mServerInfo.getConfigNames().iterator();
            while ( iter.hasNext() )
            {
                final String	configName	= (String)iter.next();

                if ( dottedNameExpr.startsWith( configName ) )
                {
                    startsWithConfig	= true;
                    break;
                }
            }
        }
        catch( DottedNameServerInfo.UnavailableException e )
        {
            logException( e );
        }

        return( startsWithConfig );
    
private booleanstartsWithDomain(java.lang.String dottedNameExpr)

        return( dottedNameExpr.startsWith( DottedNameAliasSupport.DOMAIN_SCOPE ) );