package cc.test.client;
import cc.test.ejb.CCSessionBeanRemote;
import java.sql.Time;
import java.util.Date;
import java.util.Hashtable;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Context;
/**
*
* @author dev
*/
public class LoginJFrame extends javax.swing.JFrame {
/**
* Creates new form JFrame
*/
public LoginJFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
messageLabel = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("EJB鏈接測試");
jButton1.setText("鏈接EJB glassfish");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(129, 129, 129)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(messageLabel)
.addComponent(jLabel1)))
.addGroup(layout.createSequentialGroup()
.addGap(92, 92, 92)
.addComponent(jButton1)))
.addContainerGap(173, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(107, 107, 107)
.addComponent(messageLabel)
.addGap(40, 40, 40)
.addComponent(jButton1)
.addContainerGap(105, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
try {
Date d = new Date();
Hashtable env = new Hashtable();
//GlassFish
env.put("org.omg.CORBA.ORBInitialHost", "localhost");
env.put("org.omg.CORBA.ORBInitialPort", "3700");
//Jboss
/* env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
env.put(Context.SECURITY_PRINCIPAL,"user");//用戶名
env.put(Context.SECURITY_CREDENTIALS, "user");//密碼
env.put("jboss.naming.client.ejb.context", true);
*/
Context context = new InitialContext(env);
Logger.getLogger(LoginJFrame.class.getName()).log(Level.WARNING,String.valueOf(new Date().getTime()-d.getTime()));
/**
* 1."cc.test.ejb.CCSessionBeanRemote"
* 2.CCSessionBeanRemote.class.getName()
* 3.java:global/CCEnterpriseApplication/CCSessionBean
* 4.CCEnterpriseApplication/CCEnterpriseApplication-ejb/CCSessionBean!cc.test.ejb.CCSessionBeanRemote"
*
*/
// CCSessionBeanRemote ccSession = (CCSessionBeanRemote)context.lookup("CCEnterpriseApplication/CCEnterpriseApplication-ejb/CCSessionBean!"+CCSessionBeanRemote.class.getName());
CCSessionBeanRemote ccSession = (CCSessionBeanRemote)context.lookup(CCSessionBeanRemote.class.getName());
Logger.getLogger(LoginJFrame.class.getName()).log(Level.WARNING,String.valueOf(new Date().getTime()-d.getTime()));
this.messageLabel.setText(ccSession.checkConn());
Logger.getLogger(LoginJFrame.class.getName()).log(Level.WARNING,String.valueOf(new Date().getTime()-d.getTime()));
// CCSessionBeanRemote ccSession2 = (CCSessionBeanRemote)context.lookup("CCEnterpriseApplication/CCEnterpriseApplication-ejb/CCSessionBean!"+CCSessionBeanRemote.class.getName());
Logger.getLogger(LoginJFrame.class.getName()).log(Level.WARNING,String.valueOf(new Date().getTime()-d.getTime()));
} catch (NamingException ex) {
Logger.getLogger(LoginJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_jButton1MouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(LoginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(LoginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(LoginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(LoginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoginJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel messageLabel;
// End of variables declaration//GEN-END:variables
}