Search in sources :

Example 21 with ComponentInstance

use of org.osgi.service.component.ComponentInstance in project felix by apache.

the class ComponentFactoryImpl method newInstance.

/* (non-Javadoc)
    * @see org.osgi.service.component.ComponentFactory#newInstance(java.util.Dictionary)
    */
public ComponentInstance newInstance(Dictionary<String, ?> dictionary) {
    final SingleComponentManager<S> cm = createComponentManager();
    log(LogService.LOG_DEBUG, "Creating new instance from component factory {0} with configuration {1}", new Object[] { getComponentMetadata().getName(), dictionary }, null);
    cm.setFactoryProperties(dictionary);
    // configure the properties
    cm.reconfigure(m_configuration, false, null);
    // enable
    cm.enableInternal();
    ComponentInstance instance;
    if (getComponentMetadata().isPersistentFactoryComponent()) {
        instance = new ModifyComponentInstance<S>(cm);
    } else {
        instance = cm.getComponentInstance();
        if (instance == null || instance.getInstance() == null) {
            // activation failed, clean up component manager
            cm.dispose(ComponentConstants.DEACTIVATION_REASON_DISPOSED);
            throw new ComponentException("Failed activating component");
        }
    }
    synchronized (m_componentInstances) {
        m_componentInstances.put(cm, cm);
    }
    return instance;
}
Also used : ComponentInstance(org.osgi.service.component.ComponentInstance) ExtFactoryComponentInstance(org.apache.felix.scr.component.ExtFactoryComponentInstance) ComponentException(org.osgi.service.component.ComponentException)

Aggregations

ComponentInstance (org.osgi.service.component.ComponentInstance)21 Test (org.junit.Test)13 Hashtable (java.util.Hashtable)11 ComponentFactory (org.osgi.service.component.ComponentFactory)10 SimpleServiceImpl (org.apache.felix.scr.integration.components.SimpleServiceImpl)7 SimpleComponent (org.apache.felix.scr.integration.components.SimpleComponent)3 SimpleService (org.apache.felix.scr.integration.components.SimpleService)3 ServiceReference (org.osgi.framework.ServiceReference)3 ComponentException (org.osgi.service.component.ComponentException)2 ExtFactoryComponentInstance (org.apache.felix.scr.component.ExtFactoryComponentInstance)1