FileDocCategorySizeDatePackage
AliasMgrHashMapImpl.javaAPI DocGlassfish v2 API4583Fri May 04 22:24:52 BST 2007com.sun.cli.jmx.support

AliasMgrHashMapImpl

public final class AliasMgrHashMapImpl extends Object implements AliasMgrSPI

Fields Summary
final HashMap
mMap
String
mFilename
public static final String
DEFAULT_FILENAME
Constructors Summary
public AliasMgrHashMapImpl()

	
		
	
	
		mMap	= new HashMap();
	
Methods Summary
public voidcreate(java.lang.String aliasName, java.lang.String value)

		mMap.put( aliasName, value );
		
		save();
	
public voiddelete(java.lang.String aliasName)

		mMap.remove( aliasName );
		save();
	
public java.lang.Stringget(java.lang.String aliasName)

		return( (String)mMap.get( aliasName ) );
	
public java.util.SetgetNames()

		return( mMap.keySet() );
	
public voidload(java.io.File theFile)

		mFilename	= theFile.getPath();
		
		final FileReader	in	= new FileReader( theFile );
		
		while ( true )
		{
			final String	pair	= readLine( in );
			if ( pair == null )
				break;
				
			final int		separatorOffset	= pair.indexOf( '=" );
			
			final String name	= pair.substring( 0, separatorOffset );
			final String value	= pair.substring( separatorOffset + 1, pair.length() );
			
			create( name, value );
		}
		
		in.close();
	
private java.lang.StringreadLine(java.io.FileReader in)

		StringBuffer	buf	= new StringBuffer();
		
		while ( true )
		{
			final int	i =in.read();
			if ( i < 0 )
			{
				return( null );
			}
		
			final char	theChar	= (char)i;
			if ( theChar == '\n" || theChar == '\r" )
			{
				// ignore blank lines
				if ( buf.length() == 0 )
					continue;
				break;
			}
			
			buf.append( theChar );
		}
		return( buf.toString() );
	
public voidsave()

		if ( mFilename != null )
		{
			save( new File( mFilename ) );
		}
	
public voidsave(java.io.File theFile)

		mFilename	= theFile.getPath();
		
		final Set		names	= getNames();
		final Iterator	iter	= names.iterator();
		final String []	pairs	= new String [ names.size() ];
		
		for( int i = 0; i < pairs.length; ++i )
		{
			final String	name	= (String)iter.next();

			pairs[ i ]	= name + "=" + get( name );
		}
		
		final FileWriter	out	= new FileWriter( theFile );
		
		for( int i = 0; i < pairs.length; ++i )
		{
			out.write( pairs[ i ] + "\n" );
		}
		
		out.close();