Java Code Examples for org.eclipse.core.runtime.IExtension#getConfigurationElements()

The following examples show how to use org.eclipse.core.runtime.IExtension#getConfigurationElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSetProvider.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param dataSetType
 * @param dataSourceType
 * @return
 */
public static IConfigurationElement findDataSetElement( String dataSetType,
		String dataSourceType )
{
	// NOTE: multiple data source types can support the same data set type
	IConfigurationElement dataSourceElem = findDataSourceElement( dataSourceType );
	if ( dataSourceElem != null )
	{
		// Find data set declared in the same extension
		IExtension ext = dataSourceElem.getDeclaringExtension( );
		IConfigurationElement[] elements = ext.getConfigurationElements( );
		for ( int n = 0; n < elements.length; n++ )
		{
			if ( elements[n].getAttribute( "id" ).equals( dataSetType ) ) //$NON-NLS-1$
			{
				return elements[n];
			}
		}
	}
	return null;
}
 
Example 2
Source File: RegisteredGenmodelTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Ignore @Test public void testCanResolveGenmodelURIs() {
	String declaringPlugin = "org.eclipse.emf.ecore";
	String pointId = "generated_package";
	IExtensionPoint point = registry.getExtensionPoint(declaringPlugin + "." + pointId);
	IExtension[] extensions = point.getExtensions();
	for(IExtension extension: extensions) {
		IConfigurationElement[] configurationElements = extension.getConfigurationElements();
		for(IConfigurationElement configurationElement: configurationElements) {
			String attribute = configurationElement.getAttribute("genModel");
			if (attribute != null && attribute.length() != 0) {
				String name = extension.getContributor().getName();
				String uriAsString = "platform:/plugin/" + name + "/" + attribute;
				URI uri = URI.createURI(uriAsString);
				boolean exists = URIConverter.INSTANCE.exists(uri, Collections.emptyMap());
				if (!exists) {
						fail(uriAsString + " does not exist");
				}
			}
		}
	}
}
 
Example 3
Source File: DeclaredTokensListener.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * adds an extension to this.
 * 
 * @param extension
 *            the extension
 */
private void add(IExtension extension) {
    for (IConfigurationElement element : extension.getConfigurationElements()) {
        if (TOKEN_ELEMENT_NAME.equals(element.getName())) {
            final String tokenName = element.getAttribute(SERVICE_TOKEN_ATTR_NAME);
            final String bundleName = extension.getContributor().getName();
            final List<String> services = new ArrayList<String>();
            final List<String> packages = new ArrayList<String>();
            for (IConfigurationElement child : element.getChildren()) {
                if (SERVICE_ELEMENT_NAME.equals(child.getName())) {
                    final String className = child.getAttribute(SERVICE_CLASS_ATTR_NAME);
                    services.add(className);
                } else if (PACKAGE_ELEMENT_NAME.equals(child.getName())) {
                    final String uri = child.getAttribute(URI_ATTR_NAME);
                    packages.add(uri);
                } else {
                    throw new IllegalStateException("unknown extension name");
                }
            }
            TokenRegistry.INSTANCE.registerServices(tokenName, bundleName, services);
            TokenRegistry.INSTANCE.registerPackages(tokenName, packages);
        }
    }
}
 
Example 4
Source File: Extensions.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Eine Liste von IConfigurationElements (=komplette Definition) liefern, die an einem
 * bestimmten Extensionpoint hängen, und den entsprechenden Elementnamen haben
 * 
 * @param ext
 * @param elementName
 * @return
 * @since 3.3
 */
public static List<IConfigurationElement> getExtensions(String ext, String elementName){
	List<IConfigurationElement> ret = new LinkedList<IConfigurationElement>();
	IExtensionRegistry exr = Platform.getExtensionRegistry();
	IExtensionPoint exp = exr.getExtensionPoint(ext);
	if (exp != null) {
		IExtension[] extensions = exp.getExtensions();
		for (IExtension ex : extensions) {
			IConfigurationElement[] elems = ex.getConfigurationElements();
			for (IConfigurationElement el : elems) {
				if (elementName != null) {
					if (elementName.equals(el.getName())) {
						ret.add(el);
					}
				} else {
					ret.add(el);
				}
			}
		}
		
	}
	return ret;
}
 
Example 5
Source File: ReportEngine.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
EngineExtensionManager( )
{
	IExtensionRegistry registry = Platform.getExtensionRegistry( );
	IExtensionPoint extensionPoint = registry
			.getExtensionPoint( "org.eclipse.birt.core.FactoryService" );
	IExtension[] extensions = extensionPoint.getExtensions( );
	for ( IExtension extension : extensions )
	{
		IConfigurationElement[] elements = extension
				.getConfigurationElements( );
		for ( IConfigurationElement element : elements )
		{
			String type = element.getAttribute( "type" );
			if ( "org.eclipse.birt.report.engine.extension"
					.equals( type ) )
			{
				try
				{
					Object factoryObject = element
							.createExecutableExtension( "class" );
					if ( factoryObject instanceof IReportEngineExtensionFactory )
					{
						IReportEngineExtensionFactory factory = (IReportEngineExtensionFactory) factoryObject;
						IReportEngineExtension engineExtension = factory
								.createExtension( ReportEngine.this );
						exts.put( engineExtension.getExtensionName( ),
								engineExtension );
					}
				}
				catch ( CoreException ex )
				{
					logger.log( Level.WARNING,
									"can not load the engine extension factory",
							ex );
				}
			}
		}
	}
}
 
Example 6
Source File: ExtensionPointManager.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private ExtendedElementUIPoint createReportItemUIPoint( IExtension extension )
{
	IConfigurationElement[] elements = extension.getConfigurationElements( );
	if ( elements != null && elements.length > 0 )
	{
		return loadElements( elements );
	}
	return null;
}
 
Example 7
Source File: ExtensionQuery.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: Activator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void initializeInjector(BundleContext context) throws CoreException {
	IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(PLUGIN_ID + ".overridingGuiceModule");
	IExtension[] extensions = point.getExtensions();
	Module module = new SharedModule(context);
	if (extensions.length != 0) {
		int numberOfMixedInModules = 0;
		for (IExtension iExtension : extensions) {
			IConfigurationElement[] elements = iExtension.getConfigurationElements();
			for (IConfigurationElement e : elements) {
				try {
					Module m = (Module) e.createExecutableExtension("class");
					module = Modules.override(module).with(m);
					numberOfMixedInModules++;
					if (numberOfMixedInModules == 2) {
						log.warn("Multiple overriding guice modules. Will use them in unspecified order.");
					}
				} catch (CoreException e1) {
					log.error(e1.getMessage(), e1);
				}
			}
		}
	}

	try {
		injector = Guice.createInjector(module);
		injector.createChildInjector(new Module() {
			@Override
			public void configure(Binder binder) {
				binder.bind(EagerContributionInitializer.class);
			}
		}).injectMembers(this);
	} catch (Throwable t) {
		handleGuiceInitializationError(t);
	}
}
 
Example 9
Source File: ExtensionRegistry.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public IConfigurationElement[] getConfigurationElementsFor(
		String extensionId )
{
	IExtension extension = getExtension( extensionId );
	if ( extension != null )
	{
		return extension.getConfigurationElements( );
	}
	return null;
}
 
Example 10
Source File: SimpleExtensionPointManager.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: ClassProviderRegistryListener.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parses a single {@link ILocation} extension contribution.
 * 
 * @param extension
 *            Parses the given extension and adds its contribution to the registry
 */
private void parseClassProviderExtension(IExtension extension) {
    final IConfigurationElement[] configElements = extension.getConfigurationElements();
    for (IConfigurationElement element : configElements) {
        if (CLASS_PROVIDER_TAG_EXTENSION.equals(element.getName())) {
            final IClassProviderDescriptor descriptor = new ExtensionClassProviderDescriptor(element);
            descriptors.put(element.getAttribute(CLASS_PROVIDER_ATTRIBUTE_CLASS), descriptor);
            M2DocPlugin.registerClassProvider(descriptor);
        }
    }
}
 
Example 12
Source File: ClassProviderRegistryListener.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.core.runtime.IRegistryEventListener#removed(org.eclipse.core.runtime.IExtension[])
 */
public void removed(IExtension[] extensions) {
    for (IExtension extension : extensions) {
        final IConfigurationElement[] configElements = extension.getConfigurationElements();
        for (IConfigurationElement element : configElements) {
            if (CLASS_PROVIDER_TAG_EXTENSION.equals(element.getName())) {
                final IClassProviderDescriptor descriptor = descriptors
                        .remove(element.getAttribute(CLASS_PROVIDER_ATTRIBUTE_CLASS));
                if (descriptor != null) {
                    M2DocPlugin.unregisterClassProvider(descriptor);
                }
            }
        }
    }
}
 
Example 13
Source File: ExtensionRegistry.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public IConfigurationElement[] getConfigurationElementsFor(
		String namespace, String extensionPointName, String extensionId )
{
	IExtension extension = getExtension( namespace, extensionPointName,
			extensionId );
	if ( extension == null )
		return new IConfigurationElement[0];
	return extension.getConfigurationElements( );
}
 
Example 14
Source File: DeclaredTemplatesListener.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void removed(IExtension[] extensions) {
    for (IExtension extension : extensions) {
        if (TEMPLATE_REGISTERY_EXTENSION_POINT.equals(extension.getExtensionPointUniqueIdentifier())) {
            for (IConfigurationElement element : extension.getConfigurationElements()) {
                if (TEMPLATE_ELEMENT_NAME.equals(element.getName())) {
                    final String templateName = element.getAttribute(NAME_ATTR_NAME);
                    TemplateRegistry.INSTANCE.unregisterTemplate(templateName);
                }
            }
        }
    }
}
 
Example 15
Source File: DeclaredTemplatesListener.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * adds an extension to this.
 * 
 * @param extension
 *            the extension
 */
private void add(IExtension extension) {
    for (IConfigurationElement element : extension.getConfigurationElements()) {
        if (TEMPLATE_ELEMENT_NAME.equals(element.getName())) {
            final String templateName = element.getAttribute(NAME_ATTR_NAME);
            final String templateURIString = element.getAttribute(URI_ATTR_NAME);
            TemplateRegistry.INSTANCE.registerTemplate(templateName, URI.createURI(templateURIString));
        }
    }
}
 
Example 16
Source File: DeclaredTokensListener.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void removed(IExtension[] extensions) {
    for (IExtension extension : extensions) {
        if (SERVICE_REGISTERY_EXTENSION_POINT.equals(extension.getExtensionPointUniqueIdentifier())) {
            for (IConfigurationElement element : extension.getConfigurationElements()) {
                if (TOKEN_ELEMENT_NAME.equals(element.getName())) {
                    final String tokenName = element.getAttribute(SERVICE_TOKEN_ATTR_NAME);
                    final String bundleName = extension.getContributor().getName();
                    final List<String> services = new ArrayList<String>();
                    final List<String> packages = new ArrayList<String>();
                    for (IConfigurationElement child : element.getChildren()) {
                        if (SERVICE_ELEMENT_NAME.equals(child.getName())) {
                            final String className = child.getAttribute(SERVICE_CLASS_ATTR_NAME);
                            services.add(className);
                        } else if (PACKAGE_ELEMENT_NAME.equals(child.getName())) {
                            final String uri = child.getAttribute(URI_ATTR_NAME);
                            packages.add(uri);
                        } else {
                            throw new IllegalStateException("unknown extension name");
                        }
                    }
                    TokenRegistry.INSTANCE.unregisterServices(tokenName, bundleName, services);
                    TokenRegistry.INSTANCE.unregisterPackages(tokenName, packages);
                }
            }
        }
    }
}
 
Example 17
Source File: ChartExtensionPointManager.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public Map<String, Chart> getRegisteredCharts() {
	if (chartMap == null) {
		chartMap = new HashMap<>();
	}
	
	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;
					}
					chartMap.put(json.path("name").textValue(), new Chart(json));
				}
			}
		}
	}
	return chartMap;
}
 
Example 18
Source File: JSONExtensionRegistry.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a list of executable extensions of type {@code extensionClass} from all registered extension class for
 * the given extension point IDs.
 * 
 * Returns an empty list if {@link IExtensionRegistry} is no available (platform not running).
 * 
 * @param extensionPointId
 *            The extension point ID.
 * @param extensionClass
 *            The expected extension class.
 */
private <T> List<T> createExecutableExtensions(String extensionPointId, Class<T> extensionClass) {
	final IExtensionRegistry registry = RegistryFactory.getRegistry();
	if (registry == null) {
		return Collections.emptyList();
	}

	final IExtension[] extensions = registry.getExtensionPoint(extensionPointId)
			.getExtensions();

	final List<T> executableExtensions = new ArrayList<>();

	for (IExtension extension : extensions) {
		final IConfigurationElement[] configElems = extension.getConfigurationElements();
		for (IConfigurationElement elem : configElems) {
			try {
				final Object executableExtension = elem
						.createExecutableExtension(JSON_EXTENSIONS_POINT_CLASS_PROPERTY);
				executableExtensions.add(extensionClass.cast(executableExtension));
			} catch (Exception ex) {
				LOGGER.error("Error while reading extensions for extension point "
						+ JSON_VALIDATORS_EXTENSIONS_POINT_ID, ex);
			}
		}
	}

	return executableExtensions;
}
 
Example 19
Source File: JSONUiExtensionRegistry.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a list of executable extensions of type {@code extensionClass} from
 * all registered extension class for the given extension point IDs.
 * 
 * Returns an empty list if {@link IExtensionRegistry} is no available (platform
 * not running).
 * 
 * @param extensionPointId
 *            The extension point ID.
 * @param extensionClass
 *            The expected extension class.
 */
private <T> List<T> createExecutableExtensions(String extensionPointId, Class<T> extensionClass) {
	final IExtensionRegistry registry = RegistryFactory.getRegistry();
	if (registry == null) {
		return Collections.emptyList();
	}

	final IExtension[] extensions = registry.getExtensionPoint(extensionPointId).getExtensions();

	final List<T> executableExtensions = new ArrayList<>();

	for (IExtension extension : extensions) {
		final IConfigurationElement[] configElems = extension.getConfigurationElements();
		for (IConfigurationElement elem : configElems) {
			try {
				final Object executableExtension = elem
						.createExecutableExtension(JSON_EXTENSIONS_POINT_CLASS_PROPERTY);
				executableExtensions.add(extensionClass.cast(executableExtension));
			} catch (Exception ex) {
				LOGGER.error("Error while reading extensions for extension point "
						+ JSON_QUICKFIXPROVIDER_EXTENSIONS_POINT_ID, ex);
			}
		}
	}

	return executableExtensions;
}
 
Example 20
Source File: ICEExtensionContributionFactory.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void createContributionItems(IServiceLocator serviceLoc, IContributionRoot additions) {

	// Local Declarations
	HashMap<String, MenuManager> categoryMenus = new HashMap<String, MenuManager>();
	String codeName = "", category = "";
	MenuManager codeMenu = null;

	// Set the ServiceLocator
	serviceLocator = serviceLoc;

	// Create the Developer Menu Item
	developerMenu = new MenuManager("&Developer", "iceDev");

	// Get the registry and the extensions
	registry = Platform.getExtensionRegistry();

	// Create the category sub-menus
	for (CodeCategory c : CodeCategory.values()) {
		MenuManager manager = new MenuManager(c.name(), c.name() + "ID");
		manager.setVisible(true);
		categoryMenus.put(c.name(), manager);
		developerMenu.add(manager);
	}

	// Get the Extension Points
	IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.ice.developer.code");
	IExtension[] codeExtensions = extensionPoint.getExtensions();

	// Loop over the rest of the Extensions and create
	// their sub-menus.
	for (IExtension code : codeExtensions) {
		// Get the name of the bundle this extension comes from
		// so we can instantiate its AbstractHandlers
		String contributingPlugin = code.getContributor().getName();

		// Get the elements of this extension
		IConfigurationElement[] elements = code.getConfigurationElements();
		for (IConfigurationElement e : elements) {
			// Get the Code Name
			codeName = e.getAttribute("codeName");
			
			// Get whether this is the ICE declaration
			boolean isICE = "ICE".equals(codeName);
			
			// Get the Code Category - Framework, Physics, etc...
			category = isICE ? codeName : e.getAttribute("codeCategory");

			// Create a sub menu for the code in the
			// correct category, if this is not ICE ( we've already done it for ICE)
			codeMenu = isICE ? categoryMenus.get(codeName)
					: new MenuManager(codeName, codeName + "ID");

			// Generate the IParameters for the Command
			generateParameters(e);

			// Create a menu item for each extra command they provided
			for (IConfigurationElement command : e.getChildren("command")) {
				generateParameters(command);
				createCommand(contributingPlugin, command.getAttribute("implementation"), codeMenu);
			}

			// Add it to the correct category menu
			if (!"ICE".equals(codeName)) {
				categoryMenus.get(category).add(codeMenu);
			}
		}
		
		parameters.clear();
	}

	// Add the newly constructed developer menu
	additions.addContributionItem(developerMenu, null);

	return;
}