use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class Utils method getComponentList.
/**
* @param <T> the component type
* @param role the role for which to return implementing components
* @return all components implementing the passed role
* @throws RuntimeException if some of the components cannot be found/initialized, or if the component manager is
* not initialized
* @since 2.0M3
* @deprecated since 4.0M1 use {@link #getComponentManager()} instead
*/
@Deprecated
public static <T> List<T> getComponentList(Class<T> role) {
List<T> components;
ComponentManager componentManager = getContextComponentManager();
if (componentManager != null) {
try {
components = componentManager.getInstanceList(role);
} catch (ComponentLookupException e) {
throw new RuntimeException("Failed to load components with role [" + role.getName() + "]", e);
}
} else {
throw new RuntimeException("Component manager has not been initialized before lookup for role [" + role.getName() + "]");
}
return components;
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class DefaultScriptMacroPermissionPolicy method hasPermission.
@Override
public boolean hasPermission(ScriptMacroParameters parameters, MacroTransformationContext context) {
boolean hasPermission;
try {
MacroPermissionPolicy policy = this.componentManager.getInstance(MacroPermissionPolicy.class, ((DefaultScriptMacroParameters) parameters).getLanguage());
hasPermission = policy.hasPermission(parameters, context);
} catch (ComponentLookupException e) {
// No policy for that Macro, use the default implementation which forbids execution if the doc doesn't
// have Programming Rights.
hasPermission = super.hasPermission(parameters, context);
}
return hasPermission;
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class ExtensionInstallerTest method installExtensionWithException.
@Test
public void installExtensionWithException() throws Exception {
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version"));
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to install the extension [extensionId/version] on the wiki [wikiId].", caughtException.getMessage());
assertTrue(caughtException.getCause() instanceof ComponentLookupException);
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class XWikiServletContextListener method contextDestroyed.
@Override
public void contextDestroyed(ServletContextEvent sce) {
SHUTDOWN_LOGGER.debug("Stopping XWiki...");
// It's possible that the Component Manager failed to initialize some of the required components.
if (this.componentManager != null) {
// to do something on stop to do it.
try {
ObservationManager observationManager = this.componentManager.getInstance(ObservationManager.class);
observationManager.notify(new ApplicationStoppedEvent(), this);
} catch (ComponentLookupException e) {
// Nothing to do here.
// TODO: Log a warning
}
// below in an Event Listener and move it to the legacy module.
try {
ApplicationContextListenerManager applicationContextListenerManager = this.componentManager.getInstance(ApplicationContextListenerManager.class);
Container container = this.componentManager.getInstance(Container.class);
applicationContextListenerManager.destroyApplicationContext(container.getApplicationContext());
} catch (ComponentLookupException ex) {
// Nothing to do here.
// TODO: Log a warning
}
// Make sure to dispose all components before leaving
this.componentManager.dispose();
}
SHUTDOWN_LOGGER.debug("XWiki has been stopped!");
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class DefaultWikiComponentManagerEventListener method registerAllDocumentComponents.
/**
* Register all the wiki components that come from a document in the current wiki.
*/
private void registerAllDocumentComponents() {
try {
// Retrieve all components definitions and register them.
this.wikiComponentProviders = this.componentManager.getInstanceList(WikiComponentBuilder.class);
for (WikiComponentBuilder provider : this.wikiComponentProviders) {
for (DocumentReference reference : provider.getDocumentReferences()) {
try {
List<WikiComponent> components = provider.buildComponents(reference);
this.wikiComponentManagerEventListenerHelper.registerComponentList(components);
} catch (WikiComponentException e) {
this.logger.warn("Failed to build the wiki component located in the document [{}]: {}", reference, ExceptionUtils.getRootCauseMessage(e));
}
}
}
} catch (ComponentLookupException e) {
this.logger.warn(String.format("Unable to get a list of registered WikiComponentBuilder: %s", e));
}
}
Aggregations