Skip to content

Instantly share code, notes, and snippets.

@cescoffier
Created November 29, 2013 13:45
Show Gist options
  • Save cescoffier/7705901 to your computer and use it in GitHub Desktop.
Save cescoffier/7705901 to your computer and use it in GitHub Desktop.
package components;
import org.apache.felix.ipojo.annotations.*;
import org.apache.felix.ipojo.architecture.PropertyDescription;
import org.apache.felix.ipojo.dependency.interceptors.DefaultServiceTrackingInterceptor;
import org.apache.felix.ipojo.dependency.interceptors.ServiceTrackingInterceptor;
import org.apache.felix.ipojo.dependency.interceptors.TransformedServiceReference;
import org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler;
import org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription;
import org.apache.felix.ipojo.util.DependencyModel;
import org.osgi.framework.BundleContext;
import java.util.Arrays;
/**
* Created with IntelliJ IDEA.
* User: clement
* Date: 29/11/2013
* Time: 11:24
* To change this template use File | Settings | File Templates.
*/
@Component(immediate = true)
@Provides
@Instantiate
public class Interceptor extends DefaultServiceTrackingInterceptor implements ServiceTrackingInterceptor {
private final BundleContext context;
@ServiceProperty
private String target = "(instance.name=components.FooComponent-0)";
public Interceptor(BundleContext context) {
this.context = context;
}
@Override
public <S> TransformedServiceReference<S> accept(DependencyModel dependency, BundleContext context, TransformedServiceReference<S> ref) {
ConfigurationHandlerDescription h = (ConfigurationHandlerDescription) dependency.getComponentInstance().getInstanceDescription()
.getHandlerDescription("org.apache.felix.ipojo:properties");
if (h == null) {
return ref;
}
PropertyDescription description = h.getPropertyByName("ids");
if (description == null) {
return ref;
}
System.out.println(description.getValue() + " / " + Arrays.toString(
(String[]) description.getCurrentValue()));
return ref;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment