/** * @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 */ public static <T> List<T> getComponentList(Class<T> role) { List<T> components; if (componentManager != null) { try { components = componentManager.lookupList(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; }
/** * {@inheritDoc} * * @see VelocityContextFactory#createContext() */ public VelocityContext createContext() throws XWikiVelocityException { // Note: This constructor uses the passed context as an internal read-only context. VelocityContext context = new VelocityContext(this.toolsContext); // Call all components implementing the VelocityContextInitializer's role. try { for (Object interceptor : this.componentManager.lookupList(VelocityContextInitializer.class)) { ((VelocityContextInitializer) interceptor).initialize(context); } } catch (ComponentLookupException e) { throw new XWikiVelocityException("Failed to locate some Velocity Context initializers", e); } return context; } }
/** * {@inheritDoc} * @see org.xwiki.container.RequestInitializerManager#initializeRequest(Request) */ public void initializeRequest(Request request) throws RequestInitializerException { // Find all request interceptors and call them to initialize the Request try { for (Object interceptor : this.componentManager.lookupList(RequestInitializer.class)) { ((RequestInitializer) interceptor).initialize(request); } } catch (ComponentLookupException e) { throw new RequestInitializerException("Failed to initialize request", e); } } }
/** * {@inheritDoc} * <p> * Register all components implementing the {@link EventListener} interface. * * @see Initializable#initialize() */ public void initialize() throws InitializationException { try { for (EventListener listener : this.componentManager.lookupList(EventListener.class)) { addListener(listener); } } catch (ComponentLookupException e) { throw new InitializationException("Failed to lookup Event Listeners", e); } }
/** * {@inheritDoc} * <p> * Register all components implementing the {@link EventListener} interface. * * @see Initializable#initialize() */ public void initialize() throws InitializationException { try { for (EventListener listener : this.componentManager.lookupList(EventListener.class)) { addListener(listener); } } catch (ComponentLookupException e) { throw new InitializationException("Failed to lookup Event Listeners", e); } }
/** * Gets all syntaxes supported by the rendering parsers as an input for a syntax conversion. * * @param token The authentication token. * @return A list containing all syntaxes supported by rendering parsers. * @throws Exception An invalid token is provided or the syntax lookup fails. */ public List<String> getInputSyntaxes(String token) throws Exception { XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext); List<String> syntaxes = new ArrayList<String>(); List<Parser> parsers; ComponentManager componentManager = Utils.getComponentManager(); try { parsers = componentManager.lookupList(Parser.class); for (Parser parser : parsers) { syntaxes.add(parser.getSyntax().toIdString()); } } catch (ComponentLookupException e) { throw new RuntimeException("Failed to lookup the list of available parser syntaxes", e); } return syntaxes; }
/** * Gets all syntaxes supported by the rendering as an output for a syntax conversion. * * @param token The authentication token. * @return A list containing all syntaxes supported by renderers. * @throws Exception An invalid token is provided or the syntax lookup fails. */ public List<String> getOutputSyntaxes(String token) throws Exception { XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext); List<String> syntaxes = new ArrayList<String>(); List<PrintRendererFactory> renderers; ComponentManager componentManager = Utils.getComponentManager(); try { // TODO: use BlockRenderer renderers = componentManager.lookupList(PrintRendererFactory.class); for (PrintRendererFactory renderer : renderers) { syntaxes.add(renderer.getSyntax().toIdString()); } } catch (ComponentLookupException e) { throw new RuntimeException("Failed to lookup the list of available renderer syntaxes", e); } return syntaxes; }
/** * {@inheritDoc} */ public void initializeApplicationContext(ApplicationContext applicationContext) { try { List<ApplicationContextListener> initializers = this.componentManager.lookupList(ApplicationContextListener.class); for (ApplicationContextListener initializer : initializers) { initializer.initializeApplicationContext(applicationContext); } } catch (ComponentLookupException ex) { getLogger().error(ex.getMessage(), ex); } }
/** * {@inheritDoc} */ public void destroyApplicationContext(ApplicationContext applicationContext) { try { List<ApplicationContextListener> initializers = this.componentManager.lookupList(ApplicationContextListener.class); for (ApplicationContextListener initializer : initializers) { initializer.destroyApplicationContext(applicationContext); } } catch (ComponentLookupException ex) { getLogger().error(ex.getMessage(), ex); } } }