1 /*******************************************************************************
2  * Copyright (c) 2006, 2014 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.core.runtime.spi;
15 
16 import org.eclipse.core.runtime.IContributor;
17 
18 /**
19  * This class describes a registry contributor which is an entity that supplies information
20  * to the extension registry. Depending on the registry strategy, contributor might delegate
21  * some of its functionality to a "host" contributor. For instance, OSGi registry strategy
22  * uses "host" contributor to delegate some functionality from fragments to plug-ins.
23  * <p>
24  * This class can be instantiated by the registry Service Providers.
25  * </p><p>
26  * This class can be used without OSGi running.
27  * </p><p>
28  * This class can not be extended.
29  * </p>
30  * @since org.eclipse.equinox.registry 3.2
31  * @noextend This class is not intended to be subclassed by clients.
32  */
33 public final class RegistryContributor implements IContributor {
34 
35 	/**
36 	 * Actual ID of the contributor (e.g., "12"). IDs are expected to be unique in the workspace.
37 	 */
38 	private String actualContributorId;
39 
40 	/**
41 	 * Actual name of the contributor (e.g., "org.eclipse.core.runtime.fragment").
42 	 */
43 	private String actualContributorName;
44 
45 	/**
46 	 * ID associated with the entity "in charge" of the contributor (e.g., "1"). IDs are expected
47 	 * to be unique in the workspace. If contributor does not rely on a host, this value should be
48 	 * the same as the actual contributor ID.
49 	 */
50 	private String hostId;
51 
52 	/**
53 	 * Name of the entity "in charge" of the contributor (e.g. "org.eclipse.core.runtime").
54 	 * If contributor does not rely on a host, this value should be the same as the actual
55 	 * contributor name.
56 	 */
57 	private String hostName;
58 
59 	/**
60 	 * Constructor for the registry contributor.
61 	 * <p>
62 	 * The actual ID is a string identifier for the contributor (e.g., "12") and is expected
63 	 * to be unique within the workspace. The actual ID of the contributor must not
64 	 * be <code>null</code>.
65 	 * </p><p>
66 	 * The actual name is the name associated with the contributor
67 	 * (e.g., "org.eclipse.core.runtime.fragment"). The actual name of the contributor must
68 	 * not be <code>null</code>.
69 	 * </p><p>
70 	 * The host ID is the identifier associated with the entity "in charge" of the contributor
71 	 * (e.g., "1"). IDs are expected to be unique in the workspace. If contributor does not
72 	 * rely on a host, then <code>null</code> should be used as the host ID.
73 	 * </p><p>
74 	 * The host name is the name of the entity "in charge" of the contributor
75 	 * (e.g., "org.eclipse.core.runtime"). If contributor does not rely on a host, then
76 	 * <code>null</code> should be used as the host name.
77 	 * </p><p>
78 	 * There should be 1-to-1 mapping between the contributor and the contibutor ID.
79 	 * The IDs (either actual or host) can not be re-used in the same registry.
80 	 * For example, if ID of 12 was used to identify contributorA, the ID of 12 can not
81 	 * be used to identify contributorB or a host for the contributorC.
82 	 * </p>
83 	 * @param actualId contributor identifier
84 	 * @param actualName name of the contributor
85 	 * @param hostId id associated with the host, or <code>null</code>
86 	 * @param hostName name of the host, or <code>null</code>
87 	 */
RegistryContributor(String actualId, String actualName, String hostId, String hostName)88 	public RegistryContributor(String actualId, String actualName, String hostId, String hostName) {
89 		this.actualContributorId = actualId;
90 		this.actualContributorName = actualName;
91 		if (hostId != null) {
92 			this.hostId = hostId;
93 			this.hostName = hostName;
94 		} else {
95 			this.hostId = actualId;
96 			this.hostName = actualName;
97 		}
98 	}
99 
100 	/**
101 	 * Provides actual ID associated with the registry contributor (e.g., "12"). IDs are expected
102 	 * to be unique in the workspace.
103 	 *
104 	 * @return actual ID of the registry contributor
105 	 */
getActualId()106 	public String getActualId() {
107 		return actualContributorId;
108 	}
109 
110 	/**
111 	 * Provides actual name of the registry contributor (e.g., "org.eclipe.core.runtime.fragment").
112 	 *
113 	 * @return actual name of the registry contributor
114 	 */
getActualName()115 	public String getActualName() {
116 		return actualContributorName;
117 	}
118 
119 	/**
120 	 * Provides ID associated with the entity "in charge" of the contributor (e.g., "1"). IDs are expected
121 	 * to be unique in the workspace. If contributor does not rely on a host, this value should be
122 	 * the same as the actual contributor ID.
123 	 *
124 	 * @return id of the registry contributor
125 	 */
getId()126 	public String getId() {
127 		return hostId;
128 	}
129 
130 	/**
131 	 * Provides name of the entity "in charge" of the contributor (e.g., "org.eclipse.core.runtime").
132 	 * If contributor does not rely on a host, this value should be the same as the actual contributor name.
133 	 *
134 	 * @return name of the registry contributor
135 	 */
136 	@Override
getName()137 	public String getName() {
138 		return hostName;
139 	}
140 
141 	/* (non-Javadoc)
142 	 * @see java.lang.Object#toString()
143 	 */
144 	@Override
toString()145 	public String toString() {
146 		return actualContributorName + "[" + actualContributorId + "]"; //$NON-NLS-1$ //$NON-NLS-2$
147 	}
148 }
149