Package org.apache.felix.scr.impl

Examples of org.apache.felix.scr.impl.TargetedPID


                                                        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;
                                        }
                                    }
                                }
View Full Code Here


     *
     * @param event The configuration change event
     */
    public void configurationEvent(ConfigurationEvent event)
    {
        final TargetedPID pid = new TargetedPID( event.getPid());
        String rawFactoryPid = event.getFactoryPid();
        final TargetedPID factoryPid = rawFactoryPid == null? null: new TargetedPID( rawFactoryPid);

        // iterate over all components which must be configured with this pid
        // (since DS 1.2, components may specify a specific configuration PID (112.4.4 configuration-pid)
        Collection<ComponentHolder<?>> holders;

        if (factoryPid == null)
        {
            holders = this.m_registry.getComponentHoldersByPid(pid);
        }
        else
        {
            holders = this.m_registry.getComponentHoldersByPid(factoryPid);
        }

        Activator.log(LogService.LOG_DEBUG, null, "configurationEvent: Handling {0}  of Configuration PID={1} for component holders {2}",
                new Object[] {getEventType(event), pid, holders},
                null);

        for  ( ComponentHolder<?> componentHolder: holders )
        {
            if (!componentHolder.getComponentMetadata().isConfigurationIgnored())
            {
                switch (event.getType()) {
                case ConfigurationEvent.CM_DELETED:
                    if ( factoryPid != null || !configureComponentHolder( componentHolder ) )
                    {
                        componentHolder.configurationDeleted( pid, factoryPid );
                    }
                    break;

                case ConfigurationEvent.CM_UPDATED:
                {
                    final BundleComponentActivator activator = componentHolder.getActivator();
                    if (activator == null)
                    {
                        break;
                    }

                    final BundleContext bundleContext = activator.getBundleContext();
                    if (bundleContext == null)
                    {
                        break;
                    }

                    TargetedPID targetedPid = factoryPid == null? pid: factoryPid;
                    TargetedPID oldTargetedPID = componentHolder.getConfigurationTargetedPID(pid, factoryPid);
                    if ( factoryPid != null || targetedPid.equals(oldTargetedPID) || targetedPid.bindsStronger( oldTargetedPID ))
                    {
                        final ConfigurationInfo configInfo = getConfigurationInfo( pid, targetedPid, componentHolder, bundleContext );
                        if ( checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ) )
                        {
                            //If this is replacing a weaker targetedPID delete the old one.
                            if ( factoryPid == null && !targetedPid.equals(oldTargetedPID) && oldTargetedPID != null)
                            {
                                componentHolder.configurationDeleted( pid, factoryPid );
                            }
                            componentHolder.configurationUpdated( pid, factoryPid, configInfo.getProps(), configInfo.getChangeCount() );
                        }
                    }

                    break;
                }
                case ConfigurationEvent.CM_LOCATION_CHANGED:
                {
                    //TODO is this logic correct for factory pids????
                    final BundleComponentActivator activator = componentHolder.getActivator();
                    if (activator == null)
                    {
                        break;
                    }

                    final BundleContext bundleContext = activator.getBundleContext();
                    if (bundleContext == null)
                    {
                        break;
                    }

                    TargetedPID targetedPid = factoryPid == null? pid: factoryPid;
                    TargetedPID oldTargetedPID = componentHolder.getConfigurationTargetedPID(pid, factoryPid);
                    if ( targetedPid.equals(oldTargetedPID))
                    {
                        //this sets the location to this component's bundle if not already set.  OK here
                        //since it used to be set to this bundle, ok to reset it
                        final ConfigurationInfo configInfo = getConfigurationInfo( pid, targetedPid, componentHolder, bundleContext );
View Full Code Here

        assertEquals( "Expect no other component manager list", 1, getComponentManagers( holder ).size());

        // configure with the singleton configuration
        final Dictionary config = new Hashtable();
        config.put( "value", name );
        TargetedPID targetedPid = new TargetedPID(name);
    holder.configurationUpdated( targetedPid, null, config, 0 );

        // assert single component and no map
        final SingleComponentManager cmgrAfterConfig = getSingleManager( holder );
        assertNotNull( "Expect single component manager", cmgrAfterConfig );
View Full Code Here

        // configure with configuration
        final String pid1 = "test.factory.0001";
        final Dictionary config1 = new Hashtable();
        config1.put( "value", pid1 );
        TargetedPID targetedFactoryPid = new TargetedPID(name);
    TargetedPID targetedPid1 = new TargetedPID(pid1);
    holder.configurationUpdated( targetedPid1, targetedFactoryPid, config1, 0 );

        // assert single component and single-entry map
        final SingleComponentManager cmgrAfterConfig = getSingleManager( holder );
        final List<SingleComponentManager> cmgrsAfterConfig = getComponentManagers( holder );
        assertNotNull( "Expect single component manager", cmgrAfterConfig );
        assertNotNull( "Expect component manager list", cmgrsAfterConfig );
        assertEquals( "Expect one component manager in list", 1, cmgrsAfterConfig.size() );

        // add another configuration
        final String pid2 = "test.factory.0002";
        final Dictionary config2 = new Hashtable();
        config1.put( "value", pid2 );
        TargetedPID targetedPid2 = new TargetedPID(pid2);
    holder.configurationUpdated( targetedPid2, targetedFactoryPid, config2, 1 );

        final List<SingleComponentManager> cmgrsAfterConfig2 = getComponentManagers( holder );
        assertNotNull( "Expect component manager list", cmgrsAfterConfig2 );
        assertEquals( "Expect two component manager in list", 2, cmgrsAfterConfig2.size() );
View Full Code Here

        assertFalse( "Expect no configuration", cmgr.hasConfiguration() );

        // configure with the singleton configuration
        final Dictionary config = new Hashtable();
        config.put( "value", name );
        holder.configurationUpdated( name, config, 0, new TargetedPID(name) );

        // assert single component and no map
        final SingleComponentManager cmgrAfterConfig = getSingleManager( holder );
        assertNotNull( "Expect single component manager", cmgrAfterConfig );
        assertEquals( "Expect no other component manager list", 1, getComponentManagers( holder ).length);
View Full Code Here

        // configure with configuration
        final String pid1 = "test.factory.0001";
        final Dictionary config1 = new Hashtable();
        config1.put( "value", pid1 );
        holder.configurationUpdated( pid1, config1, 0, new TargetedPID(name) );

        // assert single component and single-entry map
        final SingleComponentManager cmgrAfterConfig = getSingleManager( holder );
        final SingleComponentManager[] cmgrsAfterConfig = getComponentManagers( holder );
        assertNotNull( "Expect single component manager", cmgrAfterConfig );
        assertNotNull( "Expect component manager list", cmgrsAfterConfig );
        assertEquals( "Expect one component manager in list", 1, cmgrsAfterConfig.length );

        // add another configuration
        final String pid2 = "test.factory.0002";
        final Dictionary config2 = new Hashtable();
        config1.put( "value", pid2 );
        holder.configurationUpdated( pid2, config2, 1, new TargetedPID(name) );

        // assert single component and single-entry map
        final SingleComponentManager cmgrAfterConfig2 = getSingleManager( holder );
        final SingleComponentManager[] cmgrsAfterConfig2 = getComponentManagers( holder );
        assertNotNull( "Expect single component manager", cmgrAfterConfig2 );
        assertNotNull( "Expect component manager list", cmgrsAfterConfig2 );
        assertEquals( "Expect two component manager in list", 2, cmgrsAfterConfig2.length );

        // remove second configuration
        holder.configurationDeleted( pid2 );

        // assert single component and single-entry map
        final SingleComponentManager cmgrAfterUnConfig2 = getSingleManager( holder );
        final SingleComponentManager[] cmgrsAfterUnConfig2 = getComponentManagers( holder );
        assertNotNull( "Expect single component manager", cmgrAfterUnConfig2 );
        assertNotNull( "Expect component manager list", cmgrsAfterUnConfig2 );
        assertEquals( "Expect one component manager in list", 1, cmgrsAfterUnConfig2.length );

        // add second config again and remove first config -> replace singleton component
        holder.configurationUpdated( pid2, config2, 2, new TargetedPID(name) );
        holder.configurationDeleted( pid1 );

        // assert single component and single-entry map
        final SingleComponentManager cmgrAfterConfigUnconfig = getSingleManager( holder );
        final SingleComponentManager[] cmgrsAfterConfigUnconfig = getComponentManagers( holder );
View Full Code Here

                                            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(config.getPid(), config.getProperties(), changeCount, new TargetedPID(config.getFactoryPid()));
                                    }
                                }
                                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(confPid, singleton.getProperties(), changeCount, new TargetedPID(singleton.getPid()));
                                        return true;
                                    }
                                }
                            }
                        }
View Full Code Here

     *
     * @param event The configuration change event
     */
    public void configurationEvent(ConfigurationEvent event)
    {
        final TargetedPID pid = new TargetedPID( event.getPid());
        String rawFactoryPid = event.getFactoryPid();
        final TargetedPID factoryPid = rawFactoryPid == null? null: new TargetedPID( rawFactoryPid);

        // iterate over all components which must be configured with this pid
        // (since DS 1.2, components may specify a specific configuration PID (112.4.4 configuration-pid)
        Collection<ComponentHolder> holders;

        if (factoryPid == null)
        {
            holders = this.m_registry.getComponentHoldersByPid(pid);
        }
        else
        {
            holders = this.m_registry.getComponentHoldersByPid(factoryPid);
        }

        Activator.log(LogService.LOG_DEBUG, null, "configurationEvent: Handling {0}  of Configuration PID={1} for component holders {2}",
                new Object[] {getEventType(event), pid, holders},
                null);

        for  ( ComponentHolder componentHolder: holders )
        {
            if (!componentHolder.getComponentMetadata().isConfigurationIgnored())
            {
                switch (event.getType()) {
                case ConfigurationEvent.CM_DELETED:
                    if ( factoryPid != null || !configureComponentHolder( componentHolder ) )
                    {
                        componentHolder.configurationDeleted( pid.getServicePid() );
                    }
                    break;

                case ConfigurationEvent.CM_UPDATED:
                {
                    final BundleComponentActivator activator = componentHolder.getActivator();
                    if (activator == null)
                    {
                        break;
                    }

                    final BundleContext bundleContext = activator.getBundleContext();
                    if (bundleContext == null)
                    {
                        break;
                    }

                    TargetedPID targetedPid = factoryPid == null? pid: factoryPid;
                    TargetedPID oldTargetedPID = componentHolder.getConfigurationTargetedPID(pid);
                    if ( targetedPid.equals(oldTargetedPID) || targetedPid.bindsStronger( oldTargetedPID ))
                    {
                        final ConfigurationInfo configInfo = getConfigurationInfo( pid, componentHolder, bundleContext );
                        if ( checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ) )
                        {
                            //If this is replacing a weaker targetedPID delete the old one.
                            if ( !targetedPid.equals(oldTargetedPID) && oldTargetedPID != null)
                            {
                                componentHolder.configurationDeleted( pid.getServicePid() );
                            }
                            componentHolder.configurationUpdated( pid.getServicePid(), configInfo.getProps(), configInfo.getChangeCount(), targetedPid );
                        }
                    }

                    break;
                }
                case ConfigurationEvent.CM_LOCATION_CHANGED:
                {
                    //TODO is this logic correct for factory pids????
                    final BundleComponentActivator activator = componentHolder.getActivator();
                    if (activator == null)
                    {
                        break;
                    }

                    final BundleContext bundleContext = activator.getBundleContext();
                    if (bundleContext == null)
                    {
                        break;
                    }

                    TargetedPID targetedPid = factoryPid == null? pid: factoryPid;
                    TargetedPID oldTargetedPID = componentHolder.getConfigurationTargetedPID(pid);
                    if ( targetedPid.equals(oldTargetedPID))
                    {
                        //this sets the location to this component's bundle if not already set.  OK here
                        //since it used to be set to this bundle, ok to reset it
                        final ConfigurationInfo configInfo = getConfigurationInfo( pid, componentHolder, bundleContext );
View Full Code Here

TOP

Related Classes of org.apache.felix.scr.impl.TargetedPID

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.