Search in sources :

Example 81 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class XWikiServletContextListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    // Initializes the Embeddable Component Manager
    EmbeddableComponentManager ecm = new EmbeddableComponentManager();
    // Initialize all the components. Note that this can fail with a Runtime Exception. This is done voluntarily so
    // that the XWiki webapp will not be available if one component fails to load. It's better to fail-fast.
    ecm.initialize(this.getClass().getClassLoader());
    this.componentManager = ecm;
    // This is a temporary bridge to allow non XWiki components to lookup XWiki components.
    // We're putting the XWiki Component Manager instance in the Servlet Context so that it's
    // available in the XWikiAction class which in turn puts it into the XWikiContext instance.
    // Class that need to lookup then just need to get it from the XWikiContext instance.
    // This is of course not necessary for XWiki components since they just need to implement
    // the Composable interface to get access to the Component Manager or better they simply
    // need to declare their components requirements using the @Inject annotation of the xwiki
    // component manager together with a private class member, for automatic injection by the CM on init.
    servletContextEvent.getServletContext().setAttribute(org.xwiki.component.manager.ComponentManager.class.getName(), this.componentManager);
    // Use a Component Event Manager that stacks Component instance creation events till we tell it to flush them.
    // The reason is that the Observation Manager used to send the events but we need the Application Context to
    // be set up before we start sending events since there can be Observation Listener components that require
    // the Application Context (this is the case for example for the Office Importer Lifecycle Listener).
    StackingComponentEventManager eventManager = new StackingComponentEventManager();
    this.componentManager.setComponentEventManager(eventManager);
    // Initialize the Environment
    try {
        ServletEnvironment servletEnvironment = this.componentManager.getInstance(Environment.class);
        servletEnvironment.setServletContext(servletContextEvent.getServletContext());
    } catch (ComponentLookupException e) {
        throw new RuntimeException("Failed to initialize the Servlet Environment", e);
    }
    // below in an Event Listener and move it to the legacy module.
    try {
        ServletContainerInitializer containerInitializer = this.componentManager.getInstance(ServletContainerInitializer.class);
        containerInitializer.initializeApplicationContext(servletContextEvent.getServletContext());
    } catch (ComponentLookupException e) {
        throw new RuntimeException("Failed to initialize the Application Context", e);
    }
    // Send an Observation event to signal the XWiki application is started. This allows components who need to do
    // something on startup to do it.
    ObservationManager observationManager;
    try {
        observationManager = this.componentManager.getInstance(ObservationManager.class);
    } catch (ComponentLookupException e) {
        throw new RuntimeException("Failed to find the Observation Manager component", e);
    }
    // Now that the Application Context is set up, send the Component instance creation events we had stacked up.
    eventManager.setObservationManager(observationManager);
    eventManager.shouldStack(false);
    eventManager.flushEvents();
    // Make sure installed extensions are initialized before sending ApplicationStartedEvent
    try {
        this.componentManager.getInstance(ExtensionInitializer.class);
    } catch (ComponentLookupException e) {
        throw new RuntimeException("Failed to initialize installed extensions", e);
    }
    // Indicate to the various components that XWiki is ready
    observationManager.notify(new ApplicationStartedEvent(), this);
}
Also used : EmbeddableComponentManager(org.xwiki.component.embed.EmbeddableComponentManager) ApplicationStartedEvent(org.xwiki.observation.event.ApplicationStartedEvent) EmbeddableComponentManager(org.xwiki.component.embed.EmbeddableComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ObservationManager(org.xwiki.observation.ObservationManager) StackingComponentEventManager(org.xwiki.component.internal.StackingComponentEventManager) ServletEnvironment(org.xwiki.environment.internal.ServletEnvironment)

Example 82 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class JobRootResourceReferenceHandler method handleChild.

private void handleChild(ParentResourceReference reference) throws ResourceReferenceHandlerException {
    if (StringUtils.isNotEmpty(reference.getChild())) {
        ComponentManager componentManager = this.componentManagerProvider.get();
        if (componentManager.hasComponent(JobResourceReferenceHandler.class, reference.getChild())) {
            JobResourceReferenceHandler child;
            try {
                child = componentManager.getInstance(JobResourceReferenceHandler.class, reference.getChild());
            } catch (ComponentLookupException e) {
                throw new ResourceReferenceHandlerException("Failed to initialize job resource handler with hint [" + reference.getChild() + "]");
            }
            child.handle(reference);
        } else {
            throw new ResourceReferenceHandlerException("Unknow job resource handler with hint [" + reference.getChild() + "]");
        }
    } else {
    // TODO: put some explanation about the various services provided by the job resource handler
    }
}
Also used : ResourceReferenceHandlerException(org.xwiki.resource.ResourceReferenceHandlerException) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 83 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class AnnotationVelocityContextInitializer method initialize.

@Override
public void initialize(VelocityContext context) {
    try {
        // create a wrapper of the annotation service for exposing its methods in velocity
        ScriptService annotationsScriptService = componentManager.getInstance(ScriptService.class, ANNOTATION_SCRIPT_SERVICE_HINT);
        context.put(VELOCITY_CONTEXT_KEY, annotationsScriptService);
    } catch (ComponentLookupException e) {
        this.logger.warn("Could not initialize the annotations velocity bridge, " + "annotations service will not be accessible in velocity context.");
    }
}
Also used : ScriptService(org.xwiki.script.service.ScriptService) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 84 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DocumentTreeNode method initialize.

@Override
public void initialize() throws InitializationException {
    String[] nonLeafChildNodeTypes = new String[] { "translations", "attachments", "classProperties", "objects" };
    ComponentManager contextComponentManager = this.contextComponentManagerProvider.get();
    try {
        for (String nonLeafChildNodeType : nonLeafChildNodeTypes) {
            TreeNode treeNode = contextComponentManager.getInstance(TreeNode.class, nonLeafChildNodeType);
            this.nonLeafChildNodes.put(nonLeafChildNodeType, treeNode);
        }
    } catch (ComponentLookupException e) {
        throw new InitializationException("Failed to lookup the child components.", e);
    }
}
Also used : TreeNode(org.xwiki.tree.TreeNode) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InitializationException(org.xwiki.component.phase.InitializationException)

Example 85 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DefaultDocumentRevisionProvider method getRevision.

@Override
public XWikiDocument getRevision(DocumentReference reference, String revision) throws XWikiException {
    // Parse the version
    String revisionPrefix = null;
    if (revision != null) {
        int revisionPrefixIndex = revision.indexOf(':');
        if (revisionPrefixIndex > 0) {
            revisionPrefix = revision.substring(0, revisionPrefixIndex);
        }
    }
    String shortRevision;
    if (revisionPrefix != null) {
        shortRevision = revision.substring(revisionPrefix.length() + 1);
    } else {
        shortRevision = revision;
    }
    // Find the provider
    DocumentRevisionProvider provider = this.databaseDocumentRevisionProvider;
    if (revisionPrefix != null) {
        ComponentManager componentManager = this.componentManagerProvider.get();
        if (componentManager.hasComponent(DocumentRevisionProvider.class, revisionPrefix)) {
            try {
                provider = componentManager.getInstance(DocumentRevisionProvider.class, revisionPrefix);
            } catch (ComponentLookupException e) {
                throw new XWikiException("Failed to get revision provider for revision [" + revision + "]", e);
            }
        }
    }
    // Load the document revision
    return provider.getRevision(reference, shortRevision);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) DocumentRevisionProvider(com.xpn.xwiki.doc.DocumentRevisionProvider) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) XWikiException(com.xpn.xwiki.XWikiException)

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