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);
}
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
}
}
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.");
}
}
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);
}
}
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);
}
Aggregations