Search in sources :

Example 1 with RendererFactory

use of org.apache.sling.junit.RendererFactory in project sling by apache.

the class RendererSelectorImpl method getRenderer.

public Renderer getRenderer(TestSelector selector) {
    if (renderersTracker.getTrackingCount() != renderersTrackerTrackingCount) {
        log.debug("Rebuilding list of {}", Renderer.class.getSimpleName());
        renderersTrackerTrackingCount = renderersTracker.getTrackingCount();
        final ServiceReference[] refs = renderersTracker.getServiceReferences();
        renderers.clear();
        if (refs != null) {
            for (ServiceReference ref : refs) {
                renderers.add((Renderer) bundleContext.getService(ref));
            }
        }
        log.info("List of {} rebuilt: {}", Renderer.class.getSimpleName(), renderers);
    }
    for (Renderer r : renderers) {
        if (r.appliesTo(selector)) {
            if (r instanceof RendererFactory) {
                return ((RendererFactory) r).createRenderer();
            }
            throw new UnsupportedOperationException("Renderers must implement RendererFactory, this one does not:" + r);
        }
    }
    return null;
}
Also used : RendererFactory(org.apache.sling.junit.RendererFactory) Renderer(org.apache.sling.junit.Renderer) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

Renderer (org.apache.sling.junit.Renderer)1 RendererFactory (org.apache.sling.junit.RendererFactory)1 ServiceReference (org.osgi.framework.ServiceReference)1