KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > jnlp > ServiceManager


1 /*
2  * @(#)ServiceManager.java 1.11 04/03/12
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.jnlp;
9
10 /**
11  * The <code>ServiceManager</code> provides static methods to lookup JNLP services. This class
12  * is abstract and final and cannot be instantiated.
13  * <p>
14  * Requests are delegated to a <code>ServiceManagerStub</code>
15  * object. This object must be set by the JNLP Client on startup using the
16  * <code>setServiceManagerStub</code> method.
17  *
18  * @since 1.0
19  *
20  * @see ServiceManagerStub
21  */

22 public final class ServiceManager {
23     static private ServiceManagerStub _stub = null;
24     
25     /** Private constructor in order to prevent instantiation */
26     private ServiceManager() { /* dummy */ }
27
28     /**
29      * Asks the JNLP Client for a service with a given name. The lookup
30      * must be idempotent, that is return the same object for each invocation
31      * with the same name.
32      *
33      * @param name Name of service to lookup.
34      *
35      * @return An object implementing the service. <code>null</code>
36      * will never be returned. Instead an exception will be thrown.
37      *
38      * @exception <code>UnavailableServiceException</code> if the service is not available, or if <code>name</code> is null.
39      */

40     public static Object lookup(String name) throws UnavailableServiceException {
41     if (_stub != null) {
42         return _stub.lookup(name);
43     } else {
44         throw new UnavailableServiceException("uninitialized");
45     }
46     }
47     
48     /**
49      * Returns the names of all services implemented by the JNLP Client.
50      */

51     public static String[] getServiceNames() {
52     if (_stub != null) {
53         return _stub.getServiceNames();
54     } else {
55         return null;
56     }
57     }
58     
59     /**
60      * Sets the object that all <code>lookup</code> and <code>getServiceNames</code>
61      * requests are delegated to. The <code>setServiceManagerStub</code> call is ignored
62      * if the stub has already been set.
63      * <p>
64      * This method should be called exactly once by the JNLP Client, and never be
65      * called by a launched application.
66      *
67      * @param stub The ServiceManagerStub object to delegate to
68      */

69     public static synchronized void setServiceManagerStub(ServiceManagerStub stub) {
70     if (_stub == null) {
71         _stub = stub;
72     }
73     }
74 }
75
76
Popular Tags