KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
14 import java.lang.ref.SoftReference JavaDoc;
15 import org.eclipse.core.runtime.IContributor;
16
17 /**
18  * An object which represents the user-defined extension point in a
19  * plug-in manifest.
20  */

21 public class ExtensionPoint extends RegistryObject {
22     public static final ExtensionPoint[] EMPTY_ARRAY = new ExtensionPoint[0];
23
24     //Place holder for the label and the schema. It contains either a String[] or a SoftReference to a String[].
25
//The array layout is [label, schemaReference, fullyQualifiedName, namespace, contributorId]
26
private Object JavaDoc extraInformation;
27     //Indexes of the various fields
28
private static final byte LABEL = 0; //The human readable name for the extension point
29
private static final byte SCHEMA = 1; //The schema of the extension point
30
private static final byte QUALIFIED_NAME = 2; //The fully qualified name of the extension point
31
private static final byte NAMESPACE = 3; //The name of the namespace of the extension point
32
private static final byte CONTRIBUTOR_ID = 4; //The ID of the actual contributor of the extension point
33
private static final int EXTRA_SIZE = 5;
34
35     protected ExtensionPoint(ExtensionRegistry registry, boolean persist) {
36         super(registry, persist);
37     }
38
39     protected ExtensionPoint(int self, int[] children, int dataOffset, ExtensionRegistry registry, boolean persist) {
40         super(registry, persist);
41
42         setObjectId(self);
43         setRawChildren(children);
44         setExtraDataOffset(dataOffset);
45     }
46
47     protected String JavaDoc getSimpleIdentifier() {
48         return getUniqueIdentifier().substring(getUniqueIdentifier().lastIndexOf('.') + 1);
49     }
50
51     private String JavaDoc[] getExtraData() {
52         //The extension point has been created by parsing, or does not have any extra data
53
if (noExtraData()) { //When this is true, the extraInformation is always a String[]. This happens when the object is created by the parser.
54
if (extraInformation != null)
55                 return (String JavaDoc[]) extraInformation;
56             return new String JavaDoc[EXTRA_SIZE];
57         }
58
59         //The extension point has been loaded from the cache.
60
String JavaDoc[] result = null;
61         if (extraInformation == null || (result = ((extraInformation instanceof SoftReference JavaDoc) ? (String JavaDoc[]) ((SoftReference JavaDoc) extraInformation).get() : (String JavaDoc[]) extraInformation)) == null) {
62             result = registry.getTableReader().loadExtensionPointExtraData(getExtraDataOffset());
63             extraInformation = new SoftReference JavaDoc(result);
64         }
65         return result;
66     }
67
68     /**
69      * At the end of this method, extra information will be a string[]
70      */

71     private void ensureExtraInformationType() {
72         if (extraInformation instanceof SoftReference JavaDoc) {
73             extraInformation = ((SoftReference JavaDoc) extraInformation).get();
74         }
75         if (extraInformation == null) {
76             extraInformation = new String JavaDoc[EXTRA_SIZE];
77         }
78     }
79
80     protected String JavaDoc getSchemaReference() {
81         String JavaDoc[] result = getExtraData();
82         return result[1] == null ? "" : result[SCHEMA].replace(File.separatorChar, '/'); //$NON-NLS-1$
83
}
84
85     protected String JavaDoc getLabel() {
86         String JavaDoc[] result = getExtraData();
87         return result[0] == null ? "" : result[LABEL]; //$NON-NLS-1$
88
}
89
90     protected String JavaDoc getUniqueIdentifier() {
91         return getExtraData()[QUALIFIED_NAME];
92     }
93
94     public String JavaDoc getNamespace() {
95         return getExtraData()[NAMESPACE];
96     }
97
98     protected String JavaDoc getContributorId() {
99         return getExtraData()[CONTRIBUTOR_ID];
100     }
101
102     public IContributor getContributor() {
103         return registry.getObjectManager().getContributor(getContributorId());
104     }
105
106     void setSchema(String JavaDoc value) {
107         ensureExtraInformationType();
108         ((String JavaDoc[]) extraInformation)[SCHEMA] = value;
109     }
110
111     void setLabel(String JavaDoc value) {
112         ensureExtraInformationType();
113         ((String JavaDoc[]) extraInformation)[LABEL] = value;
114     }
115
116     void setUniqueIdentifier(String JavaDoc value) {
117         ensureExtraInformationType();
118         ((String JavaDoc[]) extraInformation)[QUALIFIED_NAME] = value;
119     }
120
121     void setNamespace(String JavaDoc value) {
122         ensureExtraInformationType();
123         ((String JavaDoc[]) extraInformation)[NAMESPACE] = value;
124     }
125
126     void setContributorId(String JavaDoc id) {
127         ensureExtraInformationType();
128         ((String JavaDoc[]) extraInformation)[CONTRIBUTOR_ID] = id;
129     }
130
131     public String JavaDoc toString() {
132         return getUniqueIdentifier();
133     }
134
135 }
136
Popular Tags