aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/version/VersionActivator.java
blob: 907fae0f3486fcb3e128e399358517601b13ffd6 (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
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.version;

import net.java.sip.communicator.util.*;

import org.jitsi.service.configuration.*;
import org.jitsi.service.version.*;
import org.jitsi.service.version.Version;
import org.osgi.framework.*;

/**
 * The entry point to the Version Service Implementation. We register the
 * VersionServiceImpl instance on the OSGi BUS.
 *
 * @author Emil Ivov
 */
public class VersionActivator
    implements BundleActivator
{
    /**
     * The <tt>Logger</tt> used by this <tt>VersionActivator</tt> instance for
     * logging output.
     */
    private final Logger logger = Logger.getLogger(VersionActivator.class);

    /**
     * The OSGi <tt>BundleContext</tt>.
     */
    private static BundleContext bundleContext;

    /**
     * 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
    {
        if (logger.isDebugEnabled())
            logger.debug("Started.");

        VersionActivator.bundleContext = context;

        context.registerService(
                VersionService.class.getName(),
                new VersionServiceImpl(),
                null);

        if (logger.isDebugEnabled())
            logger.debug("Jitsi Version Service ... [REGISTERED]");

        Version version = VersionImpl.currentVersion();
        String applicationName = version.getApplicationName();
        String versionString = version.toString();

        if (logger.isInfoEnabled())
        {
            logger.info(
                    "Jitsi Version: " + applicationName + " " + versionString);
        }

        //register properties for those that would like to use them
        ConfigurationService cfg = getConfigurationService();

        cfg.setProperty(Version.PNAME_APPLICATION_NAME, applicationName, true);
        cfg.setProperty(Version.PNAME_APPLICATION_VERSION, versionString, true);
    }

    /**
     * Gets a <tt>ConfigurationService</tt> implementation currently
     * registered in the <tt>BundleContext</tt> in which this bundle has been
     * started or <tt>null</tt> if no such implementation was found.
     *
     * @return a <tt>ConfigurationService</tt> implementation currently
     * registered in the <tt>BundleContext</tt> in which this bundle has been
     * started or <tt>null</tt> if no such implementation was found
     */
    private static ConfigurationService getConfigurationService()
    {
        return
            ServiceUtils.getService(bundleContext, ConfigurationService.class);
    }

    /**
     * Gets the <tt>BundleContext</tt> instance within which this bundle has
     * been started.
     *
     * @return the <tt>BundleContext</tt> instance within which this bundle has
     * been started
     */
    public static BundleContext getBundleContext()
    {
        return bundleContext;
    }

    /**
     * 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
    {
    }
}