KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.core.internal.registry;
12
13 import java.lang.ref.SoftReference JavaDoc;
14 import org.eclipse.core.runtime.IContributor;
15
16 /**
17  * An object which represents the user-defined extension in a plug-in manifest.
18  */

19 public class Extension extends RegistryObject {
20     public static final Extension[] EMPTY_ARRAY = new Extension[0];
21
22     //Extension simple identifier
23
private String JavaDoc simpleId;
24     //The namespace for the extension.
25
private String JavaDoc namespaceIdentifier;
26
27     // Place holder for the label and the extension point. It contains either a String[] or a SoftReference to a String[].
28
//The array layout is [label, extension point name]
29
private Object JavaDoc extraInformation;
30     private static final byte LABEL = 0; //The human readable name of the extension
31
private static final byte XPT_NAME = 1; // The fully qualified name of the extension point to which this extension is attached to
32
private static final byte CONTRIBUTOR_ID = 2; // ID of the actual contributor of this extension
33
private static final int EXTRA_SIZE = 3;
34
35     protected Extension(ExtensionRegistry registry, boolean persist) {
36         super(registry, persist);
37     }
38
39     protected Extension(int self, String JavaDoc simpleId, String JavaDoc namespace, int[] children, int extraData, ExtensionRegistry registry, boolean persist) {
40         super(registry, persist);
41
42         setObjectId(self);
43         this.simpleId = simpleId;
44         setRawChildren(children);
45         setExtraDataOffset(extraData);
46         this.namespaceIdentifier = namespace;
47     }
48
49     protected String JavaDoc getExtensionPointIdentifier() {
50         return getExtraData()[XPT_NAME];
51     }
52
53     protected String JavaDoc getSimpleIdentifier() {
54         return simpleId;
55     }
56
57     protected String JavaDoc getUniqueIdentifier() {
58         return simpleId == null ? null : this.getNamespaceIdentifier() + '.' + simpleId;
59     }
60
61     void setExtensionPointIdentifier(String JavaDoc value) {
62         ensureExtraInformationType();
63         ((String JavaDoc[]) extraInformation)[XPT_NAME] = value;
64     }
65
66     void setSimpleIdentifier(String JavaDoc value) {
67         simpleId = value;
68     }
69
70     private String JavaDoc[] getExtraData() {
71         //The extension has been created by parsing, or does not have any extra data
72
if (noExtraData()) {
73             if (extraInformation != null)
74                 return (String JavaDoc[]) extraInformation;
75             return null;
76         }
77
78         //The extension has been loaded from the cache.
79
String JavaDoc[] result = null;
80         if (extraInformation == null || (result = ((extraInformation instanceof SoftReference JavaDoc) ? (String JavaDoc[]) ((SoftReference JavaDoc) extraInformation).get() : (String JavaDoc[]) extraInformation)) == null) {
81             result = registry.getTableReader().loadExtensionExtraData(getExtraDataOffset());
82             extraInformation = new SoftReference JavaDoc(result);
83         }
84         return result;
85     }
86
87     String JavaDoc getLabel() {
88         String JavaDoc s = getExtraData()[LABEL];
89         if (s == null)
90             return ""; //$NON-NLS-1$
91
return s;
92     }
93
94     void setLabel(String JavaDoc value) {
95         ensureExtraInformationType();
96         ((String JavaDoc[]) extraInformation)[LABEL] = value;
97     }
98
99     String JavaDoc getContributorId() {
100         String JavaDoc s = getExtraData()[CONTRIBUTOR_ID];
101         if (s == null)
102             return ""; //$NON-NLS-1$
103
return s;
104     }
105
106     public IContributor getContributor() {
107         return registry.getObjectManager().getContributor(getContributorId());
108     }
109
110     void setContributorId(String JavaDoc value) {
111         ensureExtraInformationType();
112         ((String JavaDoc[]) extraInformation)[CONTRIBUTOR_ID] = value;
113     }
114
115     public String JavaDoc getNamespaceIdentifier() {
116         return namespaceIdentifier;
117     }
118
119     void setNamespaceIdentifier(String JavaDoc value) {
120         namespaceIdentifier = value;
121     }
122
123     public String JavaDoc toString() {
124         return getUniqueIdentifier() + " -> " + getExtensionPointIdentifier(); //$NON-NLS-1$
125
}
126
127     /**
128      * At the end of this method, extra information will be a string[]
129      */

130     private void ensureExtraInformationType() {
131         if (extraInformation instanceof SoftReference JavaDoc) {
132             extraInformation = ((SoftReference JavaDoc) extraInformation).get();
133         }
134         if (extraInformation == null) {
135             extraInformation = new String JavaDoc[EXTRA_SIZE];
136         }
137     }
138 }
139
Popular Tags