📄 loaddataservletctxlsnr.java
字号:
/*
* @author : Elangovan
* @version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : LoadDataServletCtxLsnr.java
*
* Creation / Modification History
* Elangovan 28-Aug-2003 Created
*
*/
package oracle.otnsamples.ibfbs.admin.helper;
import javax.naming.InitialContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import oracle.otnsamples.ibfbs.utils.ConnectionParams;
import oracle.otnsamples.ibfbs.usermanagement.ejb.UserManagementSessionRemote;
import oracle.otnsamples.ibfbs.usermanagement.ejb.UserManagementSessionHomeRemote;
/**
* This class is invoked by the container when the servlet context of this web
* application is initialized. Checks if the sample data has been loaded, else
* loads them. This listener class is specified in the Web application deployment
* descriptor (web.xml), when the container parses web.xml it registers this listener.
*
* @see DataPopulator.java
* @see SampleData.java
*/
public class LoadDataServletCtxLsnr
implements ServletContextListener {
/**
* Initializes a new instance of LoadDataServletCtxListener.
*/
public LoadDataServletCtxLsnr() { }
/**
* This method is invoked by the container when the servletcontext is initialized.
*
* @param sce ServletContext event details
*/
public void contextInitialized(ServletContextEvent sce) {
System.out.println("Debug: ServletContext initialized ");
// Create tables, sequences and load sample data ( if they donot exist )
DataPopulator loader = new DataPopulator();
try {
loader.populateSampleData();
}catch(Exception ex) {
System.err.println("Fatal Error loading sample data :"+ex.toString());
}
// Create admin account
this.populateAdminUser();
}
/**
* This method is called by container when servlet context is destroyed.
*
* @param sce ServletContext event details
*/
public void contextDestroyed(ServletContextEvent sce) { }
/**
* This method checks if Admin user account has been created. Creates a new
* account if Admin user does not exist.
*
*/
private void populateAdminUser() {
// Reference to rmote interface of Usermanagement session bean
UserManagementSessionRemote rmr = null;
Integer accountNumber = null;
try {
InitialContext ctx = new InitialContext();
// Bind 'NTFY_MAIL' with the notification mail id
// This name will be used by other Session EJB's for sending notification
// mails
ctx.rebind("NTFY_MAIL", ConnectionParams.notificationMailId);
// Initialize the Home Interface for 'UserManagementSessionFacadeBean'
UserManagementSessionHomeRemote rmrh = (UserManagementSessionHomeRemote)
ctx.lookup("java:comp/env/ejb/UserManagementSessionHomeRemote");
// Initialize Remote Interface
rmr = rmrh.create();
synchronized(rmr) {
// Create Admin account
accountNumber = rmr.createAdminAccount();
}
if(accountNumber.intValue() != 0)
System.out.println(" Admin user created with Account Number : "
+accountNumber+ " and password : welcome ");
} catch (Exception ex) {
System.err.println("Error creating admin account :"+ex.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -