Package org.osgi.framework

Examples of org.osgi.framework.BundleContext


            lock.release();
        }
    }

    protected void setStartLevel(int level) throws Exception {
        BundleContext ctx = framework.getBundleContext();
        ServiceReference[] refs = ctx.getServiceReferences(StartLevel.class.getName(), null);
        StartLevel sl = (StartLevel) ctx.getService(refs[0]);
        sl.setStartLevel(level);
    }
View Full Code Here


            if (m_serviceRegistration != null) {
                m_serviceRegistration.unregister();
            }

            // Register the ManagedService
            BundleContext bundleContext = m_instanceManager.getContext();
            Dictionary<String, String> properties = new Hashtable<String, String>();
            try {
                m_objectName = new ObjectName(getObjectNameString());

                properties.put("jmxagent.objectName", m_objectName.toString());

                m_serviceRegistration = bundleContext.registerService(
                    javax.management.DynamicMBean.class.getName(), m_MBean,
                    properties);

                m_registered = true;
            } catch (Exception e) {
View Full Code Here

     * @param bundleLocations the locations where extension for the host bundle are located. Must not be {@code null}!
     * @throws BundleException if something went wrong while installing or starting the bundles.
     */
    private static void installAndStartBundles(String... bundleLocations) throws BundleException
    {
        BundleContext bundleContext = m_framework.getBundleContext();
        Activator hostActivator = new Activator();
        hostActivator.start(bundleContext);
        for (String location : bundleLocations)
        {
            Bundle addition = bundleContext.installBundle(location);
            addition.start();
        }
    }
View Full Code Here

    public void testInitBundleContextDeployIT() throws MalformedURLException, InterruptedException
    {
        //Setup mocks
        Deployment mockDeployment = mock(Deployment.class);
        Bundle mockBundle = mock(Bundle.class);
        BundleContext mockBundleContext = mock(BundleContext.class);

        //Setup behaviors
        when(mockDeployment.getBundle()).thenReturn(mockBundle);
        when(mockBundle.getBundleContext()).thenReturn(mockBundleContext);
        when(mockBundle.getSymbolicName()).thenReturn("test");
View Full Code Here

        m_getStorageAreaCommand = getStorageAreaCommand;
    }

    protected void doExecute(DeploymentSessionImpl session) throws Exception {
        AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
        BundleContext context = session.getBundleContext();

        BundleInfo[] infos = target.getBundleInfos();
        Map storageAreas = m_getStorageAreaCommand.getStorageAreas();
        for (int i = 0; i < infos.length; i++) {
            if (isCancelled()) {
                throw new DeploymentException(CODE_CANCELLED);
            }

            String symbolicName = infos[i].getSymbolicName();
            Bundle bundle = target.getBundle(symbolicName);
            if (bundle != null) {
                File root = (File) storageAreas.get(symbolicName);
                if (root != null) {
                    File snapshot = context.getDataFile("snapshots");
                    snapshot.mkdirs();
                    snapshot = new File(snapshot, infos[i].getSymbolicName());
                    try {
                        snapshot.createNewFile();
                        store(root, snapshot);
View Full Code Here

    private static RepositoryAdmin mockManager(List<URL> repositories) throws Exception {
     
      if (repositories == null || repositories.isEmpty())
        return null;
     
        BundleContext bundleContext = mock(BundleContext.class);
        Bundle systemBundle = mock(Bundle.class);

        // TODO: Change this one
        when(bundleContext.getProperty(RepositoryAdminImpl.REPOSITORY_URL_PROP)).thenReturn(repositories.get(0).toExternalForm());

        when(bundleContext.getProperty(anyString())).thenReturn(null);
        when(bundleContext.getBundle(0)).thenReturn(systemBundle);
        when(systemBundle.getHeaders()).thenReturn(new Hashtable<String,String>());
        when(systemBundle.getRegisteredServices()).thenReturn(null);
        when(new Long(systemBundle.getBundleId())).thenReturn(new Long(0));
        when(systemBundle.getBundleContext()).thenReturn(bundleContext);
        bundleContext.addBundleListener((BundleListener) anyObject());
        bundleContext.addServiceListener((ServiceListener) anyObject());
        when(bundleContext.getBundles()).thenReturn(new Bundle[]{systemBundle});

        RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));

        // force initialization && remove all initial repositories
        org.apache.felix.bundlerepository.Repository[] repos = repoAdmin.listRepositories();
View Full Code Here

        m_configuration.start( m_context ); //this will call restart, which calls super.start.
    }
   
    public void restart( boolean globalExtender )
    {
        BundleContext context;
        if ( globalExtender )
        {
            context = m_context.getBundle( 0 ).getBundleContext();
        }
        else
View Full Code Here

            // no components in the bundle, abandon
            return;
        }

        // there should be components, load them with a bundle context
        BundleContext context = bundle.getBundleContext();
        if ( context == null )
        {
            log( LogService.LOG_ERROR, m_bundle, "Cannot get BundleContext of bundle {0}/{1}",
                new Object[] {bundle.getSymbolicName(), bundle.getBundleId()}, null );
            return;
View Full Code Here

     *
     * @return the bundle or <code>null</code> if the plugin is not activated.
     */
    public final Bundle getBundle()
    {
        final BundleContext bundleContext = getBundleContext();
        return ( bundleContext != null ) ? bundleContext.getBundle() : null;
    }
View Full Code Here

    {

        // 112.7 configure unless configuration not required
        if (!holder.getComponentMetadata().isConfigurationIgnored())
        {
            final BundleContext bundleContext = holder.getActivator().getBundleContext();
            if ( bundleContext == null )
            {
                return false;// bundle was stopped concurrently with configuration deletion
            }
            final List<String> confPids = holder.getComponentMetadata().getConfigurationPid();

            final ServiceReference<?> caRef = bundleContext.getServiceReference(ComponentRegistry.CONFIGURATION_ADMIN);
            if (caRef != null)
            {
                final Object cao = bundleContext.getService(caRef);
                if (cao != null)
                {
                    try
                    {
                        if ( cao instanceof ConfigurationAdmin )
                        {
                            final ConfigurationAdmin ca = ( ConfigurationAdmin ) cao;
                            for (String confPid: confPids )
                            {
                                final Collection<Configuration> factory = findFactoryConfigurations( ca, confPid,
                                        bundleContext.getBundle() );
                                if ( !factory.isEmpty() )
                                {
                                    boolean created = false;
                                    for ( Configuration config: factory )
                                    {
                                        Activator.log( LogService.LOG_DEBUG, null,
                                                "Configuring holder {0} with factory configuration {1}", new Object[] {
                                                        holder, config }, null );
                                        config = getConfiguration( ca, config.getPid() );
                                        if ( checkBundleLocation( config, bundleContext.getBundle() ) )
                                        {
                                            long changeCount = changeCounter.getChangeCount( config, false, -1 );
                                            created |= holder.configurationUpdated( new TargetedPID( config.getPid() ),
                                                new TargetedPID( config.getFactoryPid() ),
                                                    config.getProperties(),
                                                    changeCount );
                                        }
                                    }
                                    return created;
                                }
                                else
                                {
                                    // check for configuration and configure the holder
                                    Configuration singleton = findSingletonConfiguration( ca, confPid,
                                            bundleContext.getBundle() );
                                    if ( singleton != null )
                                    {
                                        singleton = getConfiguration( ca, singleton.getPid() );
                                        Activator.log( LogService.LOG_DEBUG, null,
                                                "Configuring holder {0} with configuration {1}", new Object[] { holder,
                                                        singleton }, null );
                                        if ( singleton != null
                                                && checkBundleLocation( singleton, bundleContext.getBundle() ) )
                                        {
                                            long changeCount = changeCounter.getChangeCount( singleton, false, -1 );
                                            holder.configurationUpdated( new TargetedPID( singleton.getPid() ), null,
                                                    singleton.getProperties(), changeCount );
                                            return true;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            Activator.log( LogService.LOG_WARNING, null, "Cannot configure component {0}",
                                 new Object[] {holder.getComponentMetadata().getName()}, null );
                            Activator.log( LogService.LOG_WARNING, null,
                                "Component Bundle's Configuration Admin is not compatible with "
                                    + "ours. This happens if multiple Configuration Admin API versions "
                                    + "are deployed and different bundles wire to different versions", null );
                            return false;

                        }
                    }
                    finally
                    {
                        try
                        {
                            bundleContext.ungetService( caRef );
                        }
                        catch ( IllegalStateException e )
                        {
                            // ignore, bundle context was shut down during the above.
                        }
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.