下面列出了org.eclipse.core.runtime.IExtensionPoint#getExtensions ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ScriptEngineFactoryManagerImpl( )
{
super( );
configs = new HashMap<String, IConfigurationElement>( );
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry( );
IExtensionPoint extensionPoint = extensionRegistry
.getExtensionPoint( "org.eclipse.birt.core.ScriptEngineFactory" );
IExtension[] extensions = extensionPoint.getExtensions( );
for ( IExtension extension : extensions )
{
IConfigurationElement[] configurations = extension
.getConfigurationElements( );
for ( IConfigurationElement configuration : configurations )
{
String scriptName = configuration.getAttribute( "scriptName" );
configs.put( scriptName, configuration );
}
}
}
/**
* Creates a new wizard element for the definition of the java code
* templates
*
* @return the wizard element corresponding to the project's template
*/
private WizardElement getTemplateWizard() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint("org.eclipse.ice.projectgeneration", PLUGIN_POINT);
if (point == null)
return null;
IExtension[] extensions = point.getExtensions();
for (int i = 0; i < extensions.length; i++) {
IConfigurationElement[] elements = extensions[i].getConfigurationElements();
for (int j = 0; j < elements.length; j++) {
if (elements[j].getName().equals(TAG_WIZARD)) {
if (TEMPLATE_ID.equals(elements[j].getAttribute(WizardElement.ATT_ID))) {
return WizardElement.create(elements[j]);
}
}
}
}
return null;
}
private static void createHelpDisplay() {
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(HELP_DISPLAY_EXTENSION_ID );
if (point != null) {
IExtension[] extensions = point.getExtensions();
if (extensions.length != 0) {
// We need to pick up the non-default configuration
IConfigurationElement[] elements = extensions[0]
.getConfigurationElements();
if (elements.length == 0)
return;
IConfigurationElement displayElement = elements[0];
// Instantiate the help display
try {
helpDisplay = (AbstractHelpDisplay) (displayElement
.createExecutableExtension(HELP_DISPLAY_CLASS_ATTRIBUTE));
} catch (CoreException e) {
HelpBasePlugin.logStatus(e.getStatus());
}
}
}
}
/**
* plugin.xmlからタグを読み込む.
*
* @throws CoreException
* @throws CoreException
*/
public static List<ExtendPopupMenu> loadExtensions(final ERDiagramEditor editor) throws CoreException {
final List<ExtendPopupMenu> extendPopupMenuList = new ArrayList<ExtendPopupMenu>();
final IExtensionRegistry registry = Platform.getExtensionRegistry();
final IExtensionPoint extensionPoint = registry.getExtensionPoint(EXTENSION_POINT_ID);
if (extensionPoint != null) {
for (final IExtension extension : extensionPoint.getExtensions()) {
for (final IConfigurationElement configurationElement : extension.getConfigurationElements()) {
final ExtendPopupMenu extendPopupMenu = ExtendPopupMenu.createExtendPopupMenu(configurationElement, editor);
if (extendPopupMenu != null) {
extendPopupMenuList.add(extendPopupMenu);
}
}
}
}
return extendPopupMenuList;
}
/**
* Returns proxies for all registered extensions; does not cause the extension plug-ins to be loaded.
* The proxies contain -- and can therefore be queried for -- all the XML attribute values that the
* extensions provide in their <i>plugin.xml</i> file. Throws IllegalArgumentException
* if extension point is unknown
*
* @return array of proxies
*/
public static ValidExtension[] getExtensions() {
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(PLUGIN_ID, EXTENSION_POINT_NAME);
if (point == null) {
throw new IllegalArgumentException(MessageFormat.format(UNKNOWN_EXTENSION_POINT, PLUGIN_ID, EXTENSION_POINT_NAME));
}
IExtension[] extensions = point.getExtensions();
List<ValidExtension> found = new ArrayList<ValidExtension>();
for (IExtension e : extensions) {
ValidExtension obj = ValidExtension.parseExtension(e);
if (obj != null) {
found.add(obj);
}
}
return found.toArray(new ValidExtension[found.size()]);
}
private void includeExtensionPartipants() throws CoreException {
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = extensionRegistry
.getExtensionPoint("com.gwtplugins.gdt.eclipse.suite.webAppCreatorParticipant");
if (extensionPoint == null) {
return;
}
IExtension[] extensions = extensionPoint.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement[] configurationElements = extension.getConfigurationElements();
for (IConfigurationElement configurationElement : configurationElements) {
Object createExecutableExtension = configurationElement.createExecutableExtension("class");
Participant participant = (Participant) createExecutableExtension;
participant.updateWebAppProjectCreator(this);
}
}
}
private IFileModificationValidator loadUIValidator() {
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(ID, DEFAULT_FILE_MODIFICATION_VALIDATOR_EXTENSION);
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
if (extensions.length > 0) {
IConfigurationElement[] configElements = extensions[0].getConfigurationElements();
if (configElements.length > 0) {
try {
Object o = configElements[0].createExecutableExtension("class"); //$NON-NLS-1$
if (o instanceof IFileModificationValidator) {
return (IFileModificationValidator)o;
}
} catch (CoreException e) {
SVNProviderPlugin.log(e.getStatus().getSeverity(), e.getMessage(), e);
}
}
}
}
return null;
}
/**
* Parses initial contributions.
*/
public void parseInitialContributions() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = registry.getExtensionPoint(SERVICE_REGISTERY_EXTENSION_POINT);
for (IExtension extension : extensionPoint.getExtensions()) {
add(extension);
}
}
private List<SimpleProxy<T>> createProxies(
String extensionPointName,
Class<T> klass,
String elementName,
String classNameAttr,
String forcePluginActivationAttr) {
List<SimpleProxy<T>> proxies = Lists.newArrayList();
// Load the reference to the extension.
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(
MechanicPlugin.PLUGIN_ID, extensionPointName);
if (point == null) {
LOG.log(Level.SEVERE,
"Cannot load extension point " + MechanicPlugin.PLUGIN_ID + "/" + extensionPointName);
return proxies;
}
// This loads all the registered extensions to this point.
IExtension[] extensions = point.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement[] configurationElements = extension.getConfigurationElements();
for (IConfigurationElement element : configurationElements) {
if (element.getName().equals(elementName)) {
SimpleProxy<T> proxy =
SimpleProxy.create(klass, element, classNameAttr, forcePluginActivationAttr);
// If parseType has an error, it returns null.
if (proxy != null) {
proxies.add(proxy);
}
}
}
}
return proxies;
}
/**
* Start the registry reading process using the supplied plugin ID and
* extension point.
*
* @param registry
* the registry to read from
* @param extensionPoint
* the fully qualified extension point id
*/
public void readRegistry(IExtensionRegistry registry, String extensionPoint) {
IExtensionPoint point = registry.getExtensionPoint(extensionPoint);
if (point == null) {
return;
}
IExtension[] extensions = point.getExtensions();
extensions = orderExtensions(extensions);
for (int i = 0; i < extensions.length; i++) {
readExtension(extensions[i]);
}
}
/**
* Gets a list of loader configuration elements from the extension point registry for a given view.
* @param viewId The view ID
* @return List of extension point configuration elements.
*/
private List<IConfigurationElement> getLoaderConfigurationElements(String viewId) {
List<IConfigurationElement> list = fViewLoadersList.get(viewId);
if (list != null) {
return list;
}
ArrayList<IConfigurationElement> ret = new ArrayList<>();
IExtensionPoint iep = Platform.getExtensionRegistry().getExtensionPoint(EXT_NAMESPACE, LOADER_TAG);
if (iep == null) {
return ret;
}
IExtension[] ie = iep.getExtensions();
if (ie == null) {
return ret;
}
for (int i = 0; i < ie.length; i++) {
IConfigurationElement c[] = ie[i].getConfigurationElements();
for (int j = 0; j < c.length; j++) {
if (viewId.equals(c[j].getAttribute("view"))) { //$NON-NLS-1$
ret.add(c[j]);
}
}
}
fViewLoadersList.put(viewId, ret);
return ret;
}
/**
* Load the plugins from the extension point, and fill the lists of entries.
*/
protected void load(String extensionId) {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint(extensionId);
if (null == point) {
return;
}
for (IExtension extension: point.getExtensions()) {
IContributor contrib = extension.getContributor();
String bundleId = contrib.getName();
// ... and for each elements
for (IConfigurationElement element :
extension.getConfigurationElements()) {
// obtain an object on the entry
ContributionEntry<T> entry = buildEntry(bundleId, element);
String entryId = entry.getId();
if (Strings.isNullOrEmpty(entryId)) {
LOG.warn("Empty entry id in {} for {}", bundleId, extensionId);
}
entries.put(entryId, entry);
// Try to instantiate the contribution and install it.
try {
T plugin = entry.prepareInstance();
installContribution(entryId, plugin);
} catch (CoreException err) {
reportException(entryId, err);
throw new RuntimeException(err);
}
}
}
}
protected List<Data<T>> getDataImpl(DataRetriever<T> c) {
List<Data<T>> classes = new ArrayList<Data<T>>();
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = pluginId == null ? extensionRegistry.getExtensionPoint(extensionPointName) :
extensionRegistry.getExtensionPoint(pluginId, extensionPointName);
// try old names: these need to be rewritten
if(extensionPoint == null && pluginId != null && pluginId.startsWith("com.gwtplugins")) {
String rewritten = pluginId.replace("com.gwtplugins", "com.google");
extensionPoint = extensionRegistry.getExtensionPoint(rewritten, extensionPointName);
if(extensionPoint != null) {
System.err.println(">>>> OLD EXTENSION POINT REFERENCE: " + pluginId);
new Throwable(">>>> OLD EXTENSION POINT REFERENCE: " + pluginId + " : " + extensionPointName).printStackTrace();
}
}
if (extensionPoint != null) {
IExtension[] extensions = extensionPoint.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement[] configurationElements = extension.getConfigurationElements();
for (IConfigurationElement configurationElement : configurationElements) {
T value = c.getData(configurationElement, attributeName);
if (value != null) {
classes.add(new Data<T>(value, configurationElement));
}
}
}
}
return classes;
}
public synchronized Map<String, MetricVisualisation> getRegisteredVisualisations() {
if (visMap == null) {
visMap = new HashMap<>();
} else {
// FIXME, this will not allow any viss to be added at runtime
return visMap;
}
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(extensionPointId);
if (extensionPoint != null) {
for (IExtension element : extensionPoint.getExtensions()) {
String name = element.getContributor().getName();
Bundle bundle = Platform.getBundle(name);
for (IConfigurationElement ice : element.getConfigurationElements()) {
String path = ice.getAttribute("json");
if (path!= null) {
// TODO: More validation is needed here, as it's very susceptible
// to error. Only load the chart if it passes validation.
URL url = bundle.getResource(path);
JsonNode json;
try {
json = loadJsonFile(url);
} catch (Exception e) {
//e.printStackTrace(); // FIXME
continue;
}
ArrayNode visses = (ArrayNode)json.get("vis");
for (JsonNode vis : visses) {
String chartType = vis.path("type").textValue();
String visName = vis.path("id").textValue();
// Legacy support
if (visName == null && vis.path("nicename").textValue() != null) {
visName = vis.path("nicename").textValue();
}
if (visMap.containsKey(visName)) {
// FIXME: Use logger.
System.err.println("Visualisation already defined for id '" + visName + "'. \nAttempted to add: " + vis + "\nPreviously registered: " + visMap.get(visName));
continue;
}
Chart chart = ChartExtensionPointManager.getInstance().findChartByType(chartType);
if (chart == null) {
// FIXME: Use logger.
System.err.println("Chart type '" + chartType + "' for visualisation '" + visName + "' not found in registry. ");
continue;
}
visMap.put(visName, new MetricVisualisation(chart, json, vis));
}
}
}
}
}
return visMap;
}
protected static Set<String> getInternalPageNames( )
{
Set<String> result = new HashSet<String>( );
result.add( DATASET_SETTINGS_PAGE );
result.add( OUTPUT_PARAMETER_PREVIEW_PAGE );
result.add( DATASOURCE_EDITOR_PROPERTY_PAGE );
result.add( COMPUTED_COLUMNS_PAGE );
result.add( RESULTSET_PREVIEW_PAGE );
result.add( FILTERS_PAGE );
result.add( PARAMETERS_PAGE );
result.add( OUTPUTCOLUMN_PAGE );
result.add( JOINT_DATA_SET_PAGE );
result.add( DATA_SOURCE_SELECTION_PAGE );
String extensionName = "org.eclipse.datatools.connectivity.oda.design.ui.dataSource";
IExtensionRegistry extReg = Platform.getExtensionRegistry( );
IExtensionPoint extPoint = extReg.getExtensionPoint( extensionName );
if ( extPoint == null )
return result;
IExtension[] exts = extPoint.getExtensions( );
if ( exts == null )
return result;
for ( int e = 0; e < exts.length; e++ )
{
IConfigurationElement[] configElems = exts[e].getConfigurationElements( );
if ( configElems == null )
continue;
for ( int i = 0; i < configElems.length; i++ )
{
if ( configElems[i].getName( ).equals( "dataSetUI" ) )
{
IConfigurationElement[] elems = configElems[i].getChildren( "dataSetPage" );
if ( elems != null && elems.length > 0 )
{
for ( int j = 0; j < elems.length; j++ )
{
String value = elems[j].getAttribute( "id" );
if ( value != null )
result.add( value );
}
}
}
}
}
return result;
}
private void loadDriverExtensions()
{
if ( loadedDriver )
// Already loaded
return;
synchronized( this )
{
if( loadedDriver )
return;
// First time: load all driverinfo extensions
driverExtensions = new HashMap();
IExtensionRegistry extReg = Platform.getExtensionRegistry();
/*
* getConfigurationElementsFor is not working for server Platform.
* I have to work around this by walking the extension list
IConfigurationElement[] configElems =
extReg.getConfigurationElementsFor( OdaJdbcDriver.Constants.DRIVER_INFO_EXTENSION );
*/
IExtensionPoint extPoint =
extReg.getExtensionPoint( OdaJdbcDriver.Constants.DRIVER_INFO_EXTENSION );
if ( extPoint == null )
return;
IExtension[] exts = extPoint.getExtensions();
if ( exts == null )
return;
for ( int e = 0; e < exts.length; e++)
{
IConfigurationElement[] configElems = exts[e].getConfigurationElements();
if ( configElems == null )
continue;
for ( int i = 0; i < configElems.length; i++ )
{
if ( configElems[i].getName().equals(
OdaJdbcDriver.Constants.DRIVER_INFO_ELEM_JDBCDRIVER) )
{
String driverClass = configElems[i].getAttribute(
OdaJdbcDriver.Constants.DRIVER_INFO_ATTR_DRIVERCLASS );
String connectionFactory = configElems[i].getAttribute(
OdaJdbcDriver.Constants.DRIVER_INFO_ATTR_CONNFACTORY );
logger.info("Found JDBC driverinfo extension: driverClass=" + driverClass + //$NON-NLS-1$
", connectionFactory=" + connectionFactory ); //$NON-NLS-1$
if ( driverClass != null && driverClass.length() > 0 &&
connectionFactory != null && connectionFactory.length() > 0 )
{
// This driver class has its own connection factory; cache it
// Note that the instantiation of the connection factory can wait
// until we actually need it
driverExtensions.put( driverClass, configElems[i] );
}
}
}
}
loadedDriver = true;
}
}
/**
* Find all elements of a given name for an extension point and delegate processing to an
* IConfigurationElementProcessor.
*
* @param pluginId
* @param extensionPointId
* @param processor
* @param elementNames
*/
public static void processConfigurationElements(String pluginId, String extensionPointId,
IConfigurationElementProcessor processor)
{
if (!StringUtil.isEmpty(pluginId) && !StringUtil.isEmpty(extensionPointId) && processor != null
&& !processor.getSupportElementNames().isEmpty())
{
IExtensionRegistry registry = Platform.getExtensionRegistry();
if (registry != null)
{
IExtensionPoint extensionPoint = registry.getExtensionPoint(pluginId, extensionPointId);
if (extensionPoint != null)
{
Set<String> elementNames = processor.getSupportElementNames();
IExtension[] extensions = extensionPoint.getExtensions();
for (String elementName : elementNames)
{
for (IExtension extension : extensions)
{
IConfigurationElement[] elements = extension.getConfigurationElements();
for (IConfigurationElement element : elements)
{
if (element.getName().equals(elementName))
{
processor.processElement(element);
if (IdeLog.isTraceEnabled(CorePlugin.getDefault(), IDebugScopes.EXTENSION_POINTS))
{
IdeLog.logTrace(
CorePlugin.getDefault(),
MessageFormat
.format("Processing extension element {0} with attributes {1}", element.getName(), //$NON-NLS-1$
collectElementAttributes(element)),
IDebugScopes.EXTENSION_POINTS);
}
}
}
}
}
}
}
}
}
private void loadPropertiesFromExtensions() {
ArrayList<SVNPropertyDefinition> propertyTypes = new ArrayList<SVNPropertyDefinition>();
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(SVNProviderPlugin.ID, SVNProviderPlugin.SVN_PROPERTY_TYPES_EXTENSION);
IExtension[] extensions = extensionPoint.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement[] configElements = extension.getConfigurationElements();
for (IConfigurationElement configElement : configElements) {
String name = configElement.getAttribute("name"); //$NON-NLS-1$
String type = configElement.getAttribute("type"); //$NON-NLS-1$
String fileOrFolder = configElement.getAttribute("fileOrFolder"); //$NON-NLS-1$
String allowRecurse = configElement.getAttribute("allowRecurse"); //$NON-NLS-1$
String description = "";
IConfigurationElement[] descriptionElements = configElement.getChildren("description");
if (descriptionElements.length == 1) {
description = descriptionElements[0].getValue();
}
int showFor;
if (fileOrFolder.equals("file")) showFor = SVNPropertyDefinition.FILE;
else if (fileOrFolder.equals("folder")) showFor = SVNPropertyDefinition.FOLDER;
else showFor = SVNPropertyDefinition.BOTH;
boolean recurse = true;
if ((allowRecurse != null) && (allowRecurse.equalsIgnoreCase("false"))) recurse = false;
SVNPropertyDefinition property = new SVNPropertyDefinition(name, description, showFor, recurse, type);
propertyTypes.add(property);
}
}
definitions = new SVNPropertyDefinition[propertyTypes.size()];
propertyTypes.toArray(definitions);
Arrays.sort(definitions);
ArrayList<SVNPropertyDefinition> fileProperties = new ArrayList<SVNPropertyDefinition>();
ArrayList<SVNPropertyDefinition> folderProperties = new ArrayList<SVNPropertyDefinition>();
for (SVNPropertyDefinition definition : definitions) {
if (definition.showForFile()) fileProperties.add(definition);
if (definition.showForFolder()) folderProperties.add(definition);
}
fileDefinitions = new SVNPropertyDefinition[fileProperties.size()];
fileProperties.toArray(fileDefinitions);
folderDefinitions = new SVNPropertyDefinition[folderProperties.size()];
folderProperties.toArray(folderDefinitions);
}
/**
* Loads all the provider extensions available. All extensions use the same extension id
* and they must implement the @see {@link IProviderExtension} interface.
*
* @return
*/
private static Map<Class<?>, IProviderExtension> loadExtensions() {
final HashMap<Class<?>, IProviderExtension> result = new HashMap<Class<?>, IProviderExtension>();
// Get a list of all registered provider extensions
IExtension extensions[] = null;
final IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
if (extensionRegistry != null) {
final IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(PROVIDER_EXTENSION_ID);
if (extensionPoint != null) {
extensions = extensionPoint.getExtensions();
}
}
if (extensions != null) {
// Walk through each extension in the list
for (final IExtension extension : extensions) {
final IConfigurationElement configElements[] = extension.getConfigurationElements();
if (configElements == null) {
continue;
}
for (final IConfigurationElement configElement : configElements) {
// We only handle providerDefinition elements for now
if (!(PROVIDER_DEFINITION.equalsIgnoreCase(configElement.getName()))) {
continue;
}
// The cast is safe because the extension point definition requires that the
// class implements this interface.
try {
final IProviderExtension ext = (IProviderExtension) configElement.createExecutableExtension(CLASS_NAME_ATTR);
for (final Class<?> intf : ext.provides()) {
final IProviderExtension oldext = result.put(intf, ext);
if (oldext != null) {
Logger.get().info(String.format("Extension %s replaced by %s for interface %s", // $NLI-ProviderFactory.Extensionsreplacedbysforinterface-1$
oldext.toString(),
ext.toString(),
intf.toString()));
}
}
} catch (final CoreException e) {
Logger.get().error(e, "Unable to create IProviderExtension"); // $NLE-ProviderFactory.UnabletocreateIProviderExtension-1$
}
}
}
}
return result;
}
/**
* Returns a list of JDBC drivers discovered in the driverInfo extensions,
* as an array of JDBCDriverInformation objects
*/
public JDBCDriverInformation[] getDriversInfo( )
{
if( jdbcDriverInfo!= null )
return jdbcDriverInfo;
synchronized( this )
{
if( jdbcDriverInfo!= null )
return jdbcDriverInfo;
IExtensionRegistry extReg = Platform.getExtensionRegistry();
IExtensionPoint extPoint =
extReg.getExtensionPoint( OdaJdbcDriver.Constants.DRIVER_INFO_EXTENSION );
if ( extPoint == null )
return new JDBCDriverInformation[0];
IExtension[] exts = extPoint.getExtensions();
if ( exts == null )
return new JDBCDriverInformation[0];
ArrayList<JDBCDriverInformation> drivers = new ArrayList<JDBCDriverInformation>( );
for ( int e = 0; e < exts.length; e++)
{
IConfigurationElement[] configElems = exts[e].getConfigurationElements();
if ( configElems == null )
continue;
for ( int i = 0; i < configElems.length; i++ )
{
if ( configElems[i].getName().equals(
OdaJdbcDriver.Constants.DRIVER_INFO_ELEM_JDBCDRIVER) )
{
drivers.add( newJdbcDriverInfo( configElems[i] ) );
}
}
}
jdbcDriverInfo = (JDBCDriverInformation[])drivers.toArray( new JDBCDriverInformation[0]);
}
return jdbcDriverInfo;
}