Package org.osgi.framework

Examples of org.osgi.framework.BundleContext


            } catch (Exception e) {
                logger.logError("Unable to instantiate build listener: " + elem.getAttribute("name"), e);
            }
        }

        BundleContext context = FrameworkUtil.getBundle(BuildListeners.class).getBundleContext();

        listenerTracker = new ServiceTracker(context, BuildListener.class.getName(), null);
        listenerTracker.open();
    }
View Full Code Here


            protected ThreadInvocationCounter initialValue() {
                return new ThreadInvocationCounter(maxRecursionDepth);
            }
        };

        BundleContext bundleContext = ctx.getBundleContext();
        this.queue = new ReferenceQueue<Object>();
        this.disposalCallbacks = new ConcurrentHashMap<java.lang.ref.Reference<Object>, DisposalCallbackRegistryImpl>();
        Hashtable<Object, Object> properties = new Hashtable<Object, Object>();
        properties.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
        properties.put(Constants.SERVICE_DESCRIPTION, "Sling Models OSGi Service Disposal Job");
        properties.put("scheduler.concurrent", false);
        properties.put("scheduler.period", Long.valueOf(30));

        this.jobRegistration = bundleContext.registerService(Runnable.class.getName(), this, properties);

        this.listener = new ModelPackageBundleListener(ctx.getBundleContext(), this, this.adapterImplementations);

        Hashtable<Object, Object> printerProps = new Hashtable<Object, Object>();
        printerProps.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
        printerProps.put(Constants.SERVICE_DESCRIPTION, "Sling Models Configuration Printer");
        printerProps.put("felix.webconsole.label", "slingmodels");
        printerProps.put("felix.webconsole.title", "Sling Models");
        printerProps.put("felix.webconsole.configprinter.modes", "always");

        this.configPrinterRegistration = bundleContext.registerService(Object.class.getName(),
                new ModelConfigurationPrinter(this), printerProps);
    }
View Full Code Here

    @Test
    public void test() {
        AdaptableTest sampleObject = new AdaptableTest();
        assertNull(sampleObject.adaptTo(String.class));

        BundleContext bundleContext = MockOsgi.newBundleContext();
        MockSling.setAdapterManagerBundleContext(bundleContext);

        bundleContext.registerService(AdapterFactory.class.getName(), new AdapterFactory() {
            @SuppressWarnings("unchecked")
            @Override
            public <AdapterType> AdapterType getAdapter(final Object adaptable, final Class<AdapterType> type) {
                if (adaptable instanceof AdaptableTest && type.isAssignableFrom(String.class)) {
                    return (AdapterType) ((AdaptableTest) adaptable).toString();
View Full Code Here

     */
    private void register(final ServiceReference serviceReference) {
        final SlingPostOperation service = (SlingPostOperation) this.bundleContext.getService(serviceReference);
        final PostOperationProxy proxy = new PostOperationProxy(service);

        final BundleContext bundleContext = serviceReference.getBundle().getBundleContext();
        final Dictionary<String, Object> props = copyServiceProperties(serviceReference);
        final ServiceRegistration reg = bundleContext.registerService(
            PostOperation.SERVICE_NAME, proxy, props);

        log.debug("Registering {}", proxy);
        synchronized (this.proxies) {
            this.proxies.put(serviceReference, reg);
View Full Code Here

    }

    @Override
    public EmbeddedArtifact loadToolingSupportBundle() {

        BundleContext bundleContext = context.getBundleContext();

        String version = "1.0.0"; // TODO - remove version hardcoding
        String artifactId = "org.apache.sling.tooling.support.install";
        String extension = "jar";
View Full Code Here

    public Statement apply(final Statement base, final Description description) {
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                final BundleContext bundleContext = Activator.getBundleContext();

                if (bundleContext == null) {
                    throw new IllegalStateException("unable to obtain a bundle context");
                }

                final ServiceReference serviceReference = bundleContext.getServiceReference(serviceClass.getName());

                if (serviceReference == null) {
                    throw new IllegalStateException("unable to get a service reference");
                }

                final Object service = bundleContext.getService(serviceReference);

                if (service == null) {
                    throw new IllegalStateException("unable to get an instance of the service");
                }

                Service.this.service = serviceClass.cast(service);

                try {
                    base.evaluate();
                } finally {
                    Service.this.service = null;
                    bundleContext.ungetService(serviceReference);
                }
            }

        };
    }
View Full Code Here

        // configure now
        this.configure(configuration);

        // other predefined operations
        final ArrayList<ServiceRegistration> providedServices = new ArrayList<ServiceRegistration>();
        final BundleContext bundleContext = context.getBundleContext();
        providedServices.add(registerOperation(bundleContext,
            SlingPostConstants.OPERATION_MODIFY, modifyOperation));
        providedServices.add(registerOperation(bundleContext,
            SlingPostConstants.OPERATION_COPY, new CopyOperation()));
        providedServices.add(registerOperation(bundleContext,
View Full Code Here

        return b;
    }
   
    @Test
    public void testInactiveBundles() throws Exception {
        final BundleContext ctx = Mockito.mock(BundleContext.class);
        final Bundle [] bundles = {
                mockBundle(false, true),
                mockBundle(false, false),
                mockBundle(false, true),
                mockBundle(true, false)
        };
        Mockito.when(ctx.getBundles()).thenReturn(bundles);
       
        final FormattingResultLog resultLog = new FormattingResultLog();
        final OsgiScriptBindingsProvider.OsgiBinding b = new OsgiScriptBindingsProvider.OsgiBinding(ctx, resultLog);
        assertEquals(1, b.inactiveBundlesCount());
    }
View Full Code Here

    private final List<Event> events = Collections.synchronizedList(new ArrayList<Event>());

    @SuppressWarnings("unchecked")
    @Before
    public void setup() throws Exception {
        final BundleContext bc = Mockito.mock(BundleContext.class);
        Mockito.when(bc.registerService(Mockito.any(String[].class),
                Mockito.any(),
                Mockito.any(Dictionary.class))).thenReturn(null);

        final SlingSettingsService otherSettings = Mockito.mock(SlingSettingsService.class);
        Mockito.when(otherSettings.getSlingId()).thenReturn(OTHER_APP_ID);
View Full Code Here

    }

    private void initMocks(String path, String[] operations){
        serviceReference = mock(ServiceReference.class);
        Bundle bundle = mock(Bundle.class);
        BundleContext bundleContext = mock(BundleContext.class);
        resourceAccessGate = mock(ResourceAccessGate.class);

        when(serviceReference.getBundle()).thenReturn(bundle);
        when(bundle.getBundleContext()).thenReturn(bundleContext);
        when(bundleContext.getService(serviceReference)).thenReturn(resourceAccessGate);

        when(serviceReference.getProperty(ResourceAccessGate.PATH)).thenReturn(path);
        when(serviceReference.getProperty(ResourceAccessGate.OPERATIONS)).thenReturn(operations);

        ((ProviderResourceAccessSecurityImpl) resourceAccessSecurity).bindResourceAccessGate(serviceReference);
View Full Code Here

TOP

Related Classes of org.osgi.framework.BundleContext

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.