Package org.osgi.service.component

Examples of org.osgi.service.component.ComponentContext


     */
    private void lazyInitialization() {
        if (!this.initialized) {
            this.initialized = true;
            // activate service in simulated OSGi environment
            ComponentContext componentContext = MockOsgi.newComponentContext();
            this.bindLogService(MockOsgi.newLogService(getClass()));
            activate(componentContext);
        }
    }
View Full Code Here


     * @param target Service instance.
     * @return true if activation method was called. False if such a method did
     *         not exist.
     */
    public static boolean activate(Object target) {
        ComponentContext componentContext = newComponentContext();
        return ReflectionServiceUtil.activateDeactivate(target, componentContext, true);
    }
View Full Code Here

     * @param properties Properties
     * @return true if activation method was called. False if such a method did
     *         not exist.
     */
    public static boolean activate(Object target, Dictionary<String, Object> properties) {
        ComponentContext componentContext = newComponentContext(properties);
        return ReflectionServiceUtil.activateDeactivate(target, componentContext, true);
    }
View Full Code Here

     * @param properties Properties
     * @return true if activation method was called. False if such a method did
     *         not exist.
     */
    public static boolean activate(Object target, BundleContext bundleContext, Dictionary<String, Object> properties) {
        ComponentContext componentContext = newComponentContext(bundleContext, properties);
        return ReflectionServiceUtil.activateDeactivate(target, componentContext, true);
    }
View Full Code Here

     * @param target Service instance.
     * @return true if deactivation method was called. False if such a method
     *         did not exist.
     */
    public static boolean deactivate(Object target) {
        ComponentContext componentContext = newComponentContext();
        return ReflectionServiceUtil.activateDeactivate(target, componentContext, false);
    }
View Full Code Here

     * @param properties Properties
     * @return true if deactivation method was called. False if such a method
     *         did not exist.
     */
    public static boolean deactivate(Object target, Dictionary<String, Object> properties) {
        ComponentContext componentContext = newComponentContext(properties);
        return ReflectionServiceUtil.activateDeactivate(target, componentContext, false);
    }
View Full Code Here

     * @param properties Properties
     * @return true if deactivation method was called. False if such a method
     *         did not exist.
     */
    public static boolean deactivate(Object target, BundleContext bundleContext, Dictionary<String, Object> properties) {
        ComponentContext componentContext = newComponentContext(bundleContext, properties);
        return ReflectionServiceUtil.activateDeactivate(target, componentContext, false);
    }
View Full Code Here

    @Test
    public void testProvidedProperties() {
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put("prop1", "value1");
        props.put("prop2", 25);
        ComponentContext componentContextWithProperties = MockOsgi.newComponentContext(props);

        Dictionary contextProps = componentContextWithProperties.getProperties();
        assertEquals(2, contextProps.size());
        assertEquals("value1", contextProps.get("prop1"));
        assertEquals(25, contextProps.get("prop2"));
    }
View Full Code Here

     * Helper method to create a mock component context
     */
    protected ComponentContext createComponentContext() throws Exception {
        final BundleContext bundleCtx = this.context.mock(BundleContext.class);
        final Filter filter = this.context.mock(Filter.class);
        final ComponentContext ctx = this.context.mock(ComponentContext.class);
        this.context.checking(new Expectations() {{
            allowing(ctx).locateService(with(any(String.class)), with(any(ServiceReference.class)));
            will(returnValue(new MockAdapterFactory()));
            allowing(ctx).getBundleContext();
            will(returnValue(bundleCtx));
View Full Code Here

     * Helper method to create a mock component context
     */
    protected ComponentContext createMultipleAdaptersComponentContext(final ServiceReference firstServiceReference, final ServiceReference secondServiceReference) throws Exception {
        final BundleContext bundleCtx = this.context.mock(BundleContext.class);
        final Filter filter = this.context.mock(Filter.class);
        final ComponentContext ctx = this.context.mock(ComponentContext.class);
        this.context.checking(new Expectations() {{
            allowing(ctx).locateService(with(any(String.class)), with(firstServiceReference));
            will(returnValue(new FirstImplementationAdapterFactory()));
            allowing(ctx).locateService(with(any(String.class)), with(secondServiceReference));
            will(returnValue(new SecondImplementationAdapterFactory()));
View Full Code Here

TOP

Related Classes of org.osgi.service.component.ComponentContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.