aboutsummaryrefslogtreecommitdiffstats
path: root/netx/javax/jnlp/ServiceManager.java
blob: 2f35a6f1700de1f09a409939335b4ca9e4504f6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package javax.jnlp;

import java.util.*;

public final class ServiceManager {

    private static ServiceManagerStub stub = null;

    private static Map<String, Object> lookupTable = new HashMap<String, Object>(); // ensure lookup is idempotent

    private ServiceManager() {
        // says it can't be instantiated
    }

    public static java.lang.Object lookup(java.lang.String name) throws UnavailableServiceException {
        if (stub == null)
            throw new UnavailableServiceException("service stub not set.");

        synchronized (lookupTable) {
            Object result = lookupTable.get(name);

            if (result == null) {
                result = stub.lookup(name);
                if (result != null)
                    lookupTable.put(name, result);
            }

            if (result == null)
                throw new UnavailableServiceException("service not available (stub returned null).");

            return result;
        }
    }

    public static java.lang.String[] getServiceNames() {
        // should this return the required ones even though no stub??
        if (stub == null)
            return new String[0];

        return stub.getServiceNames();
    }

    public static void setServiceManagerStub(ServiceManagerStub stub) {
        if (ServiceManager.stub == null)
            ServiceManager.stub = stub;
    }

}