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 );
Activator.log(LogService.LOG_DEBUG, null, "LocationChanged event, same targetedPID {0}, location now {1}",
new Object[] {targetedPid, configInfo.getBundleLocation()},
null);
if (configInfo.getProps() == null)
{
throw new IllegalStateException("Existing Configuration with pid " + pid +
" has had its properties set to null and location changed. We expected a delete event first.");
}
//this config was used on this component. Does it still match?
if (!checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ))
{
//no, delete it
componentHolder.configurationDeleted( pid, factoryPid );
//maybe there's another match
configureComponentHolder(componentHolder);
}
//else still matches
break;
}
boolean better = targetedPid.bindsStronger( oldTargetedPID );
if ( better )
{
//this sets the location to this component's bundle if not already set. OK here
//because if it is set to this bundle we will use it.
final ConfigurationInfo configInfo = getConfigurationInfo( pid, targetedPid, componentHolder, bundleContext );
Activator.log(LogService.LOG_DEBUG, null, "LocationChanged event, better targetedPID {0} compared to {1}, location now {2}",
new Object[] {targetedPid, oldTargetedPID, configInfo.getBundleLocation()},
null);
if (configInfo.getProps() == null)
{
//location has been changed before any properties are set. We don't care. Wait for an updated event with the properties
break;
}
//this component was not configured with this config. Should it be now?
if ( checkBundleLocation( configInfo.getBundleLocation(), bundleContext.getBundle() ) )
{
if ( oldTargetedPID != null )
{
//this is a better match, delete old before setting new
componentHolder.configurationDeleted( pid, factoryPid );