Debian Codegraph @

bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileScope.java

raw
1 /*******************************************************************************
2 * Copyright (c) 2009, 2017 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.equinox.p2.engine;
15
16 import org.eclipse.core.internal.preferences.PreferencesService;
17 import org.eclipse.core.runtime.Assert;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20 import org.eclipse.core.runtime.preferences.IScopeContext;
21 import org.eclipse.equinox.internal.p2.engine.SlashEncode;
22 import org.eclipse.equinox.p2.core.IAgentLocation;
23
24 /**
25 * A profile scope contains the preferences associated with a particular profile
26 * in a provisioned system.
27 * @see IProfile
28 * @since 2.0
29 */
30 public final class ProfileScope implements IScopeContext {
31
32 /**
33 * String constant (value of <code>"profile"</code>) used for the
34 * scope name for this preference scope.
35 */
36 public static final String SCOPE = "profile"; //$NON-NLS-1$
37
38 private String profileId;
39
40 private IAgentLocation location;
41
42 /**
43 * Creates and returns a profile scope for the given profile id and agent.
44 * @param agentLocation The location of the provisioning agent to obtain profile preferences for
45 * @param profileId The id of the profile to obtain preferences for
46 */
47 public ProfileScope(IAgentLocation agentLocation, String profileId) {
48 super();
49 Assert.isNotNull(agentLocation);
50 Assert.isNotNull(profileId);
51 this.profileId = profileId;
52 this.location = agentLocation;
53 }
54
55 @Override
56 public IPath getLocation() {
57 // Null returned as the location should only be used when the profile is locked
58 return null;
59 }
60
61 @Override
62 public String getName() {
63 return SCOPE;
64 }
65
66 /*
67 * Default path hierarchy for profile nodes is /profile/<profileId>/<qualifier>.
68 *
69 * @see org.eclipse.core.runtime.preferences.IScopeContext#getNode(java.lang.String)
70 */
71 @Override
72 public IEclipsePreferences getNode(String qualifier) {
73 if (qualifier == null)
74 throw new IllegalArgumentException();
75 String locationString = SlashEncode.encode(location.getRootLocation().toString());
76 //format is /profile/{agentLocationURI}/{profileId}/qualifier
77 return (IEclipsePreferences) PreferencesService.getDefault().getRootNode().node(getName()).node(locationString).node(profileId).node(qualifier);
78 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj)
83 return true;
84 if (!super.equals(obj))
85 return false;
86 if (!(obj instanceof ProfileScope))
87 return false;
88 ProfileScope other = (ProfileScope) obj;
89 return profileId.equals(other.profileId);
90 }
91
92 @Override
93 public int hashCode() {
94 return super.hashCode() + profileId.hashCode();
95 }
96 }