Package org.osgi.framework

Examples of org.osgi.framework.BundleContext


     * Test method for {@link org.apache.felix.cm.file.FilePersistenceManager#FilePersistenceManager(org.osgi.framework.BundleContext, java.lang.String)}.
     */
    public void testFilePersistenceManagerBundleContextString()
    {
        // variables used in these tests
        BundleContext bundleContext;
        FilePersistenceManager fpm;
        String relPath;
        String absPath;
        File dataArea;

View Full Code Here


        assertEquals(1, resources.length);
    }

    private RepositoryAdminImpl createRepositoryAdmin() throws Exception
    {
        BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
        Bundle systemBundle = EasyMock.createMock(Bundle.class);
        BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);

        Activator.setContext(bundleContext);
        EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
        EasyMock.expect(bundleContext.getBundle(0)).andReturn(systemBundle);
        EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable());
        EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
        EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
        EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
        EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
        EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
        bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
        bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
        EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
        final Capture c = new Capture();
        EasyMock.expect(bundleContext.createFilter((String) capture(c))).andAnswer(new IAnswer() {
            public Object answer() throws Throwable {
                return FilterImpl.newInstance((String) c.getValue());
            }
        }).anyTimes();
        EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });
View Full Code Here

        destroyExtension(bundle);
    }

    private void createExtension(final Bundle bundle) {
        try {
            BundleContext bundleContext = bundle.getBundleContext();
            if (bundleContext == null) {
                // The bundle has been stopped in the mean time
                return;
            }
            final Extension extension = doCreateExtension(bundle);
View Full Code Here

     */
    public static ServiceRegistration<?> register(Plugin plugin) {

        Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(DebugOptions.LISTENER_SYMBOLICNAME, plugin.getBundle().getSymbolicName());
        BundleContext ctx = plugin.getBundle().getBundleContext();
        return ctx.registerService(new String[] { DebugOptionsListener.class.getName(), Logger.class.getName() },
                new Tracer(plugin), props);
    }
View Full Code Here

     *        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

        }
        else
        {
            // hash the password, update config and wait for the
            // updated configuration to be supplied later
            final BundleContext bc = this.osgiManager.getBundleContext();
            final ServiceReference ref = bc.getServiceReference( ConfigurationAdmin.class.getName() );
            if ( ref != null )
            {
                final ConfigurationAdmin ca = ( ConfigurationAdmin ) bc.getService( ref );
                if ( ca != null )
                {
                    try
                    {
                        Configuration cfg = ca.getConfiguration( this.osgiManager.getConfigurationPid() );
                        Dictionary newConfig = cfg.getProperties();
                        if ( newConfig != null )
                        {
                            // assumption: config is not null and as a non-null password String property
                            final String pwd = ( String ) config.get( OsgiManager.PROP_PASSWORD );
                            final String hashedPassword = Password.hashPassword( pwd );
                            newConfig.put( OsgiManager.PROP_PASSWORD, hashedPassword );
                            cfg.update( newConfig );
                        }
                    }
                    catch ( Exception e )
                    {
                        // IOException from getting/updated config
                        // IllegalStateException from hashing password
                        throw new ConfigurationException( OsgiManager.PROP_PASSWORD, "Cannot update password property",
                            e );
                    }
                    finally
                    {
                        bc.ungetService( ref );
                    }
                }
            }
        }
    }
View Full Code Here

    /**
     * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
     */
    public final void printConfiguration(PrintWriter pw)
    {
        final BundleContext bc = getBundleContext();
        final ServiceReference paRef = bc.getServiceReference( PERMISSION_ADMIN_NAME );
        final ServiceReference cpaRef = bc.getServiceReference( CONDITIONAL_PERMISSION_ADMIN_NAME );
        final Object paSvc = paRef != null ? bc.getService(paRef) : null;
        final Object cpaSvc = cpaRef != null ? bc.getService(cpaRef) : null;

        try
        {
            pw.print("Status: Permission Admin ");
            if (null == paSvc)
                pw.print("not ");
            pw.print("available, Conditional Permission Admin ");
            if (null == cpaSvc)
                pw.print("not ");
            pw.println("available.");

            if (paSvc != null)
            {
                final PermissionAdmin pa = (PermissionAdmin) paSvc;
                pw.println();
                pw.println("Permission Admin");

                pw.println("  Default Permissions:");
                print(pa.getDefaultPermissions(), pw);

                final String locations[] = pa.getLocations();
                for (int i = 0; locations != null && i < locations.length; i++)
                {
                    pw.print("  Location: ");
                    pw.println(locations[i]);
                    print(pa.getPermissions(locations[i]), pw);
                }
            }

            if (cpaSvc != null)
            {
                final ConditionalPermissionAdmin cpa = (ConditionalPermissionAdmin) cpaSvc;
                pw.println();
                pw.println("Conditional Permission Admin");

                Method getAccessDecision = null;
                try
                {
                    getAccessDecision = ConditionalPermissionInfo.class.getMethod( "getAccessDecision",
                        ( Class[] ) null );
                }
                catch (Throwable t)
                {
                    // it is r4.0 framework, not r4.2
                }

                boolean hasPermissions = false;
                //final java.util.List list = cpa.newConditionalPermissionUpdate().getConditionalPermissionInfos();
                //for (int i = 0; list != null && i < list.size(); i++)
                for (Enumeration e = cpa.getConditionalPermissionInfos(); e.hasMoreElements();)
                {
                    hasPermissions = true;
                    //final ConditionalPermissionInfo info = (ConditionalPermissionInfo) list.get(i);
                    final ConditionalPermissionInfo info = (ConditionalPermissionInfo) e.nextElement();
                    pw.print("  "); //$NON-NLS-1$
                    pw.print(info.getName());

                    if (getAccessDecision != null)
                    {
                        try
                        {
                            final Object ad = getAccessDecision.invoke( info, ( Object[] ) null );
                            pw.print(" ("); //$NON-NLS-1$
                            pw.print(ad);
                            pw.print(")"); //$NON-NLS-1$
                        }
                        catch (Throwable t)
                        {
                            // ignore - will not print it
                        }
                    }

                    pw.println();
                    pw.println("  Conditions:");
                    print(info.getConditionInfos(), pw);
                    pw.println("  Permissions:");
                    print(info.getPermissionInfos(), pw);
                }

                if (!hasPermissions)
                    pw.println("  n/a");
            }
        }
        finally
        {
            if (paRef != null)
                bc.ungetService(paRef);
            if (cpaRef != null)
                bc.ungetService(cpaRef);
        }
    }
View Full Code Here

                return null;
            }

            try
            {
                BundleContext bundleContext = (BundleContext) bundleContextAttr;
                Filter filter = createFilter(bundleContext, null);
                this.eventDispatcherTracker = new ServiceTracker(bundleContext, filter, null)
                {
                    public void removedService(ServiceReference reference, Object service)
                    {
View Full Code Here

                            postfix = name.substring(name.length() - 1);
                            name = name.substring(0, name.length() - 1);
                        }
                        if (!(new File(name)).isAbsolute())
                        {
                            BundleContext context = (BundleContext) AccessController
                                .doPrivileged(new PrivilegedAction()
                                {
                                    public Object run()
                                    {
                                        return bundle.getBundleContext();
                                    }
                                });
                            if (context == null)
                            {
                                break;
                            }
                            name = m_action.getAbsolutePath(new File(context
                                .getDataFile(""), name));
                        }
                        if (postfix.length() > 0)
                        {
                            if ((name.length() > 0) && !name.endsWith("/"))
View Full Code Here

                        activatorClass.trim()).newInstance();

// TODO: EXTENSIONMANAGER - This is kind of hacky, can we improve it?
                felix.m_activatorList.add(activator);

                BundleContext context = felix._getBundleContext();

                bundle.setBundleContext(context);

                if ((felix.getState() == Bundle.ACTIVE) || (felix.getState() == Bundle.STARTING))
                {
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.