001: package com.sun.portal.netlet.client.jnlp;
002:
003: import com.sun.portal.netlet.client.jnlp.connect.ClientListener;
004: import com.sun.portal.netlet.client.jnlp.ui.SRAContentPane;
005: import com.sun.portal.netlet.client.common.ResourceProperties;
006: import com.sun.portal.netlet.client.common.ClientUtil;
007: import com.sun.portal.netlet.client.common.NetletErrorDialog;
008:
009: import java.util.*;
010: import java.awt.event.WindowAdapter;
011: import java.awt.event.WindowEvent;
012: import java.awt.event.ActionListener;
013: import java.awt.event.ActionEvent;
014: import java.awt.*;
015: import javax.jnlp.ServiceManager;
016: import javax.jnlp.BasicService;
017: import javax.jnlp.UnavailableServiceException;
018: import javax.swing.*;
019:
020: public class ClientManager extends WindowAdapter implements
021: ActionListener {
022:
023: private static ClientManager clientManager = null;
024: private static NetletHandler netletHandler = null;
025: private static ProxyletHandler proxyletHandler = null;
026: private static ClientListener cl = null;
027: private static SRAContentPane sraContentPane = null;
028: private static JFrame sraClientWindow = null;
029: private static Hashtable parameters = new Hashtable();
030: private NetletErrorDialog cbiped = null;
031:
032: private static BasicService bs;
033:
034: public static void main(String[] args) {
035: if (clientManager == null) {
036: clientManager = new ClientManager(args);
037: }
038: }
039:
040: private ClientManager(String args[]) {
041: initParams(args);
042: if (netletHandler == null) {
043: netletHandler = new NetletHandler(parameters);
044: }
045: if (proxyletHandler == null) {
046: proxyletHandler = new ProxyletHandler(parameters);
047: }
048:
049: initResources();
050:
051: //TODO: Do different error handling in case of JWS
052: cbiped = new NetletErrorDialog(new Frame(), this ,
053: ResourceProperties.getString("cbiped.1"),
054: ResourceProperties.getString("cbiped.2"));
055:
056: String cbip = getParam("clientBindIP");
057: if (!ClientUtil.isClientBindIPValid(cbip)) {
058: // pop up error dialog
059: cbiped.setErrorMessage(ResourceProperties
060: .getString("cbiped.3")
061: + " "
062: + cbip
063: + ". "
064: + ResourceProperties.getString("cbiped.4"));
065: cbiped.setVisible(true);
066: cbiped.toFront();
067: cbiped.waitForAction();
068: System.exit(0);
069: }
070:
071: initJnlpServices();
072: startClientListener();
073:
074: String startNetlet = (String) parameters.get("startNetlet");
075: if (startNetlet != null && startNetlet.equalsIgnoreCase("true")) {
076: // Parameters already loaded
077: netletHandler.setNetletLoaded();
078: netletHandler.startClient();
079: }
080:
081: String startProxylet = (String) parameters.get("startProxylet");
082: if (startProxylet != null
083: && startProxylet.equalsIgnoreCase("true")) {
084: //TODO : PROXYLET
085:
086: }
087:
088: showUI();
089: }
090:
091: private void initParams(String args[]) {
092: int i = 0;
093: while (i < args.length) {
094: parameters.put(args[i], args[++i]);
095: ++i;
096: }
097: }
098:
099: private void initResources() {
100: String res;
101: // TODO : Seperate properties for JWS
102: if ((res = getParam("resourceBundle")) != null) {
103: ResourceProperties.loadResources(res);
104: } else {
105: ResourceProperties.loadResources();
106: }
107: }
108:
109: private void startClientListener() {
110: System.out.println("startClientListener");
111: if (cl == null) {
112: cl = new ClientListener(45000);
113: cl.start();
114: }
115: }
116:
117: private void showUI() {
118: javax.swing.SwingUtilities.invokeLater(new Runnable() {
119: public void run() {
120: //JWSPanel.createAndShowGUI(clientManager);
121: JFrame.setDefaultLookAndFeelDecorated(true);
122:
123: //Create and set up the window.
124: sraClientWindow = new JFrame(ResourceProperties
125: .getString("jws.sraFrame"));
126: sraClientWindow.setSize(350, 350);
127: sraClientWindow.setResizable(false);
128:
129: sraContentPane = new SRAContentPane();
130: sraContentPane.setOpaque(true); //content panes must be opaque
131: sraClientWindow.getContentPane().add(sraContentPane);
132: //sraClientWindow.getContentPane().setSize(300, 300);
133: sraClientWindow.addWindowListener(clientManager);
134: //Display the window.
135: sraClientWindow.pack();
136: sraClientWindow.setVisible(true);
137: }
138: });
139: }
140:
141: private void initJnlpServices() {
142: try {
143: bs = (BasicService) ServiceManager
144: .lookup("javax.jnlp.BasicService");
145: } catch (UnavailableServiceException e) {
146: System.out.println("UnavailableServiceException " + e);
147: bs = null;
148: }
149: }
150:
151: public static ClientManager getInstance() {
152: return clientManager;
153: }
154:
155: public static NetletHandler getNetletHandler() {
156: return netletHandler;
157: }
158:
159: public static ProxyletHandler getProxyletHandler() {
160: return proxyletHandler;
161: }
162:
163: public static ClientListener getClientListener() {
164: return cl;
165: }
166:
167: public static SRAContentPane getSRAContentPane() {
168: return sraContentPane;
169: }
170:
171: public static JFrame getSRAClientWindow() {
172: return sraClientWindow;
173: }
174:
175: public void windowClosing(WindowEvent e) {
176: stopProcessing();
177: }
178:
179: public static String getParam(String name) {
180: return (String) parameters.get(name);
181: }
182:
183: public static BasicService getBasicService() {
184: return bs;
185: }
186:
187: public static String getCodeBaseUrl() {
188: String cbUrl = null;
189: if (bs != null) {
190: cbUrl = bs.getCodeBase().toString();
191: }
192: return cbUrl;
193: }
194:
195: public static void stopProcessing() {
196: if (cl != null) {
197: cl.close();
198: }
199: if (netletHandler != null) {
200: netletHandler.unloadNetlet();
201: }
202: System.exit(0);
203: }
204:
205: public void actionPerformed(ActionEvent evt) {
206: if ("OK".equals(evt.getActionCommand())) {
207: Object obj = evt.getSource();
208: if (obj == cbiped.okButton) {
209: cbiped.notifyAction();
210: cbiped.setVisible(false);
211: }
212: }
213: }
214: }
|