KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > base > IpanemaBasePlugin


1 package com.nightlabs.ipanema.base;
2
3 import java.util.MissingResourceException JavaDoc;
4 import java.util.ResourceBundle JavaDoc;
5
6 import javax.security.auth.login.LoginException JavaDoc;
7
8 import org.apache.log4j.Logger;
9 import org.eclipse.jface.action.IAction;
10 import org.eclipse.ui.plugin.AbstractUIPlugin;
11 import org.osgi.framework.BundleContext;
12
13 import com.nightlabs.ipanema.base.login.Login;
14 import com.nightlabs.ipanema.base.login.LoginStateListener;
15 import com.nightlabs.ipanema.person.PersonManager;
16
17 /**
18  * The main plugin class to be used in the desktop.
19  */

20 public class IpanemaBasePlugin
21     extends AbstractUIPlugin
22     implements LoginStateListener
23 {
24     
25     public static final String JavaDoc ZONE_ADMIN = IpanemaBasePlugin.class.getName() + "#ZONE_ADMIN";
26     
27     
28     //The shared instance.
29
private static IpanemaBasePlugin plugin;
30     //Resource bundle.
31
private ResourceBundle JavaDoc resourceBundle;
32     
33     /**
34      * The constructor registeres this plugin
35      * as LoginStateListener.
36      *
37      */

38     public IpanemaBasePlugin() {
39         super();
40         plugin = this;
41         try {
42             resourceBundle = ResourceBundle.getBundle("com.nightlabs.ipanema.base.plugin");
43         } catch (MissingResourceException JavaDoc x) {
44             resourceBundle = null;
45         }
46     }
47
48     /**
49      * This method is called upon plug-in activation
50      */

51     public void start(BundleContext context) throws Exception JavaDoc {
52         super.start(context);
53 // Login.addLoginStateListener(this);
54
// LOGGER.debug("Registered IpanemaBasePlugin as LoginStateListener");
55
// LanguageWatcher.registerAsLoginStateListener();
56
// LOGGER.debug("Registered LanguageWatcher as LoginStateListener");
57
}
58
59     /**
60      * This method is called when the plug-in is stopped
61      */

62     public void stop(BundleContext context) throws Exception JavaDoc {
63         super.stop(context);
64     }
65
66     /**
67      * Returns the shared instance.
68      */

69     public static IpanemaBasePlugin getDefault() {
70         return plugin;
71     }
72
73     /**
74      * Returns the string from the plugin's resource bundle,
75      * or 'key' if not found.
76      */

77     public static String JavaDoc getResourceString(String JavaDoc key) {
78         ResourceBundle JavaDoc bundle = IpanemaBasePlugin.getDefault().getResourceBundle();
79         try {
80             return (bundle != null) ? bundle.getString(key) : key;
81         } catch (MissingResourceException JavaDoc e) {
82             return key;
83         }
84     }
85
86     /**
87      * Returns the plugin's resource bundle,
88      */

89     public ResourceBundle JavaDoc getResourceBundle() {
90         return resourceBundle;
91     }
92
93     /**
94      * Calls {@link com.nightlabs.ipanema.person.PersonStructCache#initialize(PersonManager)
95      * when logged in.
96      *
97      * @see com.nightlabs.ipanema.base.login.LoginStateListener#loginStateChanged(int, org.eclipse.jface.action.IAction)
98      */

99     public void loginStateChanged(int loginState, IAction action) {
100         if (loginState == Login.LOGINSTATE_LOGGED_IN) {
101         Login login = null;
102         PersonManager personManager = null;
103         try {
104           login = Login.getLogin();
105         } catch (LoginException JavaDoc e) {
106             Logger.getLogger(this.getClass()).error("Error getting login.",e);
107         }
108 // PersonManagerHome home = null;
109
// try {
110
// home = PersonManagerUtil.getHome(login.getInitialContextProperties());
111
// } catch (Exception e) {
112
// LOGGER.error("Error getting PersonManagerHome.",e);
113
// }
114
// try {
115
// personManager = home.create();
116
// } catch (Exception e) {
117
// LOGGER.error("Error creating PersonManager.",e);
118
// }
119
// PersonStructCache.initialize(personManager);
120
}
121     }
122
123 }
124
Popular Tags