FELIX-4402 separate ComponentHolder interface into 2 sides, one called from configuration support etc and one called from the component managers. Remove some unused methods from AbstractComponentManager. Some factory component tests currently fail.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1602643 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java b/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
index a667462..dd4958a 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
@@ -33,6 +33,7 @@
import org.apache.felix.scr.Component;
import org.apache.felix.scr.ScrService;
+import org.apache.felix.scr.impl.config.ComponentContainer;
import org.apache.felix.scr.impl.config.ComponentHolder;
import org.apache.felix.scr.impl.config.ConfigurationSupport;
import org.apache.felix.scr.impl.config.ConfigurableComponentHolder;
@@ -323,7 +324,7 @@
{
// register the name if no registration for that name exists already
final ComponentRegistryKey key = new ComponentRegistryKey( bundle, name );
- ComponentHolder existingRegistration = null;
+ ComponentHolder<?> existingRegistration = null;
boolean present;
synchronized ( m_componentHoldersByName )
{
@@ -559,7 +560,7 @@
*/
public ComponentHolder createComponentHolder( BundleComponentActivator activator, ComponentMetadata metadata )
{
- ComponentHolder holder;
+ ComponentHolder holder = null;//TODO not null
if (metadata.isFactory())
{
@@ -568,11 +569,11 @@
// as soon as the component factory is satisfied
if ( !metadata.isObsoleteFactoryComponentFactory() )
{
- holder = new ComponentFactoryImpl(activator, metadata );
+//TODO holder = new ComponentFactoryImpl(this );
}
else
{
- holder = new ConfigurationComponentFactoryImpl(activator, metadata );
+//TODO holder = new ConfigurationComponentFactoryImpl(activator );
}
}
else
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/TargetedPID.java b/scr/src/main/java/org/apache/felix/scr/impl/TargetedPID.java
index abf1f9d..e8ccedd 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/TargetedPID.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/TargetedPID.java
@@ -21,7 +21,6 @@
import org.apache.felix.scr.impl.config.ComponentHolder;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
/**
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
index 5b86d23..3720446 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
@@ -22,10 +22,8 @@
import java.util.Dictionary;
import java.util.List;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.impl.BundleComponentActivator;
import org.apache.felix.scr.impl.TargetedPID;
-import org.apache.felix.scr.impl.manager.SingleComponentManager;
import org.apache.felix.scr.impl.metadata.ComponentMetadata;
@@ -44,18 +42,16 @@
/**
* Returns the {@link BundleComponentActivator} owning this component
- * holder.
+ * holder. (overlaps ComponentContaienr)
*/
BundleComponentActivator getActivator();
-
/**
* Returns the {@link ComponentMetadata} describing and declaring this
- * component.
+ * component. (overlaps ComponentContaienr)
*/
ComponentMetadata getComponentMetadata();
-
/**
* The configuration with the given PID has been deleted from the
* Configuration Admin service.
@@ -129,11 +125,4 @@
* @param reason
*/
void disposeComponents( int reason );
-
-
- /**
- * Informs the holder that the component has been disposed as a result of
- * calling the dispose method.
- */
- void disposed( SingleComponentManager<S> component );
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
index 36e4313..a4d1f32 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
@@ -26,11 +26,9 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.impl.Activator;
import org.apache.felix.scr.impl.BundleComponentActivator;
import org.apache.felix.scr.impl.TargetedPID;
@@ -61,7 +59,7 @@
* <code>service.factoryPid</code> equals the component name.</li>
* </ul>
*/
-public class ConfigurableComponentHolder<S> implements ComponentHolder<S>, SimpleLogger
+public class ConfigurableComponentHolder<S> implements ComponentHolder<S>, ComponentContainer<S>, SimpleLogger
{
/**
@@ -73,22 +71,22 @@
* The {@link ComponentMetadata} describing the held component(s)
*/
private final ComponentMetadata m_componentMetadata;
-
+
/** the targeted pids corresponding to the pids specified in the config metadata, except possibly for the single
* factory pid
*/
private final TargetedPID[] m_targetedPids;
-
+
private final Long[] m_changeCount;
-
+
private final Map<String, Long> m_factoryChangeCount = new HashMap<String, Long>();
-
+
/**
* the index in metadata.getConfigurationPid() of the base factory pid, if any. Each component created from a factory configuration
* might have a different targeted pid.
*/
private Integer m_factoryPidIndex;
-
+
/**
* the non-factory configurations shared between all instances.
*/
@@ -99,7 +97,7 @@
* other required configs may not yet be present so we can't create the component manager yet.
*/
private final Map<String, Dictionary<String, Object>> m_factoryConfigurations = new HashMap<String, Dictionary<String, Object>>();
-
+
/**
* Each factory config may be from a different TargetedPID (sharing the same base service pid, but with different level of detail)
*/
@@ -129,7 +127,7 @@
* <ul>
*/
private AbstractComponentManager<S> m_singleComponent;
-
+
/**
* Whether components have already been enabled by calling the
* {@link #enableComponents(boolean)} method. If this field is <code>true</code>
@@ -138,7 +136,7 @@
* enabled. Otherwise they are not enabled immediately.
*/
private volatile boolean m_enabled;
-
+
private final ComponentMethods m_componentMethods;
public ConfigurableComponentHolder( final BundleComponentActivator activator, final ComponentMetadata metadata )
@@ -146,7 +144,7 @@
this.m_activator = activator;
this.m_componentMetadata = metadata;
int pidCount = metadata.getConfigurationPid().size();
- this.m_targetedPids = new TargetedPID[pidCount];
+ this.m_targetedPids = new TargetedPID[pidCount];
this.m_configurations = new Dictionary[pidCount];
this.m_changeCount = new Long[pidCount];
this.m_components = new HashMap<String, AbstractComponentManager<S>>();
@@ -164,19 +162,19 @@
}
else if ( m_componentMetadata.getServiceScope() == Scope.bundle )
{
- manager = new ServiceFactoryComponentManager<S>( m_activator, this, m_componentMetadata, m_componentMethods );
+ manager = new ServiceFactoryComponentManager<S>( this, m_componentMethods );
}
else if ( m_componentMetadata.getServiceScope() == Scope.prototype )
{
- manager = null;// NYI
-// manager = new ServiceFactoryComponentManager<S>( m_activator, this, m_componentMetadata, m_componentMethods );
+ manager = null;// NYI
+ // manager = new ServiceFactoryComponentManager<S>( m_activator, this, m_componentMetadata, m_componentMethods );
}
else
{
//immediate or delayed
- manager = new SingleComponentManager<S>( m_activator, this, m_componentMetadata, m_componentMethods );
+ manager = new SingleComponentManager<S>( this, m_componentMethods );
}
return manager;
@@ -218,7 +216,7 @@
public void configurationDeleted( final TargetedPID pid, TargetedPID factoryPid )
{
log( LogService.LOG_DEBUG, "ImmediateComponentHolder configuration deleted for pid {0}",
- new Object[] {pid}, null);
+ new Object[] {pid}, null);
// component to deconfigure or dispose of
final Map<AbstractComponentManager<S>, Map<String, Object>> scms = new HashMap<AbstractComponentManager<S>, Map<String, Object>>();
@@ -226,88 +224,88 @@
synchronized ( m_components )
{
-// // FELIX-2231: nothing to do any more, all components have been disposed off
-// if (m_singleComponent == null)
-// {
-// return;
-// }
- if (factoryPid != null) {
- checkFactoryPidIndex(factoryPid);
- String servicePid = pid.getServicePid();
- m_factoryTargetedPids.remove(servicePid);
- m_factoryChangeCount.remove(servicePid);
- m_factoryConfigurations.remove(servicePid);
- AbstractComponentManager<S> scm = m_components.remove(servicePid);
- if ( m_factoryConfigurations.isEmpty() )
- {
- m_factoryPidIndex = null;
- }
- if ( !m_enabled || scm == null )
- {
- return;
- }
- reconfigure = m_componentMetadata.isConfigurationOptional() && m_components.isEmpty();
- if ( reconfigure )
- {
- m_singleComponent = scm;
- scms.put( scm, mergeProperties(null) );
- }
- else
- {
- scms.put( scm, null );
- }
- }
- else
- {
- //singleton pid
- int index = getSingletonPidIndex(pid);
- m_targetedPids[index] = null;
- m_changeCount[index] = null;
- m_configurations[index] = null;
- if ( !m_enabled )
- {
- return;
- }
- reconfigure = m_componentMetadata.isConfigurationOptional();
+ // // FELIX-2231: nothing to do any more, all components have been disposed off
+ // if (m_singleComponent == null)
+ // {
+ // return;
+ // }
+ if (factoryPid != null) {
+ checkFactoryPidIndex(factoryPid);
+ String servicePid = pid.getServicePid();
+ m_factoryTargetedPids.remove(servicePid);
+ m_factoryChangeCount.remove(servicePid);
+ m_factoryConfigurations.remove(servicePid);
+ AbstractComponentManager<S> scm = m_components.remove(servicePid);
+ if ( m_factoryConfigurations.isEmpty() )
+ {
+ m_factoryPidIndex = null;
+ }
+ if ( !m_enabled || scm == null )
+ {
+ return;
+ }
+ reconfigure = m_componentMetadata.isConfigurationOptional() && m_components.isEmpty();
+ if ( reconfigure )
+ {
+ m_singleComponent = scm;
+ scms.put( scm, mergeProperties(null) );
+ }
+ else
+ {
+ scms.put( scm, null );
+ }
+ }
+ else
+ {
+ //singleton pid
+ int index = getSingletonPidIndex(pid);
+ m_targetedPids[index] = null;
+ m_changeCount[index] = null;
+ m_configurations[index] = null;
+ if ( !m_enabled )
+ {
+ return;
+ }
+ reconfigure = m_componentMetadata.isConfigurationOptional();
- if ( m_factoryPidIndex == null)
- {
- if ( m_singleComponent != null ) {
- if (reconfigure) {
- scms.put(m_singleComponent, mergeProperties(null));
- } else {
- scms.put(m_singleComponent, null);
- m_singleComponent = null;
- }
- }
- }
- else
- {
- if (reconfigure) {
- for (Map.Entry<String, AbstractComponentManager<S>> entry : m_components.entrySet()) {
- scms.put(entry.getValue(), mergeProperties(entry.getKey()));
- }
- }
- else
- {
- for (Map.Entry<String, AbstractComponentManager<S>> entry : m_components.entrySet()) {
- scms.put(entry.getValue(), null );
- }
- m_components.clear();
- }
- }
+ if ( m_factoryPidIndex == null)
+ {
+ if ( m_singleComponent != null ) {
+ if (reconfigure) {
+ scms.put(m_singleComponent, mergeProperties(null));
+ } else {
+ scms.put(m_singleComponent, null);
+ m_singleComponent = null;
+ }
+ }
+ }
+ else
+ {
+ if (reconfigure) {
+ for (Map.Entry<String, AbstractComponentManager<S>> entry : m_components.entrySet()) {
+ scms.put(entry.getValue(), mergeProperties(entry.getKey()));
+ }
+ }
+ else
+ {
+ for (Map.Entry<String, AbstractComponentManager<S>> entry : m_components.entrySet()) {
+ scms.put(entry.getValue(), null );
+ }
+ m_components.clear();
+ }
+ }
- }
+ }
}
for ( Map.Entry<AbstractComponentManager<S>,Map<String, Object>> entry: scms.entrySet())
{
- if ( reconfigure ) {
- entry.getKey().reconfigure( entry.getValue(), true);
- } else {
- entry.getKey().dispose(ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_DELETED);
- }
- }
+ if ( reconfigure ) {
+ entry.getKey().reconfigure( entry.getValue(), true);
+ } else {
+ entry.getKey().dispose(ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_DELETED);
+ }
+ }
}
@@ -328,69 +326,69 @@
public boolean configurationUpdated( TargetedPID pid, TargetedPID factoryPid, final Dictionary<String, Object> props, long changeCount )
{
log( LogService.LOG_DEBUG, "ConfigurableComponentHolder configuration updated for pid {0} with properties {1}",
- new Object[] {pid, props}, null);
+ new Object[] {pid, props}, null);
// component to update or create
final Map<AbstractComponentManager<S>, Map<String, Object>> scms = new HashMap< AbstractComponentManager<S>, Map<String, Object>>();
boolean created = false;
-
+
//TODO better change count tracking
synchronized (m_components) {
- //Find or create the component manager, or return if not satisfied.
- if (factoryPid != null) {
- checkFactoryPidIndex(factoryPid);
- m_factoryConfigurations.put(pid.getServicePid(), props);
- m_factoryTargetedPids.put(pid.getServicePid(), factoryPid);
- m_factoryChangeCount.put(pid.getServicePid(), changeCount);
- if (m_enabled && isSatisfied()) {
- if (m_singleComponent != null) {
- AbstractComponentManager<S> scm = m_singleComponent;
- scms.put( scm, mergeProperties( pid.getServicePid() ) );
- m_singleComponent = null;
- m_components.put(pid.getServicePid(), scm);
- } else if (m_components.containsKey(pid.getServicePid())) {
- scms.put( m_components.get(pid.getServicePid()), mergeProperties( pid.getServicePid()) );
- } else {
- AbstractComponentManager<S> scm = createComponentManager();
- m_components.put(pid.getServicePid(), scm);
- scms.put( scm, mergeProperties( pid.getServicePid()) );
- created = true;
- }
- } else {
- return false;
- }
+ //Find or create the component manager, or return if not satisfied.
+ if (factoryPid != null) {
+ checkFactoryPidIndex(factoryPid);
+ m_factoryConfigurations.put(pid.getServicePid(), props);
+ m_factoryTargetedPids.put(pid.getServicePid(), factoryPid);
+ m_factoryChangeCount.put(pid.getServicePid(), changeCount);
+ if (m_enabled && isSatisfied()) {
+ if (m_singleComponent != null) {
+ AbstractComponentManager<S> scm = m_singleComponent;
+ scms.put( scm, mergeProperties( pid.getServicePid() ) );
+ m_singleComponent = null;
+ m_components.put(pid.getServicePid(), scm);
+ } else if (m_components.containsKey(pid.getServicePid())) {
+ scms.put( m_components.get(pid.getServicePid()), mergeProperties( pid.getServicePid()) );
+ } else {
+ AbstractComponentManager<S> scm = createComponentManager();
+ m_components.put(pid.getServicePid(), scm);
+ scms.put( scm, mergeProperties( pid.getServicePid()) );
+ created = true;
+ }
+ } else {
+ return false;
+ }
- } else {
- //singleton pid
- int index = getSingletonPidIndex(pid);
- m_targetedPids[index] = pid;
- m_changeCount[index] = changeCount;
- m_configurations[index] = props;
- if (m_enabled && isSatisfied()) {
- if (m_singleComponent != null) {
- scms.put( m_singleComponent, mergeProperties( pid.getServicePid() ) );
- }
- else if ( m_factoryPidIndex != null)
- {
- for (Map.Entry<String, AbstractComponentManager<S>> entry: m_components.entrySet())
- {
- scms.put(entry.getValue(), mergeProperties( entry.getKey()));
- }
- }
- else
- {
- m_singleComponent = createComponentManager();
- scms.put( m_singleComponent, mergeProperties( pid.getServicePid() ) );
- created = true;
- }
- } else {
- return false;
- }
+ } else {
+ //singleton pid
+ int index = getSingletonPidIndex(pid);
+ m_targetedPids[index] = pid;
+ m_changeCount[index] = changeCount;
+ m_configurations[index] = props;
+ if (m_enabled && isSatisfied()) {
+ if (m_singleComponent != null) {
+ scms.put( m_singleComponent, mergeProperties( pid.getServicePid() ) );
+ }
+ else if ( m_factoryPidIndex != null)
+ {
+ for (Map.Entry<String, AbstractComponentManager<S>> entry: m_components.entrySet())
+ {
+ scms.put(entry.getValue(), mergeProperties( entry.getKey()));
+ }
+ }
+ else
+ {
+ m_singleComponent = createComponentManager();
+ scms.put( m_singleComponent, mergeProperties( pid.getServicePid() ) );
+ created = true;
+ }
+ } else {
+ return false;
+ }
- }
-
- }
-
+ }
+
+ }
+
// we have the icm.
//properties is all the configs merged together (without any possible component factory info.
@@ -398,199 +396,199 @@
final boolean enable = created && m_enabled;// TODO WTF?? && getComponentMetadata().isEnabled();
for ( Map.Entry<AbstractComponentManager<S>,Map<String, Object>> entry: scms.entrySet())
{
- // configure the component
- entry.getKey().reconfigure(entry.getValue(), false);
- log(LogService.LOG_DEBUG,
- "ImmediateComponentHolder Finished configuring the dependency managers for component for pid {0} ",
- new Object[] { pid }, null);
- if (enable) {
- entry.getKey().enable(false);
- log(LogService.LOG_DEBUG,
- "ImmediateComponentHolder Finished enabling component for pid {0} ",
- new Object[] { pid }, null);
- } else {
- log(LogService.LOG_DEBUG,
- "ImmediateComponentHolder Will not enable component for pid {0}: holder enabled state: {1}, metadata enabled: {2} ",
- new Object[] { pid, m_enabled,
- m_componentMetadata.isEnabled() }, null);
- }
- }
- return created;
+ // configure the component
+ entry.getKey().reconfigure(entry.getValue(), false);
+ log(LogService.LOG_DEBUG,
+ "ImmediateComponentHolder Finished configuring the dependency managers for component for pid {0} ",
+ new Object[] { pid }, null);
+ if (enable) {
+ entry.getKey().enable(false);
+ log(LogService.LOG_DEBUG,
+ "ImmediateComponentHolder Finished enabling component for pid {0} ",
+ new Object[] { pid }, null);
+ } else {
+ log(LogService.LOG_DEBUG,
+ "ImmediateComponentHolder Will not enable component for pid {0}: holder enabled state: {1}, metadata enabled: {2} ",
+ new Object[] { pid, m_enabled,
+ m_componentMetadata.isEnabled() }, null);
+ }
+ }
+ return created;
}
- private Map<String, Object> mergeProperties(String servicePid) {
- Map<String, Object> properties;
- properties = new HashMap<String, Object>(m_componentMetadata.getProperties());
- for (int i = 0; i < m_configurations.length; i++)
- {
- if ( m_factoryPidIndex != null && i == m_factoryPidIndex)
- {
- copyTo(properties, m_factoryConfigurations.get(servicePid));
- }
- else if ( m_configurations[i] != null )
- {
- copyTo(properties, m_configurations[i]);
- }
- }
- return properties;
- }
+ private Map<String, Object> mergeProperties(String servicePid) {
+ Map<String, Object> properties;
+ properties = new HashMap<String, Object>(m_componentMetadata.getProperties());
+ for (int i = 0; i < m_configurations.length; i++)
+ {
+ if ( m_factoryPidIndex != null && i == m_factoryPidIndex)
+ {
+ copyTo(properties, m_factoryConfigurations.get(servicePid));
+ }
+ else if ( m_configurations[i] != null )
+ {
+ copyTo(properties, m_configurations[i]);
+ }
+ }
+ return properties;
+ }
- private int getSingletonPidIndex(TargetedPID pid) {
- int index = m_componentMetadata.getPidIndex(pid);
- if (index == -1) {
- log(LogService.LOG_ERROR,
- "Unrecognized pid {0}, expected one of {1}",
- new Object[] { pid,
- m_componentMetadata.getConfigurationPid() },
- null);
- throw new IllegalArgumentException("Unrecognized pid "
- + pid);
- }
- if (m_factoryPidIndex != null && index == m_factoryPidIndex) {
- log(LogService.LOG_ERROR,
- "singleton pid {0} supplied, but matches an existing factory pid at index: {1}",
- new Object[] { pid, m_factoryPidIndex }, null);
- throw new IllegalStateException(
- "Singleton pid supplied matching a previous factory pid "
- + pid);
- }
- return index;
- }
+ private int getSingletonPidIndex(TargetedPID pid) {
+ int index = m_componentMetadata.getPidIndex(pid);
+ if (index == -1) {
+ log(LogService.LOG_ERROR,
+ "Unrecognized pid {0}, expected one of {1}",
+ new Object[] { pid,
+ m_componentMetadata.getConfigurationPid() },
+ null);
+ throw new IllegalArgumentException("Unrecognized pid "
+ + pid);
+ }
+ if (m_factoryPidIndex != null && index == m_factoryPidIndex) {
+ log(LogService.LOG_ERROR,
+ "singleton pid {0} supplied, but matches an existing factory pid at index: {1}",
+ new Object[] { pid, m_factoryPidIndex }, null);
+ throw new IllegalStateException(
+ "Singleton pid supplied matching a previous factory pid "
+ + pid);
+ }
+ return index;
+ }
//TODO update error messages so they make sense for deleting config too.
- private void checkFactoryPidIndex(TargetedPID factoryPid) {
- int index = m_componentMetadata.getPidIndex(factoryPid);
- if (index == -1) {
- log(LogService.LOG_ERROR,
- "Unrecognized factory pid {0}, expected one of {1}",
- new Object[] { factoryPid,
- m_componentMetadata.getConfigurationPid() },
- null);
- throw new IllegalArgumentException(
- "Unrecognized factory pid " + factoryPid);
- }
- if (m_configurations[index] != null) {
- log(LogService.LOG_ERROR,
- "factory pid {0}, but this pid is already supplied as a singleton: {1} at index {2}",
- new Object[] { factoryPid, Arrays.asList(m_targetedPids), index }, null);
- throw new IllegalStateException(
- "Factory pid supplied after all non-factory configurations supplied "
- + factoryPid);
- }
- if (m_factoryPidIndex == null) {
- m_factoryPidIndex = index;
- } else if (index != m_factoryPidIndex) {
- log(LogService.LOG_ERROR,
- "factory pid {0} supplied for index {1}, but a factory pid previously supplied at index {2}",
- new Object[] { factoryPid, index, m_factoryPidIndex },
- null);
- throw new IllegalStateException(
- "Factory pid supplied at wrong index " + factoryPid);
- }
- }
+ private void checkFactoryPidIndex(TargetedPID factoryPid) {
+ int index = m_componentMetadata.getPidIndex(factoryPid);
+ if (index == -1) {
+ log(LogService.LOG_ERROR,
+ "Unrecognized factory pid {0}, expected one of {1}",
+ new Object[] { factoryPid,
+ m_componentMetadata.getConfigurationPid() },
+ null);
+ throw new IllegalArgumentException(
+ "Unrecognized factory pid " + factoryPid);
+ }
+ if (m_configurations[index] != null) {
+ log(LogService.LOG_ERROR,
+ "factory pid {0}, but this pid is already supplied as a singleton: {1} at index {2}",
+ new Object[] { factoryPid, Arrays.asList(m_targetedPids), index }, null);
+ throw new IllegalStateException(
+ "Factory pid supplied after all non-factory configurations supplied "
+ + factoryPid);
+ }
+ if (m_factoryPidIndex == null) {
+ m_factoryPidIndex = index;
+ } else if (index != m_factoryPidIndex) {
+ log(LogService.LOG_ERROR,
+ "factory pid {0} supplied for index {1}, but a factory pid previously supplied at index {2}",
+ new Object[] { factoryPid, index, m_factoryPidIndex },
+ null);
+ throw new IllegalStateException(
+ "Factory pid supplied at wrong index " + factoryPid);
+ }
+ }
protected static void copyTo( Map<String, Object> target, Dictionary<String, ?> source )
{
-
+
for ( Enumeration<String> keys = source.keys(); keys.hasMoreElements(); )
{
- String key = keys.nextElement();
- Object value = source.get(key);
- target.put(key, value);
+ String key = keys.nextElement();
+ Object value = source.get(key);
+ target.put(key, value);
}
}
-
+
/**
* Determine if the holder is satisfied with configurations
* @return true if configuration optional or all pids supplied with configurations
*/
private boolean isSatisfied() {
- if ( m_componentMetadata.isConfigurationOptional() || m_componentMetadata.isConfigurationIgnored() )
- {
- return true;
- }
- for ( int i = 0; i < m_componentMetadata.getConfigurationPid().size(); i++)
- {
- if ( m_configurations[i] != null)
- {
- continue;
- }
- if ( m_factoryPidIndex != null && m_factoryPidIndex == i)
- {
- continue;
- }
- return false;
- }
- return true;
- }
+ if ( m_componentMetadata.isConfigurationOptional() || m_componentMetadata.isConfigurationIgnored() )
+ {
+ return true;
+ }
+ for ( int i = 0; i < m_componentMetadata.getConfigurationPid().size(); i++)
+ {
+ if ( m_configurations[i] != null)
+ {
+ continue;
+ }
+ if ( m_factoryPidIndex != null && m_factoryPidIndex == i)
+ {
+ continue;
+ }
+ return false;
+ }
+ return true;
+ }
/**
* @param pid the Targeted PID we need the change count for
* @param targetedPid the targeted factory pid for a factory configuration or the pid for a singleton configuration
* @return pid for this service pid.
*/
- public long getChangeCount( TargetedPID pid, TargetedPID targetedPid)
+ public long getChangeCount( TargetedPID pid, TargetedPID targetedPid)
{
- int index = m_componentMetadata.getPidIndex(targetedPid);
- Long result;
- if ( index == -1 )
- {
- throw new IllegalArgumentException("pid not recognized as for this component: " + pid);
- }
- if ( m_factoryPidIndex != null && index == m_factoryPidIndex )
- {
- result = m_factoryChangeCount.get(pid.getServicePid());
- }
- else
- {
- result = m_changeCount[index];
- }
- return result == null? -1: result;
-
+ int index = m_componentMetadata.getPidIndex(targetedPid);
+ Long result;
+ if ( index == -1 )
+ {
+ throw new IllegalArgumentException("pid not recognized as for this component: " + pid);
+ }
+ if ( m_factoryPidIndex != null && index == m_factoryPidIndex )
+ {
+ result = m_factoryChangeCount.get(pid.getServicePid());
+ }
+ else
+ {
+ result = m_changeCount[index];
+ }
+ return result == null? -1: result;
+
}
public List<? extends ComponentManager<?>> getComponents()
- {
+ {
synchronized ( m_components )
{
return getComponentManagers( false );
}
+ }
+
+
+ public boolean isEnabled() {
+ return m_enabled;
}
-
- public boolean isEnabled() {
- return m_enabled;
- }
-
public void enableComponents( final boolean async )
{
- List<AbstractComponentManager<S>> cms = new ArrayList<AbstractComponentManager<S>>();
- synchronized ( m_components )
- {
- if ( isSatisfied() )
- {
- if ( m_factoryPidIndex == null)
- {
- m_singleComponent = createComponentManager();
- cms.add( m_singleComponent );
- m_singleComponent.reconfigure(mergeProperties( null ), false);
- }
- else
- {
- for (String pid: m_factoryConfigurations.keySet()) {
- SingleComponentManager<S> scm = createComponentManager();
- m_components.put(pid, scm);
- scm.reconfigure( mergeProperties( pid ), false);
- cms.add( scm );
- }
- }
- }
- m_enabled = true;
- }
- for ( AbstractComponentManager<S> cm : cms )
- {
- cm.enable( async );
- }
+ List<AbstractComponentManager<S>> cms = new ArrayList<AbstractComponentManager<S>>();
+ synchronized ( m_components )
+ {
+ if ( isSatisfied() )
+ {
+ if ( m_factoryPidIndex == null)
+ {
+ m_singleComponent = createComponentManager();
+ cms.add( m_singleComponent );
+ m_singleComponent.reconfigure(mergeProperties( null ), false);
+ }
+ else
+ {
+ for (String pid: m_factoryConfigurations.keySet()) {
+ SingleComponentManager<S> scm = createComponentManager();
+ m_components.put(pid, scm);
+ scm.reconfigure( mergeProperties( pid ), false);
+ cms.add( scm );
+ }
+ }
+ }
+ m_enabled = true;
+ }
+ for ( AbstractComponentManager<S> cm : cms )
+ {
+ cm.enable( async );
+ }
}
@@ -602,11 +600,11 @@
m_enabled = false;
cms = getComponentManagers( true );
-// if (m_singleComponent != null && m_factoryPidIndex == null &&
-// (m_componentMetadata.isConfigurationIgnored() || m_componentMetadata.isConfigurationOptional()))
-// {
-// m_singleComponent = null;
-// }
+ // if (m_singleComponent != null && m_factoryPidIndex == null &&
+ // (m_componentMetadata.isConfigurationIgnored() || m_componentMetadata.isConfigurationOptional()))
+ // {
+ // m_singleComponent = null;
+ // }
}
for ( AbstractComponentManager<S> cm : cms )
{
@@ -648,7 +646,7 @@
if ( component == m_singleComponent )
{
- m_singleComponent = null;
+ m_singleComponent = null;
}
}
}
@@ -666,7 +664,7 @@
* {@code ImmediateComponentHolder} and is equal to this object;
* {@code false} otherwise.
*/
- public boolean equals(Object object)
+ public boolean equals(Object object)
{
if (!(object instanceof ConfigurableComponentHolder))
{
@@ -675,30 +673,30 @@
ConfigurableComponentHolder<S> other = (ConfigurableComponentHolder<S>) object;
return m_activator == other.m_activator
- && getName().equals(other.getName());
+ && getName().equals(other.getName());
}
-
- /**
- * Returns a hash code value for the object.
- *
- * @return An integer which is a hash code value for this object.
- */
- @Override
- public int hashCode()
- {
- return getName().hashCode();
- }
-
- @Override
- public String toString()
- {
- return "[ImmediateComponentHolder:" + getName() + "]";
- }
-
- String getName()
- {
- return m_componentMetadata.getName();
- }
+
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return An integer which is a hash code value for this object.
+ */
+ @Override
+ public int hashCode()
+ {
+ return getName().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "[ImmediateComponentHolder:" + getName() + "]";
+ }
+
+ String getName()
+ {
+ return m_componentMetadata.getName();
+ }
//---------- internal
@@ -709,32 +707,32 @@
*
* @param clear If true, clear the map and the single component manager.
*/
- List<AbstractComponentManager<S>> getComponentManagers( final boolean clear )
- {
- List<AbstractComponentManager<S>> cm;
- if ( m_components.isEmpty() )
- {
- if ( m_singleComponent != null)
- {
- cm = Collections.singletonList(m_singleComponent);
- }
- else
- {
- cm = Collections.emptyList();
- }
- }
+ List<AbstractComponentManager<S>> getComponentManagers( final boolean clear )
+ {
+ List<AbstractComponentManager<S>> cm;
+ if ( m_components.isEmpty() )
+ {
+ if ( m_singleComponent != null)
+ {
+ cm = Collections.singletonList(m_singleComponent);
+ }
+ else
+ {
+ cm = Collections.emptyList();
+ }
+ }
- else
- {
- cm = new ArrayList<AbstractComponentManager<S>>(m_components.values());
- }
- if ( clear )
- {
- m_components.clear();
- m_singleComponent = null;
- }
- return cm;
- }
+ else
+ {
+ cm = new ArrayList<AbstractComponentManager<S>>(m_components.values());
+ }
+ if ( clear )
+ {
+ m_components.clear();
+ m_singleComponent = null;
+ }
+ return cm;
+ }
public boolean isLogEnabled( int level )
{
@@ -761,20 +759,20 @@
public TargetedPID getConfigurationTargetedPID(TargetedPID pid, TargetedPID factoryPid)
{
- if ( factoryPid == null )
- {
- int index = m_componentMetadata.getPidIndex(pid);
- if (index != -1)
- {
- return m_targetedPids[index];
- }
- return null;
- }
- //each factory configured component may have a different factory targeted pid.
- synchronized (m_components)
- {
- return m_factoryTargetedPids.get(pid.getServicePid());
- }
+ if ( factoryPid == null )
+ {
+ int index = m_componentMetadata.getPidIndex(pid);
+ if (index != -1)
+ {
+ return m_targetedPids[index];
+ }
+ return null;
+ }
+ //each factory configured component may have a different factory targeted pid.
+ synchronized (m_components)
+ {
+ return m_factoryTargetedPids.get(pid.getServicePid());
+ }
}
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
index 164cfb1..ca2d2fa 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
@@ -42,6 +42,7 @@
import org.apache.felix.scr.impl.Activator;
import org.apache.felix.scr.impl.BundleComponentActivator;
+import org.apache.felix.scr.impl.config.ComponentContainer;
import org.apache.felix.scr.impl.config.ComponentManager;
import org.apache.felix.scr.impl.config.ReferenceManager;
import org.apache.felix.scr.impl.config.ScrConfiguration;
@@ -77,14 +78,13 @@
"Configuration deleted",
"Component disabled",
"Bundle stopped"};
+
+ protected final ComponentContainer m_container;
private final boolean m_factoryInstance;
// the ID of this component
private long m_componentId;
- // The metadata
- private final ComponentMetadata m_componentMetadata;
-
private final ComponentMethods m_componentMethods;
// The dependency managers that manage every dependency
@@ -96,9 +96,6 @@
private final AtomicInteger m_trackingCount = new AtomicInteger( );
- // A reference to the BundleComponentActivator
- private BundleComponentActivator m_activator;
-
// The ServiceRegistration is now tracked in the RegistrationManager
private final ReentrantLock m_stateLock;
@@ -132,22 +129,22 @@
/**
* The constructor receives both the activator and the metadata
*
- * @param activator
- * @param metadata
+ * @param container
* @param componentMethods
*/
- protected AbstractComponentManager( BundleComponentActivator activator, ComponentMetadata metadata, ComponentMethods componentMethods )
+ protected AbstractComponentManager( ComponentContainer container, ComponentMethods componentMethods )
{
- this( activator, metadata, componentMethods, false );
+ this( container, componentMethods, false );
}
- protected AbstractComponentManager( BundleComponentActivator activator, ComponentMetadata metadata, ComponentMethods componentMethods, boolean factoryInstance )
+ protected AbstractComponentManager( ComponentContainer container, ComponentMethods componentMethods, boolean factoryInstance )
{
m_factoryInstance = factoryInstance;
- m_activator = activator;
- m_componentMetadata = metadata;
+ m_container = container;
this.m_componentMethods = componentMethods;
m_componentId = -1;
+
+ ComponentMetadata metadata = container.getComponentMetadata();
m_dependencyManagers = loadDependencyManagers( metadata );
@@ -434,7 +431,7 @@
if ( async )
{
final CountDownLatch latch = enableLatch;
- m_activator.schedule( new Runnable()
+ getActivator().schedule( new Runnable()
{
long count = taskCounter.incrementAndGet();
@@ -537,7 +534,7 @@
if ( async )
{
final CountDownLatch latch = enableLatch;
- m_activator.schedule( new Runnable()
+ getActivator().schedule( new Runnable()
{
long count = taskCounter.incrementAndGet();
@@ -598,9 +595,9 @@
{
return m_componentId;
}
-
- public String getName() {
- return m_componentMetadata.getName();
+
+ protected String getName() {
+ return getComponentMetadata().getName();
}
/**
@@ -637,81 +634,10 @@
}
- public String getClassName()
+ protected boolean isImmediate()
{
- return m_componentMetadata.getImplementationClassName();
- }
+ return getComponentMetadata().isImmediate();
- public String getFactory()
- {
- return m_componentMetadata.getFactoryIdentifier();
- }
-
- public boolean isImmediate()
- {
- return m_componentMetadata.isImmediate();
-
- }
-
- public boolean isDefaultEnabled()
- {
- return m_componentMetadata.isEnabled();
- }
-
-
- public String getActivate()
- {
- return m_componentMetadata.getActivate();
- }
-
-
- public boolean isActivateDeclared()
- {
- return m_componentMetadata.isActivateDeclared();
- }
-
-
- public String getDeactivate()
- {
- return m_componentMetadata.getDeactivate();
- }
-
-
- public boolean isDeactivateDeclared()
- {
- return m_componentMetadata.isDeactivateDeclared();
- }
-
-
- public String getModified()
- {
- return m_componentMetadata.getModified();
- }
-
-
- public String getConfigurationPolicy()
- {
- return m_componentMetadata.getConfigurationPolicy();
- }
-
- public List<String> getConfigurationPid()
- {
- return m_componentMetadata.getConfigurationPid();
- }
-
- public boolean isConfigurationPidDeclared()
- {
- return m_componentMetadata.isConfigurationPidDeclared();
- }
-
- public boolean isServiceFactory()
- {
- return m_componentMetadata.getServiceScope() == Scope.bundle;
- }
-
- public String getServiceScope()
- {
- return m_componentMetadata.getServiceScope().name();
}
public boolean isFactory()
@@ -719,15 +645,6 @@
return false;
}
- public String[] getServices()
- {
- if ( m_componentMetadata.getServiceMetadata() != null )
- {
- return m_componentMetadata.getServiceMetadata().getProvides();
- }
-
- return null;
- }
//-------------- atomic transition methods -------------------------------
@@ -1092,7 +1009,7 @@
throw new IllegalStateException("Could not load implementation object class "
+ getComponentMetadata().getImplementationClassName());
}
- m_componentMethods.initComponentMethods( m_componentMetadata, implementationObjectClass );
+ m_componentMethods.initComponentMethods( getComponentMetadata(), implementationObjectClass );
for ( DependencyManager dependencyManager : m_dependencyManagers )
{
@@ -1148,7 +1065,7 @@
//**********************************************************************************************************
public BundleComponentActivator getActivator()
{
- return m_activator;
+ return m_container.getActivator();
}
@@ -1168,9 +1085,9 @@
synchronized void clear()
{
// for some testing, the activator may be null
- if ( m_activator != null )
+ if ( m_container.getActivator() != null )
{
- m_activator.unregisterComponentId( this );
+ m_container.getActivator().unregisterComponentId( this );
}
}
@@ -1484,7 +1401,7 @@
*/
public ComponentMetadata getComponentMetadata()
{
- return m_componentMetadata;
+ return m_container.getComponentMetadata();
}
/**
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
index 324f313..5d9913e 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
@@ -31,7 +31,7 @@
import org.apache.felix.scr.component.ExtFactoryComponentInstance;
import org.apache.felix.scr.impl.BundleComponentActivator;
import org.apache.felix.scr.impl.TargetedPID;
-import org.apache.felix.scr.impl.config.ComponentHolder;
+import org.apache.felix.scr.impl.config.ComponentContainer;
import org.apache.felix.scr.impl.config.ComponentManager;
import org.apache.felix.scr.impl.helper.ComponentMethods;
import org.apache.felix.scr.impl.metadata.ComponentMetadata;
@@ -58,7 +58,7 @@
* not all dependencies are present and the created components also persist whether or
* not the dependencies are present to allow the component instance to exist.
*/
-public class ComponentFactoryImpl<S> extends AbstractComponentManager<S> implements ComponentFactory, ComponentHolder<S>
+public class ComponentFactoryImpl<S> extends AbstractComponentManager<S> implements ComponentFactory, ComponentContainer<S>
{
/**
@@ -94,9 +94,9 @@
protected TargetedPID m_targetedPID;
- public ComponentFactoryImpl( BundleComponentActivator activator, ComponentMetadata metadata )
+ public ComponentFactoryImpl( ComponentContainer container )
{
- super( activator, metadata, new ComponentMethods() );
+ super( container, new ComponentMethods() );
m_componentInstances = new IdentityHashMap<SingleComponentManager<S>, SingleComponentManager<S>>();
m_configuration = new Hashtable<String, Object>();
}
@@ -389,7 +389,7 @@
{
log( LogService.LOG_DEBUG,
"ImmediateComponentHolder out of order configuration updated for pid {0} with existing count {1}, new count {2}",
- new Object[] { getConfigurationPid(), m_changeCount, changeCount }, null );
+ new Object[] { getComponentMetadata().getConfigurationPid(), m_changeCount, changeCount }, null );
return false;
}
m_changeCount = changeCount;
@@ -535,7 +535,7 @@
*/
private SingleComponentManager<S> createComponentManager()
{
- return new SingleComponentManager<S>( getActivator(), this, getComponentMetadata(), getComponentMethods(), !getComponentMetadata().isPersistentFactoryComponent() );
+ return new SingleComponentManager<S>( this, getComponentMethods(), !getComponentMetadata().isPersistentFactoryComponent() );
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ConfigurationComponentFactoryImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ConfigurationComponentFactoryImpl.java
index 82b1778..c70ad58 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ConfigurationComponentFactoryImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ConfigurationComponentFactoryImpl.java
@@ -26,12 +26,10 @@
import java.util.Map;
import org.apache.felix.scr.Component;
-import org.apache.felix.scr.impl.BundleComponentActivator;
import org.apache.felix.scr.impl.TargetedPID;
-import org.apache.felix.scr.impl.config.ComponentHolder;
+import org.apache.felix.scr.impl.config.ComponentContainer;
import org.apache.felix.scr.impl.config.ComponentManager;
import org.apache.felix.scr.impl.helper.ComponentMethods;
-import org.apache.felix.scr.impl.metadata.ComponentMetadata;
import org.osgi.framework.Constants;
import org.osgi.service.log.LogService;
@@ -55,9 +53,9 @@
*/
private final Map<String, SingleComponentManager<S>> m_configuredServices = new HashMap<String, SingleComponentManager<S>>();
- public ConfigurationComponentFactoryImpl( BundleComponentActivator activator, ComponentMetadata metadata )
+ public ConfigurationComponentFactoryImpl( ComponentContainer container )
{
- super( activator, metadata );
+ super( container );
}
@@ -247,15 +245,14 @@
*/
private SingleComponentManager<S> createConfigurationComponentManager()
{
- return new ComponentFactoryConfiguredInstance<S>( getActivator(), this, getComponentMetadata(), getComponentMethods() );
+ return new ComponentFactoryConfiguredInstance<S>( this, getComponentMethods() );
}
static class ComponentFactoryConfiguredInstance<S> extends SingleComponentManager<S> {
- public ComponentFactoryConfiguredInstance( BundleComponentActivator activator, ComponentHolder componentHolder,
- ComponentMetadata metadata, ComponentMethods componentMethods )
+ public ComponentFactoryConfiguredInstance( ComponentContainer container, ComponentMethods componentMethods )
{
- super( activator, componentHolder, metadata, componentMethods, true );
+ super( container, componentMethods, true );
}
public boolean isImmediate()
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
index 9f6b328..bd0cc9c 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
@@ -24,13 +24,11 @@
import java.util.IdentityHashMap;
import java.util.Iterator;
-import org.apache.felix.scr.impl.BundleComponentActivator;
-import org.apache.felix.scr.impl.config.ComponentHolder;
+import org.apache.felix.scr.impl.config.ComponentContainer;
import org.apache.felix.scr.impl.helper.ActivateMethod;
import org.apache.felix.scr.impl.helper.ComponentMethods;
import org.apache.felix.scr.impl.helper.MethodResult;
import org.apache.felix.scr.impl.helper.ModifiedMethod;
-import org.apache.felix.scr.impl.metadata.ComponentMetadata;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentConstants;
@@ -51,15 +49,12 @@
private IdentityHashMap<S, ComponentContextImpl> serviceContexts = new IdentityHashMap<S, ComponentContextImpl>();
/**
- * @param activator BundleComponentActivator for this DS implementation
- * @param componentHolder ComponentHolder for configuration management
- * @param metadata ComponentMetadata for this component
+ * @param container ComponentHolder for configuration management
* @param componentMethods
*/
- public ServiceFactoryComponentManager( BundleComponentActivator activator, ComponentHolder componentHolder,
- ComponentMetadata metadata, ComponentMethods componentMethods )
+ public ServiceFactoryComponentManager( ComponentContainer container, ComponentMethods componentMethods )
{
- super( activator, componentHolder, metadata, componentMethods );
+ super( container, componentMethods );
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
index 4295a00..61c6422 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
@@ -31,14 +31,13 @@
import org.apache.felix.scr.impl.BundleComponentActivator;
import org.apache.felix.scr.impl.TargetedPID;
-import org.apache.felix.scr.impl.config.ComponentHolder;
+import org.apache.felix.scr.impl.config.ComponentContainer;
import org.apache.felix.scr.impl.config.ComponentManager;
import org.apache.felix.scr.impl.config.ReferenceManager;
import org.apache.felix.scr.impl.helper.ActivateMethod.ActivatorParameter;
import org.apache.felix.scr.impl.helper.ComponentMethods;
import org.apache.felix.scr.impl.helper.MethodResult;
import org.apache.felix.scr.impl.helper.ModifiedMethod;
-import org.apache.felix.scr.impl.metadata.ComponentMetadata;
import org.apache.felix.scr.impl.metadata.ReferenceMetadata;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
@@ -62,9 +61,6 @@
// The context that will be passed to the implementationObject
private volatile ComponentContextImpl<S> m_componentContext;
- // the component holder responsible for managing this component
- private final ComponentHolder m_componentHolder;
-
// Merged properties from xml descriptor and all configurations
private Map<String, Object> m_configurationProperties;
@@ -82,31 +78,22 @@
/**
* The constructor receives both the activator and the metadata
- *
- * @param activator
- * @param metadata
- * @param componentMethods
+ * @param componentMethods
*/
- public SingleComponentManager( BundleComponentActivator activator, ComponentHolder componentHolder,
- ComponentMetadata metadata, ComponentMethods componentMethods )
+ public SingleComponentManager( ComponentContainer container, ComponentMethods componentMethods )
{
- this(activator, componentHolder, metadata, componentMethods, false);
+ this(container, componentMethods, false);
}
- public SingleComponentManager( BundleComponentActivator activator, ComponentHolder componentHolder,
- ComponentMetadata metadata, ComponentMethods componentMethods, boolean factoryInstance )
+ public SingleComponentManager( ComponentContainer container, ComponentMethods componentMethods,
+ boolean factoryInstance )
{
- super( activator, metadata, componentMethods, factoryInstance );
-
- m_componentHolder = componentHolder;
+ super( container, componentMethods, factoryInstance );
}
void clear()
{
- if ( m_componentHolder != null )
- {
- m_componentHolder.disposed( this );
- }
+ m_container.disposed( this );
super.clear();
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
index 62c2b86..3c298ab 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
@@ -7,6 +7,7 @@
import java.util.List;
import org.apache.felix.scr.impl.ComponentRegistry;
+import org.apache.felix.scr.impl.config.ComponentContainer;
import org.apache.felix.scr.impl.config.ComponentHolder;
import org.apache.felix.scr.impl.config.ComponentManager;
import org.apache.felix.scr.impl.config.ReferenceManager;
@@ -58,7 +59,7 @@
}
public ComponentDescriptionDTO getComponentDescriptionDTO(Bundle bundle, String name) {
- ComponentHolder<?> holder = componentRegistry.getComponentHolder(bundle, name);
+ ComponentHolder<?> holder = componentRegistry.getComponentHolder(bundle, name);
if ( holder != null )
{
return holderToDescription(holder);
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java b/scr/src/test/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java
index 421c27c..263e4c8 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java
@@ -28,7 +28,6 @@
import junit.framework.TestCase;
-import org.apache.felix.scr.impl.BundleComponentActivator;
import org.apache.felix.scr.impl.TargetedPID;
import org.apache.felix.scr.impl.helper.ComponentMethods;
import org.apache.felix.scr.impl.manager.SingleComponentManager;
@@ -239,7 +238,7 @@
protected SingleComponentManager createComponentManager()
{
- return new MockImmediateComponentManager( getActivator(), this, getComponentMetadata() );
+ return new MockImmediateComponentManager( this );
}
}
@@ -249,9 +248,9 @@
private Map<String, Object> m_configuration;
- public MockImmediateComponentManager( BundleComponentActivator activator, ComponentHolder componentHolder, ComponentMetadata metadata )
+ public MockImmediateComponentManager( ComponentContainer container )
{
- super( activator, componentHolder, metadata, new ComponentMethods() );
+ super( container, new ComponentMethods() );
}
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java b/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
index 6fe5703..f8e6ca8 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
@@ -25,6 +25,8 @@
import junit.framework.TestCase;
+import org.apache.felix.scr.impl.BundleComponentActivator;
+import org.apache.felix.scr.impl.config.ComponentContainer;
import org.apache.felix.scr.impl.manager.SingleComponentManager;
import org.apache.felix.scr.impl.metadata.ComponentMetadata;
import org.apache.felix.scr.impl.metadata.XmlHandler;
@@ -264,8 +266,8 @@
*/
private void checkMethod( BaseObject obj, String methodName, String methodDesc )
{
- ComponentMetadata metadata = newMetadata();
- SingleComponentManager icm = new SingleComponentManager( null, null, metadata, new ComponentMethods() );
+ ComponentContainer container = newContainer();
+ SingleComponentManager icm = new SingleComponentManager( container, new ComponentMethods() );
ActivateMethod am = new ActivateMethod( methodName, methodName != null, obj.getClass(), true, false );
am.invoke( obj, new ActivateMethod.ActivatorParameter( m_ctx, -1 ), null, icm );
Method m = get(am, "m_method");
@@ -275,6 +277,30 @@
}
+ private ComponentContainer newContainer()
+ {
+ final ComponentMetadata metadata = newMetadata();
+ ComponentContainer container = new ComponentContainer() {
+
+ public BundleComponentActivator getActivator()
+ {
+ return null;
+ }
+
+ public ComponentMetadata getComponentMetadata()
+ {
+ return metadata;
+ }
+
+ public void disposed(SingleComponentManager component)
+ {
+ }
+
+ };
+ return container;
+ }
+
+
private ComponentMetadata newMetadata() {
ComponentMetadata metadata = new ComponentMetadata( XmlHandler.DS_VERSION_1_1 );
metadata.setName("foo");
@@ -295,8 +321,8 @@
*/
private void ensureMethodNotFoundMethod( BaseObject obj, String methodName )
{
- ComponentMetadata metadata = newMetadata();
- SingleComponentManager icm = new SingleComponentManager( null, null, metadata, new ComponentMethods() );
+ ComponentContainer container = newContainer();
+ SingleComponentManager icm = new SingleComponentManager( container, new ComponentMethods() );
ActivateMethod am = new ActivateMethod( methodName, methodName != null, obj.getClass(), true, false );
am.invoke( obj, new ActivateMethod.ActivatorParameter( m_ctx, -1 ), null, icm );
assertNull( get( am, "m_method" ) );
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java b/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
index 9f23dbe..e0c45fd 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
@@ -21,6 +21,8 @@
import junit.framework.TestCase;
+import org.apache.felix.scr.impl.BundleComponentActivator;
+import org.apache.felix.scr.impl.config.ComponentContainer;
import org.apache.felix.scr.impl.manager.SingleComponentManager;
import org.apache.felix.scr.impl.manager.RefPair;
import org.apache.felix.scr.impl.manager.components.FakeService;
@@ -428,8 +430,8 @@
private void testMethod( final String methodName, final T1 component, final boolean isDS11,
final String expectCallPerformed )
{
- ComponentMetadata metadata = newMetadata();
- SingleComponentManager icm = new SingleComponentManager( null, null, metadata, new ComponentMethods() );
+ ComponentContainer container = newContainer();
+ SingleComponentManager icm = new SingleComponentManager( container, new ComponentMethods() );
BindMethod bm = new BindMethod( methodName, component.getClass(),
FakeService.class.getName(), isDS11, false );
RefPair refPair = new RefPair( m_serviceReference );
@@ -438,6 +440,29 @@
assertEquals( expectCallPerformed, component.callPerformed );
}
+ private ComponentContainer newContainer()
+ {
+ final ComponentMetadata metadata = newMetadata();
+ ComponentContainer container = new ComponentContainer() {
+
+ public BundleComponentActivator getActivator()
+ {
+ return null;
+ }
+
+ public ComponentMetadata getComponentMetadata()
+ {
+ return metadata;
+ }
+
+ public void disposed(SingleComponentManager component)
+ {
+ }
+
+ };
+ return container;
+ }
+
private ComponentMetadata newMetadata() {
ComponentMetadata metadata = new ComponentMetadata( XmlHandler.DS_VERSION_1_1 );
metadata.setName("foo");