summaryrefslogtreecommitdiffstats
path: root/tags/java/sca/2.0-M3-RC4/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java
blob: e2abcf08e4e0ac38235afc5767b8630eeea662af (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* 
 * Copyright(C) OASIS(R) 2005,2009. All Rights Reserved. 
 * OASIS trademark, IPR and other policies apply. 
 */
package org.oasisopen.sca.client;

import java.util.Properties;

import org.oasisopen.sca.client.impl.SCAClientFactoryFinder;

/**
 * The SCAClientFactory can be used by non-SCA managed code to lookup services
 * that exist in a SCADomain.
 * 
 * @see SCAClientFactoryFinder
 * @see SCAClient
 * @author OASIS Open
 */
public abstract class SCAClientFactory {

    /**
     * The default implementation of the SCAClientFactory. A Vendor may use
     * reflection to inject a default SCAClientFactory instance that will be
     * used in the newInstance() methods rather than using the
     * SCAClientFactoryFinder.
     */
    protected static SCAClientFactory defaultFactory;

    /**
     * Creates a new instance of the SCAClient that can be used to lookup SCA
     * Services.
     * 
     * @return A new SCAClient
     */
    public static SCAClient newInstance() {
        return newInstance(null, null);
    }

    /**
     * Creates a new instance of the SCAClient that can be used to lookup SCA
     * Services.
     * 
     * @param properties Properties that may be used when creating a new
     *                instance of the SCAClient
     * @return A new SCAClient instance
     */
    public static SCAClient newInstance(Properties properties) {
        return newInstance(properties, null);
    }

    /**
     * Creates a new instance of the SCAClient that can be used to lookup SCA
     * Services.
     * 
     * @param classLoader ClassLoader that may be used when creating a new
     *                instance of the SCAClient
     * @return A new SCAClient instance
     */
    public static SCAClient newInstance(ClassLoader classLoader) {
        return newInstance(null, classLoader);
    }

    /**
     * Creates a new instance of the SCAClient that can be used to lookup SCA
     * Services.
     * 
     * @param properties Properties that may be used when creating a new
     *                instance of the SCAClient
     * @param classLoader ClassLoader that may be used when creating a new
     *                instance of the SCAClient
     * @return A new SCAClient instance
     */
    public static SCAClient newInstance(Properties properties, ClassLoader classLoader) {
        final SCAClientFactory factory;
        if (defaultFactory == null) {
            factory = SCAClientFactoryFinder.find(properties, classLoader);
        } else {
            factory = defaultFactory;
        }
        return factory.createSCAClient();
    }

    /**
     * This method is invoked to create a new SCAClient instance.
     * 
     * @return A new SCAClient instance
     */
    protected abstract SCAClient createSCAClient();
}