1 11 package org.eclipse.core.internal.registry; 12 13 import org.eclipse.core.runtime.*; 14 15 18 public class ConfigurationElementHandle extends Handle implements IConfigurationElement { 19 static final ConfigurationElementHandle[] EMPTY_ARRAY = new ConfigurationElementHandle[0]; 20 21 public ConfigurationElementHandle(IObjectManager objectManager, int id) { 22 super(objectManager, id); 23 } 24 25 protected ConfigurationElement getConfigurationElement() { 26 return (ConfigurationElement) objectManager.getObject(getId(), RegistryObjectManager.CONFIGURATION_ELEMENT); 27 } 28 29 protected boolean shouldPersist() { 30 return getConfigurationElement().shouldPersist(); 31 } 32 33 public String getAttribute(String propertyName) { 34 return getConfigurationElement().getAttribute(propertyName); 35 } 36 37 public String [] getAttributeNames() { 38 return getConfigurationElement().getAttributeNames(); 39 } 40 41 public IConfigurationElement[] getChildren() { 42 ConfigurationElement actualCe = getConfigurationElement(); 43 if (actualCe.noExtraData()) { 44 return (IConfigurationElement[]) objectManager.getHandles(actualCe.getRawChildren(), RegistryObjectManager.CONFIGURATION_ELEMENT); 45 } 46 return (IConfigurationElement[]) objectManager.getHandles(actualCe.getRawChildren(), RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT); 47 } 48 49 public Object createExecutableExtension(String propertyName) throws CoreException { 50 try { 51 return getConfigurationElement().createExecutableExtension(propertyName); 52 } catch (InvalidRegistryObjectException e) { 53 Status status = new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, IRegistryConstants.PLUGIN_ERROR, "Invalid registry object", e); if (objectManager instanceof RegistryObjectManager) 55 ((RegistryObjectManager) objectManager).getRegistry().log(status); 56 throw new CoreException(status); 57 } 58 } 59 60 public String getAttributeAsIs(String name) { 61 return getConfigurationElement().getAttributeAsIs(name); 62 } 63 64 public IConfigurationElement[] getChildren(String name) { 65 ConfigurationElement actualCE = getConfigurationElement(); 66 ConfigurationElement[] children = (ConfigurationElement[]) objectManager.getObjects(actualCE.getRawChildren(), actualCE.noExtraData() ? RegistryObjectManager.CONFIGURATION_ELEMENT : RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT); 67 if (children.length == 0) 68 return ConfigurationElementHandle.EMPTY_ARRAY; 69 70 IConfigurationElement[] result = new IConfigurationElement[1]; 71 int idx = 0; 72 for (int i = 0; i < children.length; i++) { 73 if (children[i].getName().equals(name)) { 74 if (idx != 0) { 75 IConfigurationElement[] copy = new IConfigurationElement[result.length + 1]; 76 System.arraycopy(result, 0, copy, 0, result.length); 77 result = copy; 78 } 79 result[idx++] = (IConfigurationElement) objectManager.getHandle(children[i].getObjectId(), actualCE.noExtraData() ? RegistryObjectManager.CONFIGURATION_ELEMENT : RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT); 80 } 81 } 82 if (idx == 0) 83 return ConfigurationElementHandle.EMPTY_ARRAY; 84 return result; 85 } 86 87 public IExtension getDeclaringExtension() { 88 Object result = this; 89 while (!((result = ((ConfigurationElementHandle) result).getParent()) instanceof ExtensionHandle)) { 90 } 91 return (IExtension) result; 92 } 93 94 public String getName() { 95 return getConfigurationElement().getName(); 96 } 97 98 public Object getParent() { 99 ConfigurationElement actualCe = getConfigurationElement(); 100 return objectManager.getHandle(actualCe.parentId, actualCe.parentType); 101 } 102 103 public String getValue() { 104 return getConfigurationElement().getValue(); 105 } 106 107 public String getValueAsIs() { 108 return getConfigurationElement().getValueAsIs(); 109 } 110 111 RegistryObject getObject() { 112 return getConfigurationElement(); 113 } 114 115 public String getNamespace() { 117 return getContributor().getName(); 118 } 119 120 public String getNamespaceIdentifier() { 121 return getDeclaringExtension().getNamespaceIdentifier(); 123 } 124 125 public IContributor getContributor() { 126 return getConfigurationElement().getContributor(); 127 } 128 129 public boolean isValid() { 130 try { 131 getConfigurationElement(); 132 } catch (InvalidRegistryObjectException e) { 133 return false; 134 } 135 return true; 136 } 137 } 138 | Popular Tags |