use of org.xwiki.rest.XWikiRestComponent in project xwiki-platform by xwiki.
the class ComponentsObjectFactory method getInstance.
@Override
public <T> T getInstance(Class<T> clazz) throws InstantiateException {
try {
ComponentManager componentManager = this.componentManagerProvider.get();
// Use the component manager to lookup the class. This ensure that injections are properly executed.
XWikiRestComponent component = componentManager.getInstance(XWikiRestComponent.class, clazz.getName());
// JAX-RS resources and providers must be declared as components whose hint is the FQN of the class
// implementing it. This is needed because of they are looked up using the FQN as the hint.
ComponentDescriptor<XWikiRestComponent> componentDescriptor = componentManager.getComponentDescriptor(XWikiRestComponent.class, clazz.getName());
// Retrieve the list of releasable components from the execution context. This is used to store component
// instances that need to be released at the end of the request.
ExecutionContext executionContext = this.execution.getContext();
List<XWikiRestComponent> releasableComponentReferences = (List<XWikiRestComponent>) executionContext.getProperty(Constants.RELEASABLE_COMPONENT_REFERENCES);
if (releasableComponentReferences == null) {
releasableComponentReferences = new ArrayList<>();
executionContext.setProperty(Constants.RELEASABLE_COMPONENT_REFERENCES, releasableComponentReferences);
}
// Only add the components that have a per-lookup instantiation strategy.
if (componentDescriptor.getInstantiationStrategy() == ComponentInstantiationStrategy.PER_LOOKUP) {
releasableComponentReferences.add(component);
}
// component hint to the actual fully qualified name of the Java class.
return (T) component;
} catch (ComponentLookupException e) {
throw new InstantiateException(e);
}
}
use of org.xwiki.rest.XWikiRestComponent in project xwiki-platform by xwiki.
the class XWikiSetupCleanupFilter method getReleasableComponents.
/**
* @param componentManager the component manager
* @return the list of JAX-RS resources that are implemented as components with per-lookup policy and that have been
* instantiated during this request
*/
private List<XWikiRestComponent> getReleasableComponents(ComponentManager componentManager) {
try {
ExecutionContext executionContext = componentManager.<Execution>getInstance(Execution.class).getContext();
@SuppressWarnings("unchecked") List<XWikiRestComponent> releasableComponents = (List<XWikiRestComponent>) executionContext.getProperty(Constants.RELEASABLE_COMPONENT_REFERENCES);
return releasableComponents != null ? releasableComponents : Collections.<XWikiRestComponent>emptyList();
} catch (Exception e) {
getLogger().log(Level.WARNING, "Failed to retrieve the list of releasable components.", e);
return Collections.emptyList();
}
}
Aggregations