KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > WebStartContext


1 /*
2  * $Id: WebStartContext.java,v 1.2 2004/08/30 22:05:30 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing;
9
10 import java.net.URL JavaDoc;
11
12 import javax.jnlp.BasicService;
13 import javax.jnlp.ServiceManager;
14 import javax.jnlp.UnavailableServiceException;
15
16 /**
17  * A class that provides the similar services to AppletContext for Java WebStarted
18  * applications.
19  */

20 class WebStartContext {
21
22     private static WebStartContext INSTANCE;
23
24     private WebStartContext() {}
25
26     public static WebStartContext getInstance() {
27     if (INSTANCE == null) {
28         INSTANCE = new WebStartContext();
29     }
30     return INSTANCE;
31     }
32
33     /**
34      * Retrieves the web start basic service.
35      * @return the basic service instance or null if it is not available.
36      */

37     BasicService getBasicService() {
38     BasicService bs = null;
39     try {
40         bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
41     } catch (UnavailableServiceException ex) {
42         // XXX - handle better.
43
System.err.println("WebStartContext - BasicServiceUnavaiable");
44     }
45     return bs;
46     }
47     
48     public void showDocument(URL JavaDoc url, String JavaDoc target) {
49     BasicService bs = getBasicService();
50     if (bs != null) {
51         if (bs.showDocument(url) == false) {
52         // XXX -
53
System.err.println("WebStartContext - Error showing url: " + url);
54         }
55     }
56     }
57
58     /**
59      * Returns the codebase URL of the application. The code base is either specified
60      * directly in the JNLP file or it's the location of the jar file containing
61      * the main class of the application.
62      *
63      * @return the url of the code base or null.
64      */

65     public URL JavaDoc getDocumentBase() {
66     BasicService bs = getBasicService();
67     if (bs != null) {
68         return bs.getCodeBase();
69     }
70     return null;
71     }
72 }
73
Popular Tags