FileDocCategorySizeDatePackage
NativeResults.javaAPI DocGlassfish v2 API5257Fri May 04 22:32:14 BST 2007com.sun.enterprise.util.io

NativeResults

public class NativeResults extends Object
Convert an integer error number returned from native code to a localized String As of April, 2003 -- UNIX is the only supported OS.
author
bnevins

Fields Summary
private Logger
logger
private ResourceBundle
rb
private static final String
RESOURCE_BUNDLE
private String
errorKey
private String
unknownErrorKey
private String
genericError
private String
osString
private int
id
private String
resultString
private NativeIOException
exception
Constructors Summary
NativeResults(int id)

		this.id = id;
		initStrings();
		setResultString();
		setResultException();
	
Methods Summary
NativeIOExceptiongetResultException()

return
the NativeIOException -- suitable for throwing

		return exception;	// may be null!
	
java.lang.StringgetResultString()

return
The localized String explanation of the error, or success.

		return resultString;
	
private voidinitStrings()

		try
		{
			rb = ResourceBundle.getBundle(RESOURCE_BUNDLE);
		}
		catch(Throwable t)
		{
			// any little error --> RuntimeException!!
			rb = null;
			logger.severe("Unable to get a ResourceBundle: " + RESOURCE_BUNDLE);
		}
		
		if(OS.isWindows())
			osString = "Windows";
		else
			osString = "UNIX";
		
		errorKey			= "enterprise_util." + osString + ".error.";
		unknownErrorKey		= errorKey + "unknown";
		genericError		= "UNKNOWN " + osString + " Error returned.  Errno =";
	
public static voidmain(java.lang.String[] args)

	
	//////////////////////////////////////////////////////////////////////////
	
	    
	
		int errs[] = { 0, 1, 2, 4, 5, 13, 14, 20, 22, 30, 67, 78, 9999, 111, -2};

		for(int i = 0; i < errs.length; i++)
		{
			int id = errs[i];
			
			NativeResults nr = new NativeResults(id);
			String s = "ID: " + id + ",  ";
			
			if(nr.getResultException() == null)
				s += "NO ERROR, ";
			else
				s += "YES ERROR, ";
			
			s += nr.getResultString();
			
			System.out.println(s);
		}
	
voidsetResultException()

		if(id != 0)	// by definition -- an error!
			exception = new NativeIOException(resultString, id);
	
private voidsetResultString()

		if(rb == null)
		{
			resultString = genericError + id;
			return;
		}
		
		try
		{
			resultString = rb.getString(errorKey + id);
			return;
		}
		catch(Throwable t)
		{
			// go into the next try block.  No need to nest it.
		}

		try
		{
			// note: the id is outside the parenthesis -- not a mistake...
			resultString =  rb.getString(unknownErrorKey) + id; 
			return;
		}
		catch(Throwable t)
		{
			resultString = genericError + id;
		}