FileDocCategorySizeDatePackage
ObjectNames.javaAPI DocGlassfish v2 API13395Fri May 04 22:23:42 BST 2007com.sun.enterprise.management.support

ObjectNames

public final class ObjectNames extends Object
Class used to build ObjectNames for AMX MBeans. This class does not assume that any MBeans are loaded--and no code should be added which does; such code belongs in the {@link QueryMgr}.

Note that most of the time, using the {@link QueryMgr} is a better choice. In particular, the ObjectNames returned from here are the minimal ones required to uniquely identify the ; the actual registered MBean may well have additional properties.

Fields Summary
private final String
mJMXDomain
private static final String[]
EMPTY_STRING_ARRAY
public static final String
MISSING_PARENT_NAME
The name that should be used for a missing parent such as J2EEApplication=null, as defined by JSR 77 specification. Must be distinct from the name returned by getSingletonName( j2eeType ).
Constructors Summary
private ObjectNames(String jmxDomain)

		mJMXDomain	= jmxDomain;
	
Methods Summary
public javax.management.ObjectNamebuildContaineeObjectName(javax.management.ObjectName parentObjectName, java.lang.String parentFullType, java.lang.String childJ2EEType, java.lang.String childName)
Build an ObjectName for an MBean logically contained within the parent MBean. The child may be a true child (a subtype), or simply logically contained within the parent.

param
parentObjectName
param
parentFullType
param
childJ2EEType
param
childName
return
ObjectName

		final String	domain	= parentObjectName.getDomain();
		
		String	props	= "";
		
		final TypeInfo	info	= TypeInfos.getInstance().getInfo( childJ2EEType );
		if ( info.isSubType() )
		{
			// extract j2eeType and name
			final String 	parentProp		= Util.getSelfProp( parentObjectName );
			
			// extract the remaining ancestors
			final String[]	parentFullTypes	= Util.getTypeArray( parentFullType );
			final Set<String> ancestorKeys	= GSetUtil.newSet( parentFullTypes, 0, parentFullTypes.length - 1 );
			final String	ancestorProps	= JMXUtil.getProps( parentObjectName, ancestorKeys, true );
			props	= Util.concatenateProps( parentProp, ancestorProps );
		}
		else
		{
			// it's logically contained within the parent, nothing more to do
		}
		
		
		final String	requiredProps	= Util.makeRequiredProps( childJ2EEType, childName );
		final String	allProps		= Util.concatenateProps( requiredProps, props );
		
		return( Util.newObjectName( domain, allProps  ) );
	
public javax.management.ObjectNamebuildContaineeObjectName(javax.management.ObjectName parentObjectName, java.lang.String parentFullType, java.lang.String childJ2EEType)

		final String	name	= getSingletonName( childJ2EEType );
		
		return( buildContaineeObjectName( parentObjectName, parentFullType, childJ2EEType, name ) );
	
private voiddebug(java.lang.Object o)

	    AMXDebug.getInstance().getOutput(
	        "com.sun.enterprise.management.support.ObjectNames" ).println( o );
	
public javax.management.ObjectNamegetContainerObjectName(javax.management.MBeanServer server, javax.management.ObjectName containedObjectName)
Get the ObjectName of the MBean logically containing the specified MBean.

param
server
param
containedObjectName
return
the ObjectName of the MBean logically containing the child

		debug( "getContainerObjectName: containedObjectName = " + containedObjectName );
		    
		final String containedFullType	= getFullType( server, containedObjectName );
		
		debug( "getContainerObjectName: containedFullType = " + containedFullType );
		
		ObjectName	parentPattern	= getContainerObjectNamePattern( containedObjectName, containedFullType );
		ObjectName	containingObjectName	= null;
		
		if ( parentPattern != null )
		{
		    debug( "getContainerObjectName: parentPattern = " + parentPattern );
			final Set<ObjectName>	names	= JMXUtil.queryNames( server, parentPattern, null );
			
			if ( names.size() == 0 )
			{
				throw new InstanceNotFoundException( parentPattern.toString() );
			}
			
			containingObjectName	= (ObjectName)GSetUtil.getSingleton( names );
		}
		else
		{
			final String	j2eeType	= Util.getJ2EEType( containedObjectName );
			
			if ( ! j2eeType.equals( XTypes.DOMAIN_ROOT ) )
			{
				throw new IllegalArgumentException( containedObjectName.toString() );
			}
		}
		
		return( containingObjectName );
	
public javax.management.ObjectNamegetContainerObjectNamePattern(javax.management.ObjectName childObjectName, java.lang.String childFullType)
Get a parent ObjectName pattern using a child's ObjectName. The "parent" in this context means the MBean that logically contains the child. The caller must query for the actual ObjectName.

param
childObjectName the child ObjectName
return
an ObjectName pattern for the parent.


	
	
			            		            		     				 	  		      	
		 
	
		  
		 	  
	
		ObjectName	parentPattern	= null;
		
		final String	domain	= childObjectName.getDomain();
		
		final String[]	fullType	= Util.getTypeArray( childFullType );
		assert( fullType.length >= 1 );
		
		final String	childType	= fullType[ fullType.length - 1 ];
		
		if ( fullType.length == 1 )
		{
			final TypeInfo	info		= TypeInfos.getInstance().getInfo( childType );
			
			final String	containedByJ2EEType	= info.getContainedByJ2EEType();
			if ( containedByJ2EEType != null )
			{
				String	parentProps	= "";
				
				// special case--DomainRoot and J2EEDomain must have a name
				// equal to the domain name
				if ( containedByJ2EEType.equals( XTypes.DOMAIN_ROOT ) ||
					containedByJ2EEType.equals( J2EETypes.J2EE_DOMAIN ) )
				{
					parentProps	= Util.makeRequiredProps( containedByJ2EEType, domain );
				}
				else
				{
					parentProps	= Util.makeRequiredProps( containedByJ2EEType,
						getSingletonName( containedByJ2EEType ) );
				}
				
				parentPattern	= Util.newObjectNamePattern( domain, parentProps );
			}
			else
			{
				parentPattern	= null;	// no parent
			}
		}
		else
		{
			/*
				 It's a subType.  A subtype may have one or more "missing" ancestors.  For example,
				 the FullType of EJBModule is J2EEServer.J2EEApplication.EJBModule.  Since an EJBModule
				 may be standalone, the J2EEApplication may not actually exist.  We need to account for
				 this, and we do so by using the convention that a name of "null" indicates such a missing
				 ancestor.
				 
				 The parent is handled differently than the other properties because we have to extract
				 j2eeType=<type>,name=<name> whereas the other properties are of the form
				 <type>=<name>.  So first, we must find the first real parent.
			 */
			String	parentJ2EEType	= null;
			String	parentName		= null;
			Set<String>		remainingKeys		= Collections.emptySet();
			for( int i = fullType.length - 2; i >= 0; --i )
			{
				final String	tempType	= fullType[ i ];
				final String	tempName	= childObjectName.getKeyProperty( tempType );
				assert( tempName != null ) : "missing ObjectName property: " + tempType;
				if ( ! MISSING_PARENT_NAME.equals( tempName ) )
				{
					parentJ2EEType	= tempType;
					parentName		= tempName;
					final int	numItems	= i;
					remainingKeys	= GSetUtil.newSet( fullType, 0, numItems );
					break;
				}
			}
			/*
			trace( "\n---------------------- getContainerObjectNamePattern ---------------------------" );
			trace( childFullType + " = " + childObjectName );
			trace( "parentJ2EEType = " + parentJ2EEType );
			trace( "parentName = " + parentName );
			trace( "remainingKeys = " + toString( remainingKeys ) );
			trace( "-------------------------------------------------" );
			*/
			final String parentProps = Util.makeRequiredProps( parentJ2EEType, parentName );
			final String ancestorProps	= JMXUtil.getProps( childObjectName, remainingKeys );
			
			final String props	= Util.concatenateProps( parentProps, ancestorProps );
			
			parentPattern	= Util.newObjectNamePattern( domain, props );
		}
		
		return( parentPattern );
	
public javax.management.ObjectNamegetDomainRootObjectName()

		return( newObjectName( Util.makeRequiredProps( XTypes.DOMAIN_ROOT, getJMXDomain() ) ) );
	
private static java.lang.StringgetFullType(javax.management.MBeanServer server, javax.management.ObjectName objectName)

		try
		{
			final String fullType	= (String)
				server.getAttribute( objectName, AMXAttributes.ATTR_FULL_TYPE );
				
			return( fullType );
		}
		catch( Exception e )
		{
			throw new RuntimeException( e );
		}
	
public static com.sun.enterprise.management.support.ObjectNamesgetInstance(java.lang.String jmxDomain)

		return( new ObjectNames( jmxDomain ) );
	
public static java.lang.StringgetJ2EEType(java.lang.Class theInterface)

	
	
		 
		  
	   
	
		return( (String)ClassUtil.getFieldValue( theInterface, "J2EE_TYPE" ) );
	
public java.lang.StringgetJMXDomain()

		return( mJMXDomain );
	
public static java.lang.StringgetSingletonName(java.lang.String j2eeType)
In the ObjectName, what should the "name" property contain if the object is a singleton or otherwise not named? The name property is always required. Possible choices include:
  • "none" (or similar idea)
  • the same as its j2eeType"
  • empty
  • random

		if ( TypeInfos.getInstance().getInfo( j2eeType ) == null )
		{
			throw new IllegalArgumentException( j2eeType );
		}
		
		assert( ! AMX.NO_NAME.equals( MISSING_PARENT_NAME ) );
		return( AMX.NO_NAME );
	
public javax.management.ObjectNamegetSingletonObjectName(java.lang.String j2eeType)
Get the ObjectName for a singleton object.

		final TypeInfo info	= TypeInfos.getInstance().getInfo( j2eeType );
		if ( info.isSubType() )
		{
			throw new IllegalArgumentException( "singletons may not be sub-types: " + j2eeType );
		}
		
		final String	props	= Util.makeRequiredProps( j2eeType, getSingletonName( j2eeType ) );
		
		return( newObjectName( props ) );
	
public static java.lang.StringmakeWild(java.lang.String props)

		return( Util.concatenateProps( props, JMXUtil.WILD_PROP ) );
	
private javax.management.ObjectNamenewObjectName(java.lang.String props)
Append the formatted props to the JMX domain and return the ObjectName

		return( Util.newObjectName( getJMXDomain(), props ) );
	
private static java.lang.StringtoString(java.lang.Object o)

		return( SmartStringifier.toString( o ) );