From e73afe6adb468508264858fe8247672fd5a5c481 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Wed, 3 Mar 2004 20:51:11 +0000 Subject: [PATCH] helper method for getting extension elements of a cextension. --- .../cdt/core/ICExtensionReference.java | 92 ++++++++++++++----- .../cdt/internal/core/CDescriptor.java | 22 ++++- .../internal/core/CExtensionReference.java | 4 + 3 files changed, 90 insertions(+), 28 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtensionReference.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtensionReference.java index 57bf1ede8ab..f940e4ebb5b 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtensionReference.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICExtensionReference.java @@ -7,37 +7,81 @@ * * Contributors: * QNX Software Systems - Initial API and implementation -***********************************************************************/ + ***********************************************************************/ package org.eclipse.cdt.core; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; public interface ICExtensionReference { - - /** - * Return the extension point of this reference. - * @return String - */ - public String getExtension(); + + /** + * Return the extension point of this reference. + * + * @return String + */ + public String getExtension(); + + /** + * Return the extension ID of this reference. + * + * @return String + */ + public String getID(); + + /** + * Sets a name/value data pair on this reference in the .cdtproject file + */ + public void setExtensionData(String key, String value); + + /** + * Gets a value of the key from the .cdtproject file set by + * setExtensionData() + */ + public String getExtensionData(String key); /** - * Return the extension ID of this reference. - * @return String + * Creates and returns a new instance of the cextension executable + * identified by the <run> attribute of the cextension. + *

+ * The ICExtension is instantiated using its 0-argument public + * constructor. If the class implements the + * IExecutableExtension interface, the method + * setInitializationData is called, passing to the object + * the configuration information that was used to create it. + *

+ *

+ * Unlike other methods on this object, invoking this method may activate + * the plug-in. + *

+ * + * @return the executable ICExtension instance + * @exception CoreException if an instance of the executable extension + * could not be created for any reason. + * @see IExecutableExtension#setInitializationData */ - public String getID(); - - /** - * Sets a name/value data pair on this reference in the .cdtproject file - */ - public void setExtensionData(String key, String value); + public ICExtension createExtension() throws CoreException; - /** - * Gets a value of the key from the .cdtproject file set by setExtensionData() - */ - public String getExtensionData(String key); - - /** - * Creates the executable extension for the reference. - */ - public ICExtension createExtension() throws CoreException; + /** + * Returns all configuration elements that are children of the + * cextension element. Returns an empty array if this configuration + * element has no children. + *

+ * Each child corresponds to a nested XML element in the configuration + * markup. For example, the configuration markup + * + *

+     *  <view>
+     *  &nbsp&nbsp&nbsp&nbsp<verticalHint>top</verticalHint>
+     *  &nbsp&nbsp&nbsp&nbsp<horizontalHint>left</horizontalHint>
+     *  </view>
+     * 
+ * + * corresponds to a configuration element, named "view", + * with two children. + *

+ * + * @return the child configuration elements + */ + public IConfigurationElement[] getExtensionElements() throws CoreException; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptor.java index fbebf9db567..56db99d8883 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CDescriptor.java @@ -16,7 +16,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; @@ -60,12 +59,12 @@ public class CDescriptor implements ICDescriptor { private HashMap extInfoMap = new HashMap(4); private Document dataDoc; + static final String CEXTENSION_NAME = "cextension"; //$NON-NLS-1$ static final String DESCRIPTION_FILE_NAME = ".cdtproject"; //$NON-NLS-1$ private static final char[][] NO_CHAR_CHAR = new char[0][]; private static final String PROJECT_DESCRIPTION = "cdtproject"; //$NON-NLS-1$ private static final String PROJECT_EXTENSION = "extension"; //$NON-NLS-1$ private static final String PROJECT_EXTENSION_ATTRIBUTE = "attribute"; //$NON-NLS-1$ - private static final String PATH_ENTRY = "cpathentry"; //$NON-NLS-1$ private static final String PROJECT_DATA = "data"; //$NON-NLS-1$ private static final String PROJECT_DATA_ITEM = "item"; //$NON-NLS-1$ private static final String PROJECT_DATA_ID = "id"; //$NON-NLS-1$ @@ -318,7 +317,6 @@ public class CDescriptor implements ICDescriptor { private void readProjectDescription(Node node) { Node childNode; - ArrayList pathEntries = new ArrayList(); NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { childNode = list.item(i); @@ -397,7 +395,7 @@ public class CDescriptor implements ICDescriptor { } IConfigurationElement element[] = extension.getConfigurationElements(); for (int i = 0; i < element.length; i++) { - if (element[i].getName().equalsIgnoreCase("cextension")) { //$NON-NLS-1$ + if (element[i].getName().equalsIgnoreCase(CEXTENSION_NAME)) { cExtension = (InternalCExtension) element[i].createExecutableExtension("run"); //$NON-NLS-1$ cExtension.setExtenionReference(ext); cExtension.setProject(fProject); @@ -407,6 +405,22 @@ public class CDescriptor implements ICDescriptor { return (ICExtension) cExtension; } + protected IConfigurationElement[] getConfigurationElement(ICExtensionReference ext) throws CoreException { + IPluginRegistry pluginRegistry = Platform.getPluginRegistry(); + IExtensionPoint extensionPoint = pluginRegistry.getExtensionPoint(ext.getExtension()); + IExtension extension = extensionPoint.getExtension(ext.getID()); + if ( extension == null) { + throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, CCorePlugin.getResourceString("CDescriptor.exception.providerNotFound"), null)); //$NON-NLS-1$ + } + IConfigurationElement element[] = extension.getConfigurationElements(); + for (int i = 0; i < element.length; i++) { + if (element[i].getName().equalsIgnoreCase(CEXTENSION_NAME)) { + return element[i].getChildren(); + } + } + return new IConfigurationElement[0]; + } + // The project data allows for the storage of any structured information // into the cdtproject file. private Document getProjectDataDoc() throws CoreException { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionReference.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionReference.java index 1126d682474..6f62c895d24 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionReference.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CExtensionReference.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core; import org.eclipse.cdt.core.ICExtension; import org.eclipse.cdt.core.ICExtensionReference; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; public class CExtensionReference implements ICExtensionReference { private CDescriptor fDescriptor; @@ -49,4 +50,7 @@ public class CExtensionReference implements ICExtensionReference { return fDescriptor.createExtensions(this); } + public IConfigurationElement[] getExtensionElements() throws CoreException { + return fDescriptor.getConfigurationElement(this); + } }