FileDocCategorySizeDatePackage
AppContainer.javaAPI DocGlassfish v2 API9292Wed Jun 13 12:41:38 BST 2007com.sun.enterprise.appclient

AppContainer

public class AppContainer extends Object
This is the application client container. It performs tasks such as user login and other initialization based on the deployment descriptor information.
author
Vivek Nagar
author
Harpreet Singh

Fields Summary
public static final int
USERNAME_PASSWORD
public static final int
CERTIFICATE
public static final int
ALL
private static final boolean
debug
private com.sun.enterprise.deployment.ApplicationClientDescriptor
descriptor
private com.sun.enterprise.Switch
sw
private com.sun.enterprise.NamingManager
nm
private static CallbackHandler
handler
private boolean
guiAuth
private static Logger
_logger
Constructors Summary
public AppContainer(com.sun.enterprise.deployment.ApplicationClientDescriptor desc, boolean useGuiAuth)
The constructor takes the application client descriptor as an argument.


                   
         
    
	sw = Switch.getSwitch();
	sw.setContainerType(Switch.APPCLIENT_CONTAINER);
        // Inform the JTS that this is a APPCLIENT_CONTAINER . This is required
        // as JTS can not use Switch interface as it creates a circular dependency
        // Configuration.setAsAppClientConatiner();
	descriptor = desc;
        guiAuth = useGuiAuth;
    
Methods Summary
public static javax.security.auth.callback.CallbackHandlergetCallbackHandler()
This returns the CallbackHandler for the AppContainer.

return
handler

        return handler;
    
private voidinitializeCallbackHandler(java.lang.String callbackHandler, java.lang.ClassLoader loader)
Initialize the JAAS login modules. One login module per realm (default and certificate).

param
the JAAS callback handler class.
exception
LoginException if there was an error.

	Class handlerClass = null;
	handler = null;
	
	try {
	    if(callbackHandler != null) {
	        handlerClass = Class.forName(callbackHandler, true, loader);
		handler = (CallbackHandler) handlerClass.newInstance();
	    } else {
	        handler = new com.sun.enterprise.security.auth.login.LoginCallbackHandler(guiAuth);
	    }
	} catch(Exception e) {
            _logger.log(Level.FINE, "Could not instantiate specified " +
                         "callback handler:" + e.getMessage(), e);
            _logger.info("acc.using_default_callback");
	    handler = new com.sun.enterprise.security.auth.login.LoginCallbackHandler(guiAuth);
	} 
    
public static javax.naming.InitialContextinitializeNaming(java.util.Properties iiopProperties)
Creates the InitialContext, initializes the ORB's transaction service, and creates and establishes the switch's transaction manager.

param
iiopProperties Properties object used in creating the InitialContext
return
the InitialContext created
throws
NamingException for errors creating the InitialContext

        InitialContext result = new InitialContext(iiopProperties);
        
        Switch sw = Switch.getSwitch();
        
	InvocationManager im = new InvocationManagerImpl();
	sw.setInvocationManager(im);

	// Initialize Transaction service. By now the ORB must have
	// been created during the new InitialContext() call using
	// the ORBManager
	PEORBConfigurator.initTransactionService(null, new Properties() );
	
	/* Create the transaction manager and set it in the switch. */
	// J2EETransactionManager tm = new J2EETransactionManagerImpl();
	J2EETransactionManager tm = 
		J2EETransactionManagerImpl.createTransactionManager();
	sw.setTransactionManager(tm);

        /* Create the naming manager and set it in the switch. */
	sw.setNamingManager(new NamingManagerImpl(result));

        // Create the Injection Manager and set it on the switch.
        InjectionManager injectionMgr = new InjectionManagerImpl();
        sw.setInjectionManager(injectionMgr);               

        return result;
    
public voidperformUserLogin()

	/* Login the user. */
	// eager authentication!
	boolean doLogin = 
	    Boolean.valueOf(System.getProperty("startup.login", "false")).booleanValue();
	if(doLogin) {
            _logger.info("acc.init_login");
	    String loginMech = System.getProperty(
		"com.sun.enterprise.loginMech", "password");
	    if(loginMech.equalsIgnoreCase("ssl")) {
		LoginContextDriver.doClientLogin(CERTIFICATE, handler);
	    } else if(loginMech.equalsIgnoreCase("all")) {
		LoginContextDriver.doClientLogin(ALL, handler);
	    } else {
		LoginContextDriver.doClientLogin(USERNAME_PASSWORD, handler);
	    }
	}
    
public voidpostInvoke()
This is called by the main after the real main of the application is invoked. Performs cleanup.

	nm.unbindObjects(descriptor);
    
public java.lang.StringpreInvoke(java.util.Properties props)
This is called by main before the actual main of the application is invoked. It initializes the container and performs login for the user.

return
the main class of the application.

        return preInvoke(initializeNaming(props), Thread.currentThread().getContextClassLoader());
    
public java.lang.StringpreInvoke(javax.naming.InitialContext ic, java.lang.ClassLoader loader)
This is called by main before the actual main of the application is invoked. It initializes the container and performs login for the user.

return
the main class of the application.

	ComponentInvocation ci = new ComponentInvocation(null, this);

	sw.getInvocationManager().preInvoke(ci);
 	
	// Do security setup
	String callbackHandler = descriptor.getCallbackHandler();
        
	_logger.fine("Callback Handler:" + callbackHandler);
        
	initializeCallbackHandler(callbackHandler, loader);
	
        performUserLogin();

	String mainClass = descriptor.getMainClassName();
	sw.setDescriptorFor(this, descriptor);
        
        nm = Switch.getSwitch().getNamingManager();
	nm.bindObjects(descriptor);

	return mainClass;