| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 
 |  
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.logging.Logger;
 
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
 
import com.olivier.OlivierBeanRemote;
 
 
public class Main {
 
	@EJB(mappedName="ejb/OlivierBean")
	private OlivierBeanRemote ejb;
 
	public static void main(String[] args) {
		Main m = new Main();
		m.launch();
	}
 
	public Main() {
		super();
	}
 
	private void launch(){		
 
		JFrame jf = new JFrame("test");
		jf.setSize(800, 400);
		jf.setLocationRelativeTo(null);
 
		JPanel content = new JPanel();
		content.setBackground(Color.CYAN);	
		content.setLayout(new GridLayout(3, 1));
 
		JButton jb = new JButton();
		jb.setText("test ejb injection");
 
		JButton jb2 = new JButton();
		jb2.setText("test ejb lookup");
 
		final JTextArea jta = new JTextArea(20, 20);
		jta.setBackground(Color.yellow);
 
		jb.addActionListener(new ActionListener() {			
			@Override
			public void actionPerformed(ActionEvent e) {
				String result = (null == ejb) ? "null" : "pas null";
				jta.setText(jta.getText() + "ejb réf : " + result + "\n");	
			}
		});
 
		jb2.addActionListener(new ActionListener() {			
			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					Context c = new InitialContext();
					OlivierBeanRemote ejb = (OlivierBeanRemote)c.lookup("java:global/oli_ear/oli_ejb/OlivierBean!com.olivier.OlivierBeanRemote");
 
					/*ejb.testLogin();	
					System.out.println(ejb.test());*/
					String result = (null == ejb) ? "null" : "pas null";
					jta.setText(jta.getText() + "ejb lookup : " + result + "\n");
				} catch (NamingException e2) {
					jta.setText(jta.getText() + e2.getMessage());
				}
			}
		});
 
		content.add(jb);	
		content.add(jb2);	
		content.add(jta);				
 
		jf.setContentPane(content);
 
		jf.setVisible(true);
 
		try {
			Class<?> c = Class.forName("com.sun.corba.ee.org.objectweb.asm.AnnotationVisitor");
			jta.setText("trouvé");
		} catch (ClassNotFoundException e1) {
			jta.setText(e1.getMessage());
		}
 
	}
 
} | 
Partager