View Javadoc

1   /*
2    * Created on Apr 25, 2005, Copyright UC Regents
3    */
4   package net.sf.sail.common.example;
5   
6   import java.beans.beancontext.BeanContextServices;
7   import java.util.TooManyListenersException;
8   import java.util.logging.Logger;
9   
10  import javax.swing.JOptionPane;
11  
12  import net.sf.sail.common.beansupport.ITitleAware;
13  import net.sf.sail.common.beansupport.SailBeanContextChildSupport;
14  import net.sf.sail.core.beans.event.SessionEvent;
15  import net.sf.sail.core.beans.event.SessionEventListener;
16  import net.sf.sail.core.beans.service.SessionService;
17  
18  /**
19   * Bean which displays a dialog box when the session starts.
20   * 
21   * @author turadg
22   */
23  public class BasicExampleSessionListeningBean extends SailBeanContextChildSupport implements
24  		ITitleAware {
25  	/**
26  	 * Logger for this class
27  	 */
28  	private static final Logger logger = Logger
29  			.getLogger(BasicExampleSessionListeningBean.class.getName());
30  
31  	private static final long serialVersionUID = 1L;
32  
33  	private SessionService sessionService;
34  
35  	SessionEventListener sessionListener = new SessionEventListener() {
36  
37  		public void sessionInitiated(SessionEvent e) {
38  		}
39  
40  		public void sessionStarted(SessionEvent e) {
41  			initializeUI();
42  		}
43  
44  		public void sessionStopped(SessionEvent e) {
45  		}
46  
47  	};
48  
49  	private String title = "untitled BasicRootPodBean";
50  
51  	protected void registerDesiredServices(BeanContextServices bcs) {
52  		// TODO why can this be empty?
53  	}
54  
55  	protected void initializeUI() {
56  		JOptionPane.showMessageDialog(null, "hello from " + title);
57  	}
58  
59  	/**
60  	 * This method can be called more than once in the authoring runtime, when
61  	 * the preview is shown more than once.
62  	 * 
63  	 * @param bcs
64  	 * @param serviceClass
65  	 * @param project
66  	 */
67  	@SuppressWarnings("unchecked")
68  	protected void consumeService(BeanContextServices bcs, Class serviceClass) {
69  		if (serviceClass == SessionService.class) {
70  			try {
71  				sessionService = (SessionService) bcs.getService(this, this,
72  						SessionService.class, this, this);
73  				sessionService.addSessionEventListener(sessionListener);
74  			} catch (TooManyListenersException e1) {
75  				// TODO Auto-generated catch block
76  				logger
77  						.severe("BeanContextServices, Class -  : exception: " + e1); //$NON-NLS-1$
78  			}
79  		}
80  	}
81  
82  	/**
83  	 * @return the sessionService
84  	 */
85  	public SessionService getSessionService() {
86  		return sessionService;
87  	}
88  
89  	/**
90  	 * @param sessionService
91  	 *            the sessionService to set
92  	 */
93  	public void setSessionService(SessionService sessionService) {
94  		this.sessionService = sessionService;
95  	}
96  
97  	public String getTitle() {
98  		return title;
99  	}
100 
101 	public void setTitle(String title) {
102 		this.title = title;
103 	}
104 }