KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > registry > Namespace


1 /*******************************************************************************
2  * Copyright (c) 2003, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.registry;
12
13 import java.util.MissingResourceException JavaDoc;
14 import java.util.ResourceBundle JavaDoc;
15 import org.eclipse.core.internal.runtime.ResourceTranslator;
16 import org.eclipse.core.runtime.IExtension;
17 import org.eclipse.core.runtime.IExtensionPoint;
18 import org.osgi.framework.Bundle;
19
20 /**
21  * An object which represents the user-defined contents of a bundle model
22  * in a extensions manifest.
23  */

24 public class Namespace extends NestedRegistryModelObject {
25     // null if this does not correspond to a fragment
26
private String JavaDoc hostId;
27     private IExtensionPoint[] extensionPoints;
28     private IExtension[] extensions;
29     private transient ResourceBundle JavaDoc resourceBundle;
30     private boolean missingResourceBundle = false;
31     private Bundle JavaDoc bundle; //Introduced to fix #46308
32

33     public String JavaDoc getUniqueIdentifier() {
34         return getName();
35     }
36
37     public void setUniqueIdentifier(String JavaDoc value) {
38         setName(value);
39     }
40
41     public void setExtensions(IExtension[] value) {
42         extensions = value;
43     }
44
45     public IExtension getExtension(String JavaDoc id) {
46         if (id == null)
47             return null;
48         IExtension[] list = getExtensions();
49         if (list == null)
50             return null;
51         for (int i = 0; i < list.length; i++) {
52             if (id.equals(list[i].getSimpleIdentifier()))
53                 return list[i];
54         }
55         return null;
56     }
57
58     public IExtension[] getExtensions() {
59         return extensions == null ? new IExtension[0] : extensions;
60     }
61
62     public void setExtensionPoints(IExtensionPoint[] value) {
63         extensionPoints = value;
64     }
65
66     public IExtensionPoint getExtensionPoint(String JavaDoc xpt) {
67         if (xpt == null)
68             return null;
69         IExtensionPoint[] list = getExtensionPoints();
70         if (list == null)
71             return null;
72         for (int i = 0; i < list.length; i++) {
73             if (xpt.equals(list[i].getSimpleIdentifier()))
74                 return list[i];
75         }
76         return null;
77     }
78
79     public IExtensionPoint[] getExtensionPoints() {
80         return extensionPoints == null ? new IExtensionPoint[0] : extensionPoints;
81     }
82
83     public void setHostIdentifier(String JavaDoc value) {
84         hostId = value;
85     }
86
87     public String JavaDoc getHostIdentifier() {
88         return hostId;
89     }
90
91     public boolean isFragment() {
92         return hostId != null;
93     }
94
95     public String JavaDoc toString() {
96         return "Namespace: " + getName(); //$NON-NLS-1$
97
}
98
99     public long getId() {
100         // returns an invalid id, but avoids NPE
101
return bundle == null ? -1 : bundle.getBundleId();
102     }
103
104     public Bundle JavaDoc getBundle() {
105         return bundle;
106     }
107
108     public void setBundle(Bundle JavaDoc value) {
109         bundle = value;
110     }
111
112     public String JavaDoc getResourceString(String JavaDoc value) {
113         if (resourceBundle != null)
114             return ResourceTranslator.getResourceString(null, value, resourceBundle);
115
116         if (missingResourceBundle)
117             return value;
118
119         if (resourceBundle == null) {
120             try {
121                 resourceBundle = ResourceTranslator.getResourceBundle(bundle);
122             } catch (MissingResourceException JavaDoc e) {
123                 resourceBundle = null;
124             }
125         }
126
127         if (resourceBundle == null) {
128             missingResourceBundle = true;
129             return value;
130         }
131
132         return ResourceTranslator.getResourceString(null, value, resourceBundle);
133     }
134 }
Popular Tags