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

MappedDelegate

public class MappedDelegate extends DelegateBase
Delegate class which wraps another, and maps its Attributes to different names.

Fields Summary
private final Delegate
mDelegate
MBeanInfo in which names have not been mapped (original).
private final MBeanInfo
mUnmappedMBeanInfo
MBeanInfo in which names have not been mapped (original).
private final MBeanInfo
mMappedMBeanInfo
MBeanInfo in which names have been mapped.
private final Set
mUnmappedAttributeNames
the Attribute names, before mapping
private final com.sun.enterprise.management.support.AMXAttributeNameMapper
mAttributeNameMapper
the mapper
Constructors Summary
public MappedDelegate(Delegate delegate, com.sun.enterprise.management.support.AMXAttributeNameMapper mapper)
New instance which wraps the supplied delegate using the specified mapper.

		super( "MappedDelegate." + (delegate == null ? "null" : delegate.getID()), null);
		
		mDelegate	= delegate;
		
		mUnmappedMBeanInfo	= getUnmappedMBeanInfoFresh();
		
		final String[]	unmappedAttributeNames	=
			JMXUtil.getAttributeNames( mUnmappedMBeanInfo.getAttributes() );
		mUnmappedAttributeNames	= ArrayConversion.arrayToSet( unmappedAttributeNames );
		
		mAttributeNameMapper	= mapper;
		//mAttributeNameMapper.deriveAll( unmappedAttributeNames );
		
		mMappedMBeanInfo	= mapMBeanInfo( mDelegate.getMBeanInfo() );
	
Methods Summary
protected final java.lang.String_getDefaultValue(java.lang.String mappedName)

		checkSupported( mappedName );
		
		final String unmappedName	= mAttributeNameMapper.derivedToOriginal( mappedName );
		
		return( mDelegate.getDefaultValue( unmappedName ) );
	
private voidcheckSupported(java.lang.String mappedName)

		if ( ! supportsAttribute( mappedName ) )
		{
		    debug( "Attribute " + mappedName + " is not supported, have: " +
		        CollectionUtil.toString( mAttributeNameMapper.getDerivedNames(), ", ") );
			throw new AttributeNotFoundException( mappedName );
		}
	
protected java.lang.StringderivedToOriginal(java.lang.String mappedName)
Get the unmapped name for a mapped Attribute name. If the name has not been mapped, it is returned unchanged.

		return( mAttributeNameMapper.derivedToOriginal( mappedName ) );
	
private javax.management.AttributederivedToOriginal(javax.management.Attribute mappedAttr)
Return the unmapped version of an mapped Attribute.

		final String	unmappedName	= derivedToOriginal( mappedAttr.getName() );
		
		return( new Attribute( unmappedName, mappedAttr.getValue() ) );
	
protected java.lang.String[]derivedToOriginal(java.lang.String[] mappedNames)
Call derivedToOriginal( name ) for each mapped name.

		final String[]	unmappedNames	= new String[ mappedNames.length ];
		
		for( int i = 0; i < unmappedNames.length; ++i )
		{
			unmappedNames[ i ]	= derivedToOriginal( mappedNames[ i ] );
		}
		
		return( unmappedNames );
	
protected javax.management.AttributeListderivedToOriginal(javax.management.AttributeList mappedAttrs)

		// first, create a new list which uses the unmapped names
		final int			numAttrs		= mappedAttrs.size();
		final AttributeList	unmappedAttrs	= new AttributeList();
		for( int i = 0; i < numAttrs; ++i )
		{
			unmappedAttrs.add( derivedToOriginal( (Attribute)mappedAttrs.get( i ) ) );
		}
		
		return( unmappedAttrs );
	
public java.lang.ObjectgetAttribute(java.lang.String mappedName)

		checkSupported( mappedName );
		
		final String unmappedName	= mAttributeNameMapper.derivedToOriginal( mappedName );
		
		return( mDelegate.getAttribute( unmappedName ) );
	
public java.lang.String[]getAttributeNames()

		final String[]	names	=
			JMXUtil.getAttributeNames( getMBeanInfo().getAttributes() );
			
		return( names );
	
public javax.management.AttributeListgetAttributes(java.lang.String[] mappedNames)

		final AttributeList	unmappedResults	=
			mDelegate.getAttributes( derivedToOriginal( mappedNames ) );
		
		return( originalToDerived( unmappedResults ) );
	
public javax.management.MBeanInfogetMBeanInfo()

		return( getMappedMBeanInfo() );
	
protected javax.management.MBeanInfogetMappedMBeanInfo()

		return( mMappedMBeanInfo );
	
protected javax.management.MBeanInfogetUnmappedMBeanInfo()

		return( mUnmappedMBeanInfo );
	
protected javax.management.MBeanInfogetUnmappedMBeanInfoFresh()

		return( mDelegate.getMBeanInfo( ) );
	
public final java.lang.Objectinvoke(java.lang.String operationName, java.lang.Object[] args, java.lang.String[] types)
Just pass it along to the Delegate

		final Object	result	= mDelegate.invoke( operationName, args, types );
		
		return( result );
	
private javax.management.MBeanAttributeInfomapAttributeInfo(javax.management.MBeanAttributeInfo unmappedInfo)

		String	mappedName	= originalToDerived( unmappedInfo.getName() );
		
		if ( mappedName == null )
		{
            mappedName  = unmappedInfo.getName();
		}
		
		final MBeanAttributeInfo	mappedInfo	=
							new MBeanAttributeInfo(
								mappedName, 
								unmappedInfo.getType(), 
								unmappedInfo.getDescription(), 
								unmappedInfo.isReadable(), 
								unmappedInfo.isWritable(), 
								unmappedInfo.isIs()
							);
		
		return( mappedInfo );
	
private javax.management.MBeanAttributeInfo[]mapAttributeInfos(javax.management.MBeanAttributeInfo[] unmappedInfos)

		final MBeanAttributeInfo[]	mappedInfos	=
				new MBeanAttributeInfo[ unmappedInfos.length ];
		
		for ( int i = 0; i < unmappedInfos.length; ++i )
		{
		    final String    attrName    = unmappedInfos[ i ].getName();
			assert( attrName != null );
		    
			mappedInfos[ i ]	= mapAttributeInfo( unmappedInfos[ i ] );
			assert( mappedInfos[ i ].getName() != null );
			debug( "Mapped " + unmappedInfos[ i ].getName() + " to " + mappedInfos[i].getName() );
		}
		return( mappedInfos );
	
private javax.management.MBeanInfomapMBeanInfo(javax.management.MBeanInfo unmappedMBeanInfo)
Create an MBeanInfo which contains the mapped names.

		final MBeanAttributeInfo[]	mappedAttributeInfos	=
				mapAttributeInfos( unmappedMBeanInfo.getAttributes() );
				
		final MBeanInfo	mappedInfo	= new MBeanInfo(
			unmappedMBeanInfo.getClassName(),
			unmappedMBeanInfo.getDescription(),
			mappedAttributeInfos,
			unmappedMBeanInfo.getConstructors(),
			unmappedMBeanInfo.getOperations(),
			unmappedMBeanInfo.getNotifications()
			);
		
		return( mappedInfo );
	
private java.lang.StringoriginalToDerived(java.lang.String unmappedName)
Get the mapped name for an unmapped name. If the name has not been mapped, it is returned unchanged.

		return( mAttributeNameMapper.originalToDerived( unmappedName ) );
	
private javax.management.AttributeoriginalToDerived(javax.management.Attribute unmappedAttr)

		final String	mappedName	= originalToDerived( unmappedAttr.getName() );
		return( new Attribute( mappedName, unmappedAttr.getValue() ) );
	
protected javax.management.AttributeListoriginalToDerived(javax.management.AttributeList unmappedAttrs)

		// first, create a new list which uses the unmapped names
		final int			numAttrs	= unmappedAttrs.size();
		final AttributeList	mappedAttrs	= new AttributeList();
		for( int i = 0; i < numAttrs; ++i )
		{
			mappedAttrs.add( originalToDerived( (Attribute)unmappedAttrs.get( i ) ) );
		}
		
		
		return( unmappedAttrs );
	
public voidsetAttribute(javax.management.Attribute mappedAttr)

		checkSupported( mappedAttr.getName() );
		
		final Attribute unmappedAttr	= derivedToOriginal( mappedAttr );
		
		mDelegate.setAttribute( unmappedAttr );
	
public javax.management.AttributeListsetAttributes(javax.management.AttributeList mappedAttrs)

		// first, create a new list which uses the unmapped names
		final AttributeList	unmappedAttrs	= derivedToOriginal( mappedAttrs );
		
		// get the Attributes using the unmapped names
		final AttributeList	unmappedResults	=
						mDelegate.setAttributes( unmappedAttrs );
		
		return( originalToDerived( unmappedResults ) );
	
public booleansupportsAttribute(java.lang.String mappedName)

		return( mAttributeNameMapper.getDerivedNames().contains( mappedName ) );