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

ParamNameMapper

public final class ParamNameMapper extends Object implements com.sun.appserv.management.util.jmx.AttributeNameMangler
Translates parameters from the new Attribute names to the old ones. When instantiated, optional override mappings may be supplied; these will be used in lieu of the algorithmic translation.

Fields Summary
final Map
mMappings
final String
mWordDelim
public static final String
DEFAULT_WORD_DELIM
The default delimiter used between words.
Constructors Summary
public ParamNameMapper(Map overrides)
Create a new instance. The 'overrides' map should map a new name to an old one.

param
overrides any special mappings that override the algorithmic mapping (may be null)

	
	
			   				           				            	 
		
	    
	
		this( overrides, DEFAULT_WORD_DELIM );
	
public ParamNameMapper(Map overrides, String wordDelim)
Create a new instance

param
overrides any special mappings that override the algorithmic mapping (may be null)

		mMappings	= new HashMap<String,String>();
		if ( overrides != null )
		{
			mMappings.putAll( overrides );
		}
		
		mWordDelim	= wordDelim;
	
public ParamNameMapper(String wordDelim)
Create a new instance with no overrides.

		this( null, wordDelim );
	
public ParamNameMapper()
Create a new instance with no overrides.

		this( null, DEFAULT_WORD_DELIM );
	
Methods Summary
private java.lang.StringgetLowerCaseSequence(java.text.StringCharacterIterator iter)

		final StringBuffer	buf = new StringBuffer();
		
		char	c;
		
		while ( (c=iter.current()) != CharacterIterator.DONE )
		{
			if ( Character.isUpperCase( c ) )
			{
				break;
			}

			iter.next();
			buf.append( c );
		}
		
		return( buf.toString() );
	
private java.lang.StringgetUpperCaseSequence(java.text.CharacterIterator iter)

		final StringBuffer	buf = new StringBuffer();
		
		char	c;
		
		while ( (c=iter.current()) != CharacterIterator.DONE )
		{
			if ( Character.isLowerCase( c ) )
			{
				break;
			}

			iter.next();
			buf.append( c );
		}
		
		return( buf.toString() );
	
public java.lang.StringmangleAttributeName(java.lang.String newName)
Convert an Attribute name from the new one to the old one. Any special casing should override this.

		String	result	= (String)mMappings.get( newName );
		
		if ( result == null )
		{
			// use algorithmic conversion
			result	= newToOld( newName );
			
			// cache for later
			mMappings.put( newName, result );
	    }

		return( result );
	
private java.lang.StringnewToOld(java.lang.String newName)

		final StringCharacterIterator	iter	= new StringCharacterIterator( newName );
		final StringBuffer	buf = new StringBuffer();

		while ( iter.current() != CharacterIterator.DONE )
		{
			final String	uppercase	= getUpperCaseSequence( iter );
			if (	uppercase.length() <= 1 ||
					iter.current() == CharacterIterator.DONE )
			{
				buf.append( uppercase.toLowerCase() );
			}
			else
			{
				// a run of an uppercase acronym of length N.  The first N-1 characters
				// are the acronym and the last character is actually the first letter of
				// the next word.
				final int	acronymLength	= uppercase.length() - 1;
				final String	acronym		= uppercase.substring( 0, acronymLength );
				final char		firstOfNext	= uppercase.charAt( acronymLength );
				buf.append( acronym.toLowerCase() );
				buf.append( mWordDelim );
				buf.append( Character.toLowerCase( firstOfNext ) );
			}
			
			buf.append( getLowerCaseSequence( iter ) );
			if ( iter.current() != CharacterIterator.DONE )
			{
				buf.append( mWordDelim );
			}
		}
		
		return( buf.toString() );
	
public java.lang.StringtoString()

		final StringBuffer	buf = new StringBuffer();
		final Iterator 		iter	= mMappings.keySet().iterator();
		
		while ( iter.hasNext() )
		{
			final String	newName	= (String)iter.next();
			
			buf.append( newName + "=" + mMappings.get( newName ) + "\n");
		}
		return( buf.toString() );