Search in sources :

Example 1 with ComponentContext

use of org.apache.felix.dm.context.ComponentContext in project felix by apache.

the class ConfigurationDependencyImplTest method createConfigurationDependency.

private ConfigurationDependencyImpl createConfigurationDependency(Object service) {
    BundleContext bc = mock(BundleContext.class);
    Logger mockLogger = mock(Logger.class);
    ComponentContext component = mock(ComponentContext.class);
    when(component.getExecutor()).thenReturn(Executors.newSingleThreadExecutor());
    when(component.getLogger()).thenReturn(mockLogger);
    ConfigurationDependencyImpl result = new ConfigurationDependencyImpl(bc, mockLogger);
    result.setCallback(service, "updated").setPid("does.not.matter");
    result.setComponentContext(component);
    result.start();
    return result;
}
Also used : ComponentContext(org.apache.felix.dm.context.ComponentContext) Logger(org.apache.felix.dm.Logger) BundleContext(org.osgi.framework.BundleContext)

Example 2 with ComponentContext

use of org.apache.felix.dm.context.ComponentContext in project felix by apache.

the class ComponentBuilderImpl method invokeCallbacks.

private void invokeCallbacks(Component component, Object callbackInstance, String callback, String defaultCallback) {
    boolean logIfNotFound = (callback != null);
    callback = callback != null ? callback : defaultCallback;
    ComponentContext ctx = (ComponentContext) component;
    Object[] instances = callbackInstance != null ? new Object[] { callbackInstance } : ctx.getInstances();
    ctx.invokeCallbackMethod(instances, callback, new Class[][] { { Component.class }, {} }, new Object[][] { { component }, {} }, logIfNotFound);
}
Also used : ComponentContext(org.apache.felix.dm.context.ComponentContext) InstanceCbComponent(org.apache.felix.dm.lambda.callbacks.InstanceCbComponent) Component(org.apache.felix.dm.Component)

Example 3 with ComponentContext

use of org.apache.felix.dm.context.ComponentContext in project felix by apache.

the class Helpers method isDependencyRequiredByDefault.

/**
 * Is a dependency required by default ?
 *
 * @param c the component on which the dependency is added
 * @param ctx the bundle context
 * @return true if the dependency is required by default, false if not
 */
public static boolean isDependencyRequiredByDefault(Component c) {
    BundleContext ctx = ((ComponentContext) c).getBundleContext();
    String defaultRequiredDependency = ctx.getProperty(DEFAULT_REQUIRED_DEPENDENCY);
    if (defaultRequiredDependency != null) {
        defaultRequiredDependency = defaultRequiredDependency.trim();
        String componentName = c.getComponentDeclaration().getClassName();
        for (String pkg : defaultRequiredDependency.split(",")) {
            if (componentName.startsWith(pkg)) {
                return true;
            }
        }
    }
    return false;
}
Also used : ComponentContext(org.apache.felix.dm.context.ComponentContext) BundleContext(org.osgi.framework.BundleContext)

Aggregations

ComponentContext (org.apache.felix.dm.context.ComponentContext)3 BundleContext (org.osgi.framework.BundleContext)2 Component (org.apache.felix.dm.Component)1 Logger (org.apache.felix.dm.Logger)1 InstanceCbComponent (org.apache.felix.dm.lambda.callbacks.InstanceCbComponent)1