{
// 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.
}