com.day.cq.wcm.core.contentfinder.ContentFinderListInfoProviderHelper Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2012 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.day.cq.wcm.core.contentfinder;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.commons.ListInfoProvider;
import com.day.cq.commons.servlets.AbstractPredicateServlet;
/**
*/
@Component(componentAbstract = true)
@Reference(
referenceInterface = ListInfoProvider.class,
name = "listInfoProvider",
policy = ReferencePolicy.DYNAMIC,
cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE
)
public abstract class ContentFinderListInfoProviderHelper extends AbstractPredicateServlet {
private static final Logger LOG = LoggerFactory.getLogger(ContentFinderListInfoProviderHelper.class);
private static final long serialVersionUID = 7018564321415615254L;
private ComponentContext componentContext;
private List listInfoProviders = new CopyOnWriteArrayList();
protected void pingCallbacksWithItem(SlingHttpServletRequest request, JSONObject jsonObject, Resource resource) {
for (ServiceReference ref : listInfoProviders) {
ListInfoProvider listInfoProvider = (ListInfoProvider) componentContext.locateService("listInfoProvider", ref);
if (listInfoProvider != null) {
try {
listInfoProvider.updateListItemInfo(request, jsonObject, resource);
} catch (JSONException e) {
LOG.error("Unable to update jsonObject", e);
}
}
}
}
// OSGi ################################################################################################################################
protected void activate(ComponentContext componentContext) {
this.componentContext = componentContext;
}
protected void deactivate(ComponentContext componentContext) {
this.componentContext = null;
}
protected void bindListInfoProvider(ServiceReference ref) {
listInfoProviders.add(ref);
}
protected void unbindListInfoProvider(ServiceReference ref) {
listInfoProviders.remove(ref);
}
}