blob: ed4f1238dadb9fa0c590c381734cb8ebf4e9001a (
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
|
/*
* 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.argdelegation;
import java.lang.reflect.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.launchutils.*;
import org.jitsi.util.*;
import org.osgi.framework.*;
import com.apple.eawt.*;
/**
* Activates the <tt>ArgDelegationService</tt> and registers a URI delegation
* peer with the util package arg manager so that we would be notified when the
* application receives uri arguments.
*
* @author Emil Ivov
*/
public class ArgDelegationActivator
extends AbstractServiceDependentActivator
{
/**
* A reference to the bundle context that is currently in use.
*/
private static BundleContext bundleContext = null;
/**
* A reference to the delegation peer implementation that is currently
* handling uri arguments.
*/
private ArgDelegationPeerImpl delegationPeer = null;
/**
* A reference to the <tt>UIService</tt> currently in use in
* SIP Communicator.
*/
private static UIService uiService = null;
/**
* Starts the arg delegation bundle and registers the delegationPeer with
* the util package URI manager.
*
* @param dependentService the service this activator is waiting.
* @throws Exception if starting the arg delegation bundle and registering
* the delegationPeer with the util package URI manager fails
*/
public void start(Object dependentService)
{
delegationPeer = new ArgDelegationPeerImpl(bundleContext);
bundleContext.addServiceListener(delegationPeer);
//register our instance of delegation peer.
LaunchArgHandler.getInstance().setDelegationPeer(delegationPeer);
if(OSUtils.IS_MAC)
{
Application application = Application.getApplication();
if(application != null)
{
// if this fails its most probably cause using older java than
// 10.6 Update 3 and 10.5 Update 8
// and older native method for registering uri handlers
// should be working
try
{
Method method = application.getClass()
.getMethod("setOpenURIHandler", OpenURIHandler.class);
OpenURIHandler handler = new OpenURIHandler() {
public void openURI(
com.apple.eawt.AppEvent.OpenURIEvent evt)
{
delegationPeer.handleUri(evt.getURI().toString());
}
};
method.invoke(application, handler);
}
catch(Throwable ex)
{}
}
}
}
/**
* The dependent class. We are waiting for the ui service.
* @return the ui service class.
*/
@Override
public Class<?> getDependentServiceClass()
{
return UIService.class;
}
/**
* Sets the bundle context to use.
* @param context a reference to the currently active bundle context.
*/
@Override
public void setBundleContext(BundleContext context)
{
bundleContext = context;
}
/**
* Unsets the delegation peer instance that we set when we start this
* bundle.
*
* @param bc an instance of the currently valid bundle context.
* @throws Exception if unsetting the delegation peer instance that we set
* when we start this bundle fails
*/
public void stop(BundleContext bc) throws Exception
{
uiService = null;
bc.removeServiceListener(delegationPeer);
delegationPeer = null;
LaunchArgHandler.getInstance().setDelegationPeer(null);
}
/**
* Returns a reference to an UIService implementation currently registered
* in the bundle context or null if no such implementation was found.
*
* @return a reference to an UIService implementation currently registered
* in the bundle context or null if no such implementation was found.
*/
public static UIService getUIService()
{
if(uiService == null)
uiService = ServiceUtils.getService(bundleContext, UIService.class);
return uiService;
}
}
|