aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/protocol/icq/IcqActivator.java
blob: 2406f3e1fa5e7d6502474a87f2b787bc47ebd64a (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package net.java.sip.communicator.impl.protocol.icq;

import java.util.*;

import org.osgi.framework.*;

import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.resources.*;

/**
 * Loads the  ICQ provider factory and registers it with  service in the OSGI
 * bundle context.
 *
 * @author Emil Ivov
 */
public class IcqActivator
    implements BundleActivator
{
    private        ServiceRegistration  icqPpFactoryServReg   = null;
    private        ServiceRegistration  aimPpFactoryServReg   = null;
            static BundleContext        bundleContext         = null;
    private static ConfigurationService configurationService  = null;

    private static ProtocolProviderFactoryIcqImpl icqProviderFactory = null;
    private static ProtocolProviderFactoryIcqImpl aimProviderFactory = null;

    private static ResourceManagementService resourceService;

    /**
     * Called when this bundle is started so the Framework can perform the
     * bundle-specific activities necessary to start this bundle.
     *
     * @param context The execution context of the bundle being started.
     * @throws Exception If this method throws an exception, this bundle is
     *   marked as stopped and the Framework will remove this bundle's
     *   listeners, unregister all services registered by this bundle, and
     *   release all services used by this bundle.
     */
    public void start(BundleContext context) throws Exception
    {
        IcqActivator.bundleContext = context;

        Hashtable<String, String> icqHashtable = new Hashtable<String, String>();
        icqHashtable.put(ProtocolProviderFactory.PROTOCOL, ProtocolNames.ICQ);
        
        Hashtable<String, String> aimHashtable = new Hashtable<String, String>();
        aimHashtable.put(ProtocolProviderFactory.PROTOCOL, ProtocolNames.AIM);

        icqProviderFactory = new ProtocolProviderFactoryIcqImpl(false);
        aimProviderFactory = new ProtocolProviderFactoryIcqImpl(true);

        //reg the icq account man.
        icqPpFactoryServReg =  context.registerService(
                    ProtocolProviderFactory.class.getName(),
                    icqProviderFactory,
                    icqHashtable);
        
        aimPpFactoryServReg =  context.registerService(
                    ProtocolProviderFactory.class.getName(),
                    aimProviderFactory,
                    aimHashtable);
    }

    /**
     * Returns a reference to a ConfigurationService implementation currently
     * registered in the bundle context or null if no such implementation was
     * found.
     *
     * @return ConfigurationService a currently valid implementation of the
     * configuration service.
     */
    public static ConfigurationService getConfigurationService()
    {
        if(configurationService == null)
        {
            ServiceReference confReference
                = bundleContext.getServiceReference(
                    ConfigurationService.class.getName());
            configurationService
                = (ConfigurationService) bundleContext.getService(confReference);
        }
        return configurationService;
    }

    /**
     * Returns a reference to the bundle context that we were started with.
     * @return a reference to the BundleContext instance that we were started
     * witn.
     */
    public static BundleContext getBundleContext()
    {
        return bundleContext;
    }

    /**
     * Retrurns a reference to the protocol provider factory that we have
     * registered for icq accounts.
     * @return a reference to the <tt>ProtocolProviderFactoryIcqImpl</tt>
     * instance that we have registered from this package.
     */
    static ProtocolProviderFactoryIcqImpl getIcqProtocolProviderFactory()
    {
        return icqProviderFactory;
    }

    /**
     * Retrurns a reference to the protocol provider factory that we have
     * registered for aim accounts.
     * @return a reference to the <tt>ProtocolProviderFactoryIcqImpl</tt>
     * instance that we have registered from this package.
     */
    static ProtocolProviderFactoryIcqImpl getAimProtocolProviderFactory()
    {
        return aimProviderFactory;
    }

    /**
     * Called when this bundle is stopped so the Framework can perform the
     * bundle-specific activities necessary to stop the bundle.
     *
     * @param context The execution context of the bundle being stopped.
     * @throws Exception If this method throws an exception, the bundle is
     *   still marked as stopped, and the Framework will remove the bundle's
     *   listeners, unregister all services registered by the bundle, and
     *   release all services used by the bundle.
     */
    public void stop(BundleContext context) throws Exception
    {
        icqProviderFactory.stop();
        icqPpFactoryServReg.unregister();
        
        aimPpFactoryServReg.unregister();
    }
    
    /**
     * Returns an instance of the <tt>ResourceManagementService<tt>.
     * 
     * @return an instance of the <tt>ResourceManagementService<tt>.
     */
    public static ResourceManagementService getResources()
    {
        if (resourceService == null)
        {
            ServiceReference serviceReference = bundleContext
                .getServiceReference(ResourceManagementService.class.getName());

            if(serviceReference == null)
                return null;

            resourceService = (ResourceManagementService) bundleContext
                .getService(serviceReference);
        }

        return resourceService;
    }
}