FileDocCategorySizeDatePackage
AttributeNameManglerImpl.javaAPI DocGlassfish v2 API4974Fri May 04 22:31:04 BST 2007com.sun.appserv.management.util.jmx

AttributeNameManglerImpl

public class AttributeNameManglerImpl extends Object implements AttributeNameMangler
Implements the mapping by removing illegal characters and attempting to camel-case a following alphabetic character. Optionally capitalizes the first letter

Fields Summary
private final Map
mOverrides
private final boolean
mCapitalizeFirstLetter
Constructors Summary
public AttributeNameManglerImpl(boolean capitalizeFirstLetter, Map overrides)

param
capitalizeFirstLetter true if first letter should be capitalized
param
overrides explicit mappings from the original to a result

		mCapitalizeFirstLetter	= capitalizeFirstLetter;
		mOverrides				= overrides;
	
Methods Summary
private java.lang.StringconvertOverride(java.lang.String name)

		String	result	= name;
		
		if ( mOverrides != null )
		{
			if ( mOverrides.containsKey( name ) )
			{
				result	= (String)mOverrides.get( name );
			}
			/*
			else
			{
				// have to do case-insensitive search
				final Iterator	iter	= mOverrides.keySet().iterator();
				while ( iter.hasNext() )
				{
					final String	override	= (String)iter.next();
					
					if ( override.equalsIgnoreCase( name ) )
					{
						result	= (String)mOverrides.get( name );
						break;
					}
				}
			}
			*/
		}
		
		return( result );
	
public java.lang.StringmangleAttributeName(java.lang.String attributeName)

		String	result	= mangleIt( attributeName );
		
		return( result );
	
private java.lang.StringmangleIt(java.lang.String attributeName)
Note that because we expect a "get" or "set" to be placed in front of the Attribute name, the first character of the Attribute name need only be a valid Java identifier part; it need not be a valid first character.

		final char[]		chars	= attributeName.toCharArray();
		final StringBuffer	buf	= new StringBuffer();
		
		// capitalize the first letter
		final char	firstChar	= chars[ 0 ];
		if ( Character.isJavaIdentifierPart( firstChar ) )
		{
			buf.append( mCapitalizeFirstLetter ? toUpperCase( firstChar ) : "" + firstChar );
		}
		// else  { omit it }
		
		for( int i = 1; i < chars.length; ++i )
		{
			final char	c	= chars[ i ];
			
			if ( ! Character.isJavaIdentifierPart( c ) )
			{
				++i;	// skip it
				
				final char	nextChar	= (i < chars.length) ? chars[ i ] : 0;
					
				if (  nextChar >= 'a" && nextChar <= 'z" )
				{
					buf.append( toUpperCase( chars[ i ] ) );
				}
				else if (  nextChar >= 'A" && nextChar <= 'Z" )
				{
					buf.append( "" + chars[ i ] );
				}
				else
				{
					// emit nothing and go onto next character
					--i;
				}
			}
			else
			{
				buf.append( c );
			}
		}
		
		final String	before	= buf.toString();
		final String	result	= convertOverride( before );
		
		return( result );
	
private java.lang.StringtoUpperCase(char c)

		return( ("" + c).toUpperCase() );