blob: b82428a1ed3d98799758897305fb80fffb15dda6 (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2009, 2017 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.p2.core;
import java.net.URI;
import java.util.Dictionary;
import java.util.Hashtable;
import org.eclipse.equinox.p2.core.*;
import org.osgi.framework.*;
/**
* Default implementation of {@link IProvisioningAgentProvider}.
*/
public class DefaultAgentProvider implements IProvisioningAgentProvider {
private BundleContext context;
public void activate(BundleContext aContext) {
this.context = aContext;
}
@Override
public IProvisioningAgent createAgent(URI location) {
ProvisioningAgent result = new ProvisioningAgent();
result.setBundleContext(context);
result.setLocation(location);
IAgentLocation agentLocation = (IAgentLocation) result.getService(IAgentLocation.SERVICE_NAME);
Dictionary<String, Object> properties = new Hashtable<>(5);
if (agentLocation != null)
properties.put("locationURI", String.valueOf(agentLocation.getRootLocation())); //$NON-NLS-1$
//make the currently running system have a higher service ranking
if (location == null) {
properties.put(Constants.SERVICE_RANKING, Integer.valueOf(100));
properties.put(IProvisioningAgent.SERVICE_CURRENT, Boolean.TRUE.toString());
}
ServiceRegistration<IProvisioningAgent> reg = context.registerService(IProvisioningAgent.class, result, properties);
result.setServiceRegistration(reg);
return result;
}
}
|