1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

helper method for getting extension elements of a cextension.

This commit is contained in:
David Inglis 2004-03-03 20:51:11 +00:00
parent 918addbcbc
commit e73afe6adb
3 changed files with 90 additions and 28 deletions

View file

@ -7,37 +7,81 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core; package org.eclipse.cdt.core;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
public interface ICExtensionReference { public interface ICExtensionReference {
/** /**
* Return the extension point of this reference. * Return the extension point of this reference.
* @return String *
*/ * @return String
public String getExtension(); */
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. * Creates and returns a new instance of the cextension executable
* @return String * identified by the <run> attribute of the cextension.
* <p>
* The ICExtension is instantiated using its 0-argument public
* constructor. If the class implements the
* <code>IExecutableExtension</code> interface, the method
* <code>setInitializationData</code> is called, passing to the object
* the configuration information that was used to create it.
* </p>
* <p>
* Unlike other methods on this object, invoking this method may activate
* the plug-in.
* </p>
*
* @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(); public ICExtension createExtension() throws CoreException;
/**
* 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() * Returns all configuration elements that are children of the
*/ * cextension element. Returns an empty array if this configuration
public String getExtensionData(String key); * element has no children.
* <p>
/** * Each child corresponds to a nested XML element in the configuration
* Creates the executable extension for the reference. * markup. For example, the configuration markup
*/ *
public ICExtension createExtension() throws CoreException; * <pre>
* &lt;view&gt;
* &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&lt;verticalHint&gt;top&lt;/verticalHint&gt;
* &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&lt;horizontalHint&gt;left&lt;/horizontalHint&gt;
* &lt;/view&gt;
* </pre>
*
* corresponds to a configuration element, named <code>"view"</code>,
* with two children.
* </p>
*
* @return the child configuration elements
*/
public IConfigurationElement[] getExtensionElements() throws CoreException;
} }

View file

@ -16,7 +16,6 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -60,12 +59,12 @@ public class CDescriptor implements ICDescriptor {
private HashMap extInfoMap = new HashMap(4); private HashMap extInfoMap = new HashMap(4);
private Document dataDoc; private Document dataDoc;
static final String CEXTENSION_NAME = "cextension"; //$NON-NLS-1$
static final String DESCRIPTION_FILE_NAME = ".cdtproject"; //$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 char[][] NO_CHAR_CHAR = new char[0][];
private static final String PROJECT_DESCRIPTION = "cdtproject"; //$NON-NLS-1$ 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 = "extension"; //$NON-NLS-1$
private static final String PROJECT_EXTENSION_ATTRIBUTE = "attribute"; //$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 = "data"; //$NON-NLS-1$
private static final String PROJECT_DATA_ITEM = "item"; //$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$ 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) { private void readProjectDescription(Node node) {
Node childNode; Node childNode;
ArrayList pathEntries = new ArrayList();
NodeList list = node.getChildNodes(); NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) { for (int i = 0; i < list.getLength(); i++) {
childNode = list.item(i); childNode = list.item(i);
@ -397,7 +395,7 @@ public class CDescriptor implements ICDescriptor {
} }
IConfigurationElement element[] = extension.getConfigurationElements(); IConfigurationElement element[] = extension.getConfigurationElements();
for (int i = 0; i < element.length; i++) { 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 = (InternalCExtension) element[i].createExecutableExtension("run"); //$NON-NLS-1$
cExtension.setExtenionReference(ext); cExtension.setExtenionReference(ext);
cExtension.setProject(fProject); cExtension.setProject(fProject);
@ -407,6 +405,22 @@ public class CDescriptor implements ICDescriptor {
return (ICExtension) cExtension; 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 // The project data allows for the storage of any structured information
// into the cdtproject file. // into the cdtproject file.
private Document getProjectDataDoc() throws CoreException { private Document getProjectDataDoc() throws CoreException {

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core;
import org.eclipse.cdt.core.ICExtension; import org.eclipse.cdt.core.ICExtension;
import org.eclipse.cdt.core.ICExtensionReference; import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
public class CExtensionReference implements ICExtensionReference { public class CExtensionReference implements ICExtensionReference {
private CDescriptor fDescriptor; private CDescriptor fDescriptor;
@ -49,4 +50,7 @@ public class CExtensionReference implements ICExtensionReference {
return fDescriptor.createExtensions(this); return fDescriptor.createExtensions(this);
} }
public IConfigurationElement[] getExtensionElements() throws CoreException {
return fDescriptor.getConfigurationElement(this);
}
} }