1 11 package org.eclipse.core.internal.registry; 12 13 import java.lang.ref.SoftReference ; 14 import org.eclipse.core.runtime.IContributor; 15 16 19 public class Extension extends RegistryObject { 20 public static final Extension[] EMPTY_ARRAY = new Extension[0]; 21 22 private String simpleId; 24 private String namespaceIdentifier; 26 27 private Object extraInformation; 30 private static final byte LABEL = 0; private static final byte XPT_NAME = 1; private static final byte CONTRIBUTOR_ID = 2; 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 simpleId, String 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 getExtensionPointIdentifier() { 50 return getExtraData()[XPT_NAME]; 51 } 52 53 protected String getSimpleIdentifier() { 54 return simpleId; 55 } 56 57 protected String getUniqueIdentifier() { 58 return simpleId == null ? null : this.getNamespaceIdentifier() + '.' + simpleId; 59 } 60 61 void setExtensionPointIdentifier(String value) { 62 ensureExtraInformationType(); 63 ((String []) extraInformation)[XPT_NAME] = value; 64 } 65 66 void setSimpleIdentifier(String value) { 67 simpleId = value; 68 } 69 70 private String [] getExtraData() { 71 if (noExtraData()) { 73 if (extraInformation != null) 74 return (String []) extraInformation; 75 return null; 76 } 77 78 String [] result = null; 80 if (extraInformation == null || (result = ((extraInformation instanceof SoftReference ) ? (String []) ((SoftReference ) extraInformation).get() : (String []) extraInformation)) == null) { 81 result = registry.getTableReader().loadExtensionExtraData(getExtraDataOffset()); 82 extraInformation = new SoftReference (result); 83 } 84 return result; 85 } 86 87 String getLabel() { 88 String s = getExtraData()[LABEL]; 89 if (s == null) 90 return ""; return s; 92 } 93 94 void setLabel(String value) { 95 ensureExtraInformationType(); 96 ((String []) extraInformation)[LABEL] = value; 97 } 98 99 String getContributorId() { 100 String s = getExtraData()[CONTRIBUTOR_ID]; 101 if (s == null) 102 return ""; return s; 104 } 105 106 public IContributor getContributor() { 107 return registry.getObjectManager().getContributor(getContributorId()); 108 } 109 110 void setContributorId(String value) { 111 ensureExtraInformationType(); 112 ((String []) extraInformation)[CONTRIBUTOR_ID] = value; 113 } 114 115 public String getNamespaceIdentifier() { 116 return namespaceIdentifier; 117 } 118 119 void setNamespaceIdentifier(String value) { 120 namespaceIdentifier = value; 121 } 122 123 public String toString() { 124 return getUniqueIdentifier() + " -> " + getExtensionPointIdentifier(); } 126 127 130 private void ensureExtraInformationType() { 131 if (extraInformation instanceof SoftReference ) { 132 extraInformation = ((SoftReference ) extraInformation).get(); 133 } 134 if (extraInformation == null) { 135 extraInformation = new String [EXTRA_SIZE]; 136 } 137 } 138 } 139 | Popular Tags |