1 /*******************************************************************************
2  * Copyright (c) 2009 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.pde.internal.runtime.registry.model;
15 
16 public class Extension extends ModelObject {
17 
18 	private String namespaceIdentifier;
19 	private String label;
20 	private String extensionPointUniqueIdentifier;
21 	private ConfigurationElement[] configurationElements = new ConfigurationElement[0];
22 	private Long contributor;
23 
setNamespaceIdentifier(String namespaceIdentifier)24 	public void setNamespaceIdentifier(String namespaceIdentifier) {
25 		this.namespaceIdentifier = namespaceIdentifier;
26 	}
27 
setLabel(String label)28 	public void setLabel(String label) {
29 		this.label = label;
30 	}
31 
setExtensionPointUniqueIdentifier(String extensionPointUniqueIdentifier)32 	public void setExtensionPointUniqueIdentifier(String extensionPointUniqueIdentifier) {
33 		this.extensionPointUniqueIdentifier = extensionPointUniqueIdentifier;
34 	}
35 
setConfigurationElements(ConfigurationElement[] configurationElements)36 	public void setConfigurationElements(ConfigurationElement[] configurationElements) {
37 		if (configurationElements == null)
38 			throw new IllegalArgumentException();
39 
40 		this.configurationElements = configurationElements;
41 	}
42 
setContributor(Long contributor)43 	public void setContributor(Long contributor) {
44 		this.contributor = contributor;
45 	}
46 
getConfigurationElements()47 	public ConfigurationElement[] getConfigurationElements() {
48 		return configurationElements;
49 	}
50 
getExtensionPointUniqueIdentifier()51 	public String getExtensionPointUniqueIdentifier() {
52 		return extensionPointUniqueIdentifier;
53 	}
54 
getLabel()55 	public String getLabel() {
56 		return label;
57 	}
58 
getNamespaceIdentifier()59 	public String getNamespaceIdentifier() {
60 		return namespaceIdentifier;
61 	}
62 
63 	/**
64 	 * @return contributor id or <code>null</code> if contributor not present
65 	 */
getContributorId()66 	public Long getContributorId() {
67 		return contributor;
68 	}
69 
70 	@Override
equals(Object obj)71 	public boolean equals(Object obj) {
72 		if (this == obj)
73 			return true;
74 		if (obj == null)
75 			return false;
76 		if (getClass() != obj.getClass())
77 			return false;
78 		Extension other = (Extension) obj;
79 		if (contributor == null) {
80 			if (other.contributor != null)
81 				return false;
82 		} else if (!contributor.equals(other.contributor))
83 			return false;
84 		if (extensionPointUniqueIdentifier == null) {
85 			if (other.extensionPointUniqueIdentifier != null)
86 				return false;
87 		} else if (!extensionPointUniqueIdentifier.equals(other.extensionPointUniqueIdentifier))
88 			return false;
89 		if (label == null) {
90 			if (other.label != null)
91 				return false;
92 		} else if (!label.equals(other.label))
93 			return false;
94 		if (namespaceIdentifier == null) {
95 			if (other.namespaceIdentifier != null)
96 				return false;
97 		} else if (!namespaceIdentifier.equals(other.namespaceIdentifier))
98 			return false;
99 		return true;
100 	}
101 
102 	@Override
hashCode()103 	public int hashCode() {
104 		final int prime = 31;
105 		int result = 1;
106 		result = prime * result + ((contributor == null) ? 0 : contributor.hashCode());
107 		result = prime * result + ((extensionPointUniqueIdentifier == null) ? 0 : extensionPointUniqueIdentifier.hashCode());
108 		result = prime * result + ((label == null) ? 0 : label.hashCode());
109 		result = prime * result + ((namespaceIdentifier == null) ? 0 : namespaceIdentifier.hashCode());
110 		return result;
111 	}
112 
getExtensionPoint()113 	public ExtensionPoint getExtensionPoint() {
114 		if (model == null)
115 			return null;
116 		return model.getExtensionPoint(extensionPointUniqueIdentifier);
117 	}
118 
119 	/**
120 	 * @return contributor or <code>null</code> if contributor not present
121 	 */
getContributor()122 	public Bundle getContributor() {
123 		if (model == null || contributor == null)
124 			return null;
125 		return model.getBundle(contributor);
126 	}
127 }
128