Search in sources :

Example 36 with ComponentLookupException

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;
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 37 with ComponentLookupException

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;
}
Also used : AbstractScriptMacroPermissionPolicy(org.xwiki.rendering.macro.script.AbstractScriptMacroPermissionPolicy) MacroPermissionPolicy(org.xwiki.rendering.macro.script.MacroPermissionPolicy) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 38 with ComponentLookupException

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);
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) ExtensionId(org.xwiki.extension.ExtensionId) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Test(org.junit.Test)

Example 39 with 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!");
}
Also used : ApplicationContextListenerManager(org.xwiki.container.ApplicationContextListenerManager) Container(org.xwiki.container.Container) ObservationManager(org.xwiki.observation.ObservationManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ApplicationStoppedEvent(org.xwiki.observation.event.ApplicationStoppedEvent)

Example 40 with ComponentLookupException

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));
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) WikiComponentBuilder(org.xwiki.component.wiki.WikiComponentBuilder) WikiComponent(org.xwiki.component.wiki.WikiComponent) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)104 ComponentManager (org.xwiki.component.manager.ComponentManager)24 Test (org.junit.Test)15 DocumentReference (org.xwiki.model.reference.DocumentReference)12 XWikiContext (com.xpn.xwiki.XWikiContext)10 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)10 InitializationException (org.xwiki.component.phase.InitializationException)8 ArrayList (java.util.ArrayList)7 XWikiException (com.xpn.xwiki.XWikiException)5 HashMap (java.util.HashMap)5 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)5 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)5 FilterException (org.xwiki.filter.FilterException)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 Type (java.lang.reflect.Type)4 HashSet (java.util.HashSet)4 WikiComponentException (org.xwiki.component.wiki.WikiComponentException)4 ExecutionContext (org.xwiki.context.ExecutionContext)4 WikiReference (org.xwiki.model.reference.WikiReference)4