下面列出了org.eclipse.core.runtime.IExtensionPoint#getConfigurationElements ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Return the available Actions provided by the Extension Registry.
*
* @return actions All Actions exposed in the Extension Registry.
*
* @throws CoreException
*/
public static Action[] getAvailableActions() throws CoreException {
/**
* Logger for handling event messages and other information.
*/
Logger logger = LoggerFactory.getLogger(Action.class);
Action[] actions = null;
String id = "org.eclipse.ice.item.actions";
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(id);
// If the point is available, create all the builders and load them into
// the array.
if (point != null) {
IConfigurationElement[] elements = point.getConfigurationElements();
actions = new Action[elements.length];
for (int i = 0; i < elements.length; i++) {
actions[i] = (Action) elements[i].createExecutableExtension("class");
}
} else {
logger.error("Extension Point " + id + "does not exist");
}
return actions;
}
private void launchExtension(String browserName, String url) throws CoreException {
if (browserName == null || browserName.isEmpty()) {
return;
}
// remove the id, which sets the default browser id
browserName = browserName.replace(BROWSER_NAME_EXTENSION, "");
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(IDebugLaunch.EXTENSION_ID);
IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
if (elements == null || elements.length == 0) {
return;
}
for (IConfigurationElement element : elements) {
IDebugLaunch debugLaunch = (IDebugLaunch) element.createExecutableExtension("class");
String label = element.getAttribute("label");
if (debugLaunch != null && label != null && label.equals(browserName)) {
debugLaunch.launch(project, url, "debug");
}
}
}
private synchronized void ensureCleanUpInitializersRegistered() {
if (fCleanUpInitializerDescriptors != null)
return;
ArrayList<CleanUpInitializerDescriptor> result= new ArrayList<CleanUpInitializerDescriptor>();
IExtensionPoint point= Platform.getExtensionRegistry().getExtensionPoint(JavaPlugin.getPluginId(), EXTENSION_POINT_NAME);
IConfigurationElement[] elements= point.getConfigurationElements();
for (int i= 0; i < elements.length; i++) {
IConfigurationElement element= elements[i];
if (CLEAN_UP_INITIALIZER_CONFIGURATION_ELEMENT_NAME.equals(element.getName())) {
result.add(new CleanUpInitializerDescriptor(element));
}
}
fCleanUpInitializerDescriptors= result.toArray(new CleanUpInitializerDescriptor[result.size()]);
}
/**
* This operation pulls the list of JAXB class providers from the registry
* for classes that need custom handling.
*
* @return The list of class providers.
* @throws CoreException
*/
public static IJAXBClassProvider[] getJAXBProviders() throws CoreException {
// Logger for handling event messages and other information.
Logger logger = LoggerFactory.getLogger(IJAXBClassProvider.class);
IJAXBClassProvider[] jaxbProviders = null;
String id = "org.eclipse.ice.datastructures.jaxbClassProvider";
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(id);
// If the point is available, create all the builders and load them into
// the array.
if (point != null) {
IConfigurationElement[] elements = point.getConfigurationElements();
jaxbProviders = new IJAXBClassProvider[elements.length];
for (int i = 0; i < elements.length; i++) {
jaxbProviders[i] = (IJAXBClassProvider) elements[i]
.createExecutableExtension("class");
}
} else {
logger.error("Extension Point " + id + " does not exist");
}
return jaxbProviders;
}
/**
* Find Configuration Elements from Extension Registry by Extension ID
*
* @param extensionId
* @return
*/
public static IConfigurationElement[] findConfigurationElementsByExtension(
String extensionId )
{
if ( extensionId == null )
return null;
// find Extension Point entry
IExtensionRegistry registry = Platform.getExtensionRegistry( );
IExtensionPoint extensionPoint = registry
.getExtensionPoint( extensionId );
if ( extensionPoint == null )
{
return null;
}
return extensionPoint.getConfigurationElements( );
}
/**
* This operation retrieves the IUpdateEventListener implementation from the
* ExtensionRegistry.
*
* @return The current default IUpdateEventListener implementation that were
* found in the registry.
* @throws CoreException
* This exception is thrown if an extension cannot be loaded.
*/
public static IUpdateEventListener getUpdateEventListener() throws CoreException {
/**
* Logger for handling event messages and other information.
*/
Logger logger = LoggerFactory.getLogger(IUpdateEventListener.class);
IUpdateEventListener listener = null;
String id = "org.eclipse.ice.client.updateEventListener";
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(id);
// If the point is available, create the listener
if (point != null) {
IConfigurationElement[] elements = point.getConfigurationElements();
listener = (IUpdateEventListener) elements[0].createExecutableExtension("class");
} else {
logger.error("Extension Point " + id + "does not exist");
}
return listener;
}
/**
* This operation retrieves the IProcessEventListener implementation from the
* ExtensionRegistry.
*
* @return The current default IProcessEventListener implementation that were
* found in the registry.
* @throws CoreException
* This exception is thrown if an extension cannot be loaded.
*/
public static IProcessEventListener getProcessEventListener() throws CoreException {
/**
* Logger for handling event messages and other information.
*/
Logger logger = LoggerFactory.getLogger(IProcessEventListener.class);
IProcessEventListener listener = null;
String id = "org.eclipse.ice.client.processEventListener";
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(id);
// If the point is available, create the listener
if (point != null) {
IConfigurationElement[] elements = point.getConfigurationElements();
listener = (IProcessEventListener) elements[0].createExecutableExtension("class");
} else {
logger.error("Extension Point " + id + "does not exist");
}
return listener;
}
/**
* Find Configuration Elements from Extension Registry by Extension ID
*
* @param extensionId
* @return
*/
public static IConfigurationElement[] findConfigurationElementsByExtension(
String extensionId )
{
if ( extensionId == null )
return null;
// find Extension Point entry
IExtensionRegistry registry = Platform.getExtensionRegistry( );
IExtensionPoint extensionPoint = registry.getExtensionPoint( extensionId );
if ( extensionPoint == null )
{
return null;
}
return extensionPoint.getConfigurationElements( );
}
/**
* Returns all configuration elements of appcontext extension point
*
* @return
*/
private static IConfigurationElement[] getConfigurationElements( )
{
// load extension point entry
IExtensionRegistry registry = Platform.getExtensionRegistry( );
IExtensionPoint extensionPoint = registry
.getExtensionPoint( APPCONTEXT_EXTENSION_ID );
if ( extensionPoint != null )
{
// get all configuration elements
return extensionPoint.getConfigurationElements( );
}
return null;
}
/**
* This operation retrieves all of the CompositeItemBuilders from the
* ExtensionRegistry.
*
* @return The array of CompositeItemBuilders that were found in the registry.
* @throws CoreException
* This exception is thrown if an extension cannot be loaded.
*/
public static ICompositeItemBuilder[] getCompositeItemBuilders() throws CoreException {
/**
* Logger for handling event messages and other information.
*/
Logger logger = LoggerFactory.getLogger(ICompositeItemBuilder.class);
ICompositeItemBuilder[] builders = null;
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(EXTENSION_ID);
// If the point is available, create all the builders and load them into
// the array.
if (point != null) {
IConfigurationElement[] elements = point.getConfigurationElements();
builders = new ICompositeItemBuilder[elements.length];
for (int i = 0; i < elements.length; i++) {
builders[i] = (ICompositeItemBuilder) elements[i]
.createExecutableExtension("class");
}
} else {
logger.error("Extension Point " + EXTENSION_ID + "does not exist");
}
return builders;
}
protected Stream<IBuildSupport> buildSupports() {
Map<Integer, IBuildSupport> supporters = new TreeMap<>();
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(IConstants.PLUGIN_ID, BUILD_SUPPORT_EXTENSION_POINT_ID);
IConfigurationElement[] configs = extensionPoint.getConfigurationElements();
for (IConfigurationElement config : configs) {
try {
Integer order = Integer.valueOf(config.getAttribute("order"));
supporters.put(order, (IBuildSupport) config.createExecutableExtension("class")); //$NON-NLS-1$
} catch (CoreException e) {
JavaLanguageServerPlugin.logError(config.getAttribute("class") + " implementation was skipped \n" + e.getStatus());
}
}
return supporters.values().stream();
}
/**
* This operation retrieves the persistence from the ExtensionRegistry.
*
* @return The provider
* @throws CoreException
* This exception is thrown if an extension cannot be loaded.
*/
public static IPersistenceProvider getProvider() throws CoreException {
// Logger for handling event messages and other information.
Logger logger = LoggerFactory.getLogger(IPersistenceProvider.class);
// The string identifying the persistence provider extension point.
String providerID = "org.eclipse.ice.core.persistenceProvider";
// The provider
IPersistenceProvider provider = null;
// Get the persistence provider from the extension registry.
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(providerID);
// Retrieve the provider from the registry and set it if one has not
// already been set.
if (point != null) {
// We only need one persistence provider, so just pull the
// configuration element for the first one available.
IConfigurationElement[] elements = point.getConfigurationElements();
if (elements.length > 0) {
IConfigurationElement element = elements[0];
provider = (IPersistenceProvider) element
.createExecutableExtension("class");
} else {
logger.info("No extensions found for IPersistenceProvider.");
}
} else {
logger.error("Extension Point " + providerID + "does not exist");
}
return provider;
}
/**
* This utility method is used to return the correct ITextContentDescriber
* so we can validate incoming IFiles being deleted as true ICE Item files.
*
* @param type
* @return
*/
private FormTextContentDescriber getFormTextContentDescriber(String type) {
// Local Declarations
FormTextContentDescriber describer = null;
String id = "org.eclipse.core.contenttype.contentTypes";
// Get the extension point
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(id);
// If the point is available, get a reference to the correct ITextContentDescriber
if (point != null) {
IConfigurationElement[] elements = point.getConfigurationElements();
for (IConfigurationElement e : elements) {
if ("content-type".equals(e.getName()) && type.equals(e.getAttribute("name"))) {
try {
describer = (FormTextContentDescriber) e.createExecutableExtension("describer");
} catch (CoreException e1) {
e1.printStackTrace();
logger.error("Could not get ITextContentDescriber " + type, e1);
}
}
}
} else {
logger.error("Extension Point " + id + "does not exist");
}
return describer;
}
public static ClasspathContainerDescriptor[] getDescriptors() {
ArrayList<ClasspathContainerDescriptor> containers= new ArrayList<ClasspathContainerDescriptor>();
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(JavaUI.ID_PLUGIN, ATT_EXTENSION);
if (extensionPoint != null) {
ClasspathContainerDescriptor defaultPage= null;
String defaultPageName= ClasspathContainerDefaultPage.class.getName();
IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
try {
ClasspathContainerDescriptor curr= new ClasspathContainerDescriptor(elements[i]);
if (!WorkbenchActivityHelper.filterItem(curr)) {
if (defaultPageName.equals(curr.getPageClass())) {
defaultPage= curr;
} else {
containers.add(curr);
}
}
} catch (CoreException e) {
JavaPlugin.log(e);
}
}
if (defaultPageName != null && containers.isEmpty()) {
// default page only added of no other extensions found
containers.add(defaultPage);
}
}
return containers.toArray(new ClasspathContainerDescriptor[containers.size()]);
}
/**
* This operation retrieves all of the IWidgetFactories from the
* ExtensionRegistry.
*
* @return The array of IWidgetFactories that were found in the registry.
* @throws CoreException
* This exception is thrown if an extension cannot be loaded.
*/
public static IWidgetFactory[] getIWidgetFactories() throws CoreException {
/**
* Logger for handling event messages and other information.
*/
Logger logger = LoggerFactory.getLogger(IWidgetFactory.class);
IWidgetFactory[] builders = null;
String id = "org.eclipse.ice.client.IWidgetFactory";
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(id);
// If the point is available, create all the builders and load them into
// the array.
if (point != null) {
IConfigurationElement[] elements = point.getConfigurationElements();
builders = new IWidgetFactory[elements.length];
for (int i = 0; i < elements.length; i++) {
builders[i] = (IWidgetFactory) elements[i]
.createExecutableExtension("class");
}
} else {
logger.error("Extension Point " + id + "does not exist");
}
return builders;
}
@Override
public void initialize(IPreferenceStoreAccess access) {
if (this.initializers == null) {
this.initializers = new ArrayList<>();
final IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(
SARLUiConfig.NAMESPACE, SARLUiConfig.EXTENSION_POINT_EXTRA_LANGUAGE_GENERATORS);
if (extensionPoint != null) {
Object obj;
for (final IConfigurationElement element : extensionPoint.getConfigurationElements()) {
try {
obj = element.createExecutableExtension(EXTENSION_POINT_PREFERENCE_INITIALIZER_ATTRIBUTE);
if (obj instanceof IPreferenceStoreInitializer) {
this.initializers.add((IPreferenceStoreInitializer) obj);
}
} catch (CoreException exception) {
LangActivator.getInstance().getLog().log(new Status(
IStatus.WARNING,
LangActivator.getInstance().getBundle().getSymbolicName(),
exception.getLocalizedMessage(),
exception));
}
}
}
}
for (final IPreferenceStoreInitializer initializer : this.initializers) {
initializer.initialize(access);
}
}
/**
* Test for
* {@link org.eclipse.ice.datastructures.jaxbclassprovider.IJAXBClassProvider}
* .
*
* @throws CoreException
* @throws BundleException
* @throws ClassNotFoundException
* @throws URISyntaxException
* @throws FileNotFoundException
*/
// This test fails in the Tycho build, so it is disabled by default.
@Ignore
@Test
public void test() throws CoreException, BundleException,
ClassNotFoundException, URISyntaxException, FileNotFoundException {
IJAXBClassProvider[] jaxbProviders = null;
String id = "org.eclipse.ice.datastructures.jaxbClassProvider";
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(id);
// If the point is available, create all the builders and load them into
// the array.
IConfigurationElement[] elements = point.getConfigurationElements();
jaxbProviders = new IJAXBClassProvider[elements.length];
for (int i = 0; i < elements.length; i++) {
jaxbProviders[i] = (IJAXBClassProvider) elements[i]
.createExecutableExtension("class");
}
// Simply get the providers from the registry and make sure they are
// actually there.
IJAXBClassProvider[] providers = IJAXBClassProvider.getJAXBProviders();
assertNotNull(providers);
assertTrue(providers.length > 0);
return;
}
/**
* Populates the language catalog from the extension registry.
*/
private void initLanguages() {
IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(FrontEnd.PLUGIN_ID, "frontEndLanguage");
IConfigurationElement[] elements = point.getConfigurationElements();
languages = new HashMap<String, FrontEndLanguage>();
for (int i = 0; i < elements.length; i++) {
FrontEndLanguage current = FrontEndLanguage.build(elements[i]);
languages.put(current.fileExtension, current);
}
}
private synchronized void ensureCleanUpsRegistered() {
if (fCleanUpDescriptors != null)
return;
final ArrayList<CleanUpDescriptor> descriptors= new ArrayList<CleanUpDescriptor>();
IExtensionPoint point= Platform.getExtensionRegistry().getExtensionPoint(JavaPlugin.getPluginId(), EXTENSION_POINT_NAME);
IConfigurationElement[] elements= point.getConfigurationElements();
for (int i= 0; i < elements.length; i++) {
IConfigurationElement element= elements[i];
if (CLEAN_UP_CONFIGURATION_ELEMENT_NAME.equals(element.getName())) {
descriptors.add(new CleanUpDescriptor(element));
}
}
// Make sure we filter those who fail or misbehave
for (int i= 0; i < descriptors.size(); i++) {
final CleanUpDescriptor cleanUpDescriptor= descriptors.get(i);
final boolean disable[]= new boolean[1];
ISafeRunnable runnable= new SafeRunnable() {
public void run() throws Exception {
ICleanUp cleanUp= cleanUpDescriptor.createCleanUp();
if (cleanUp == null)
disable[0]= true;
else {
cleanUp.setOptions(new CleanUpOptions());
String[] enbledSteps= cleanUp.getStepDescriptions();
if (enbledSteps != null && enbledSteps.length > 0) {
JavaPlugin.logErrorMessage(
Messages.format(FixMessages.CleanUpRegistry_cleanUpAlwaysEnabled_error, new String[] { cleanUpDescriptor.getId(),
cleanUpDescriptor.fElement.getContributor().getName() }));
disable[0]= true;
}
}
}
@Override
public void handleException(Throwable t) {
disable[0]= true;
String message= Messages.format(FixMessages.CleanUpRegistry_cleanUpCreation_error, new String[] { cleanUpDescriptor.getId(),
cleanUpDescriptor.fElement.getContributor().getName() });
IStatus status= new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, t);
JavaPlugin.log(status);
}
};
SafeRunner.run(runnable);
if (disable[0])
descriptors.remove(i--);
}
fCleanUpDescriptors= descriptors.toArray(new CleanUpDescriptor[descriptors.size()]);
sort(fCleanUpDescriptors);
}
private void loadSystemPackages() {
systemResources.clear();
IExtensionPoint xp = RegistryFactory.getRegistry().getExtensionPoint(MDDCore.PLUGIN_ID, "systemPackage");
IConfigurationElement[] configElems = xp.getConfigurationElements();
for (int i = 0; i < configElems.length; i++) {
boolean autoLoad = !Boolean.FALSE.toString().equals(configElems[i].getAttribute("autoLoad"));
if (!autoLoad)
continue;
String uriValue = configElems[i].getAttribute("uri");
URI uri = URI.createURI(uriValue);
String requirements = configElems[i].getAttribute("requires");
if (requirements != null) {
String[] propertyEntries = requirements.split(",");
if (propertyEntries.length > 0) {
boolean satisfied = true;
for (String current : propertyEntries) {
String[] components = StringUtils.split(current, '=');
String propertyName = components[0];
String expectedValue = components.length > 1 ? components[1] : Boolean.TRUE.toString();
String actualValue = properties.getProperty(propertyName, System.getProperty(current));
if (!expectedValue.equals(actualValue)) {
satisfied = false;
break;
}
}
if (!satisfied) {
LogUtils.debug(MDDCore.PLUGIN_ID, () -> "System package skipped: " + uri);
continue;
}
}
}
try {
boolean lazyLoad = !Boolean.FALSE.toString().equals(configElems[i].getAttribute("lazyLoad"));
Package systemPackage = getPackage(uri, lazyLoad);
if (systemPackage != null) {
addSystemPackage(systemPackage);
LogUtils.debug(MDDCore.PLUGIN_ID, "Loading system package: " + uri);
} else {
LogUtils.logError(MDDCore.PLUGIN_ID, "System package not found: " + uri, null);
}
} catch (WrappedException e) {
if (!(e instanceof Diagnostic))
throw e;
LogUtils.logError(MDDCore.PLUGIN_ID, "Unexpected exception loading system package: " + uri, e);
}
}
}