felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1692966 [1/3] - in /felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds: src/org/apache/felix/scr/impl/ src/org/apache/felix/scr/impl/config/ src/org/apache/felix/scr/impl/helper/ src/org/apache/felix/scr/impl/m...
Date Mon, 27 Jul 2015 22:01:59 GMT
Author: pderop
Date: Mon Jul 27 22:01:59 2015
New Revision: 1692966

URL: http://svn.apache.org/r1692966
Log:
Aligned code to latest version of Apache SCR from felix-trunk.

Added:
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/ExtendedServiceEvent.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/ExtendedServiceListener.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/ExtendedServiceListenerContext.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/SingleComponentManagerTest.java
Modified:
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/BundleComponentActivator.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurationSupport.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Annotations.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethod.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethods.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Coercions.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/ComponentServiceObjectsHelper.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/FieldHandler.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/FieldMethods.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/MethodResult.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/UnbindMethod.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/UpdatedMethod.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/DependencyManager.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/RefPair.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/ServiceTracker.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/ServiceTrackerCustomizer.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/SingleComponentManager.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/AnnotationTest.java
    felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/BindMethodTest.java

Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/BundleComponentActivator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/BundleComponentActivator.java?rev=1692966&r1=1692965&r2=1692966&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/BundleComponentActivator.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/BundleComponentActivator.java Mon Jul 27 22:01:59 2015
@@ -18,7 +18,6 @@
  */
 package org.apache.felix.scr.impl;
 
-
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
@@ -28,8 +27,11 @@ import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -39,23 +41,29 @@ import org.apache.felix.scr.impl.config.
 import org.apache.felix.scr.impl.helper.Logger;
 import org.apache.felix.scr.impl.manager.AbstractComponentManager;
 import org.apache.felix.scr.impl.manager.DependencyManager;
+import org.apache.felix.scr.impl.manager.ExtendedServiceEvent;
+import org.apache.felix.scr.impl.manager.ExtendedServiceListener;
+import org.apache.felix.scr.impl.manager.ExtendedServiceListenerContext;
 import org.apache.felix.scr.impl.metadata.ComponentMetadata;
 import org.apache.felix.scr.impl.metadata.XmlHandler;
 import org.apache.felix.scr.impl.parser.KXml2SAXParser;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentException;
 import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.ServiceTracker;
 
-
 /**
  * The BundleComponentActivator is helper class to load and unload Components of
  * a single bundle. It will read information from the metadata.xml file
  * descriptors and create the corresponding managers.
  */
-public class BundleComponentActivator implements Logger
+public class BundleComponentActivator implements Logger, ExtendedServiceListenerContext<ExtendedServiceEvent>
 {
     // global component registration
     private final ComponentRegistry m_componentRegistry;
@@ -82,10 +90,149 @@ public class BundleComponentActivator im
     // the configuration
     private final ScrConfiguration m_configuration;
 
+    private final Map<String, ListenerInfo> listenerMap = new HashMap<String, ListenerInfo>();
+
+    private static class ListenerInfo implements ServiceListener
+    {
+        private Map<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>> filterMap = new HashMap<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>>();
+
+        public void serviceChanged(ServiceEvent event)
+        {
+            ServiceReference<?> ref = event.getServiceReference();
+            ExtendedServiceEvent extEvent = null;
+            ExtendedServiceEvent endMatchEvent = null;
+            Map<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>> filterMap;
+            synchronized (this)
+            {
+                filterMap = this.filterMap;
+            }
+            for (Map.Entry<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>> entry : filterMap.entrySet())
+            {
+                Filter filter = entry.getKey();
+                if (filter == null || filter.match(ref))
+                {
+                    if (extEvent == null)
+                    {
+                        extEvent = new ExtendedServiceEvent(event);
+                    }
+                    for (ExtendedServiceListener<ExtendedServiceEvent> forwardTo : entry.getValue())
+                    {
+                        forwardTo.serviceChanged(extEvent);
+                    }
+                }
+                else if (event.getType() == ServiceEvent.MODIFIED)
+                {
+                    if (endMatchEvent == null)
+                    {
+                        endMatchEvent = new ExtendedServiceEvent(
+                            ServiceEvent.MODIFIED_ENDMATCH, ref);
+                    }
+                    for (ExtendedServiceListener<ExtendedServiceEvent> forwardTo : entry.getValue())
+                    {
+                        forwardTo.serviceChanged(endMatchEvent);
+                    }
+                }
+            }
+            if (extEvent != null)
+            {
+                extEvent.activateManagers();
+            }
+            if (endMatchEvent != null)
+            {
+                endMatchEvent.activateManagers();
+            }
+        }
+
+        public synchronized void add(Filter filter,
+            ExtendedServiceListener<ExtendedServiceEvent> listener)
+        {
+            filterMap = new HashMap<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>>(
+                filterMap);
+            List<ExtendedServiceListener<ExtendedServiceEvent>> listeners = filterMap.get(filter);
+            if (listeners == null)
+            {
+                listeners = Collections.<ExtendedServiceListener<ExtendedServiceEvent>> singletonList(listener);
+            }
+            else
+            {
+                listeners = new ArrayList<ExtendedServiceListener<ExtendedServiceEvent>>(
+                    listeners);
+                listeners.add(listener);
+            }
+            filterMap.put(filter, listeners);
+        }
+
+        public synchronized boolean remove(Filter filter,
+            ExtendedServiceListener<ExtendedServiceEvent> listener)
+        {
+            List<ExtendedServiceListener<ExtendedServiceEvent>> listeners = filterMap.get(filter);
+            if (listeners != null)
+            {
+                filterMap = new HashMap<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>>(
+                    filterMap);
+                listeners = new ArrayList<ExtendedServiceListener<ExtendedServiceEvent>>(
+                    listeners);
+                listeners.remove(listener);
+                if (listeners.isEmpty())
+                {
+                    filterMap.remove(filter);
+                }
+                else
+                {
+                    filterMap.put(filter, listeners);
+                }
+            }
+            return filterMap.isEmpty();
+        }
+    }
+
+    public void addServiceListener(String classNameFilter, Filter eventFilter,
+        ExtendedServiceListener<ExtendedServiceEvent> listener)
+    {
+        ListenerInfo listenerInfo;
+        synchronized (listenerMap)
+        {
+            log(LogService.LOG_DEBUG, "classNameFilter: " + classNameFilter
+                + " event filter: " + eventFilter, null, null, null);
+            listenerInfo = listenerMap.get(classNameFilter);
+            if (listenerInfo == null)
+            {
+                listenerInfo = new ListenerInfo();
+                listenerMap.put(classNameFilter, listenerInfo);
+                try
+                {
+                    m_context.addServiceListener(listenerInfo, classNameFilter);
+                }
+                catch (InvalidSyntaxException e)
+                {
+                    throw (IllegalArgumentException) new IllegalArgumentException(
+                        "invalid class name filter").initCause(e);
+                }
+            }
+        }
+        listenerInfo.add(eventFilter, listener);
+    }
+
+    public void removeServiceListener(String className, Filter filter,
+        ExtendedServiceListener<ExtendedServiceEvent> listener)
+    {
+        synchronized (listenerMap)
+        {
+            ListenerInfo listenerInfo = listenerMap.get(className);
+            if (listenerInfo != null)
+            {
+                if (listenerInfo.remove(filter, listener))
+                {
+                    listenerMap.remove(className);
+                    m_context.removeServiceListener(listenerInfo);
+                }
+            }
+        }
+    }
 
     /**
      * Called upon starting of the bundle. This method invokes initialize() which
-     * parses the metadata and creates the instance managers
+     * parses the metadata and creates the holders
      *
      * @param componentRegistry The <code>ComponentRegistry</code> used to
      *      register components with to ensure uniqueness of component names
@@ -94,8 +241,7 @@ public class BundleComponentActivator im
      *
      * @throws ComponentException if any error occurrs initializing this class
      */
-    BundleComponentActivator( ComponentRegistry componentRegistry,
-        ComponentActorThread componentActor, BundleContext context, ScrConfiguration configuration ) throws ComponentException
+    BundleComponentActivator(ComponentRegistry componentRegistry, ComponentActorThread componentActor, BundleContext context, ScrConfiguration configuration) throws ComponentException
     {
         // keep the parameters for later
         m_componentRegistry = componentRegistry;
@@ -104,24 +250,26 @@ public class BundleComponentActivator im
         m_bundle = context.getBundle();
 
         // have the LogService handy (if available)
-        m_logService = new ServiceTracker<LogService, LogService>( context, Activator.LOGSERVICE_CLASS, null );
+        m_logService = new ServiceTracker<LogService, LogService>(context,
+            Activator.LOGSERVICE_CLASS, null);
         m_logService.open();
         m_configuration = configuration;
 
-        log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] active",
-                new Object[] {m_bundle.getBundleId()}, null, null, null );
+        log(LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] active",
+            new Object[] { m_bundle.getBundleId() }, null, null, null);
 
         // Get the Metadata-Location value from the manifest
-        String descriptorLocations = ( String ) m_bundle.getHeaders().get( "Service-Component" );
-        if ( descriptorLocations == null )
+        String descriptorLocations = (String) m_bundle.getHeaders().get(
+            "Service-Component");
+        if (descriptorLocations == null)
         {
-            throw new ComponentException( "Service-Component entry not found in the manifest" );
+            throw new ComponentException(
+                "Service-Component entry not found in the manifest");
         }
 
-        initialize( descriptorLocations );
+        initialize(descriptorLocations);
     }
 
-
     /**
      * Gets the MetaData location, parses the meta data and requests the processing
      * of binder instances
@@ -131,37 +279,38 @@ public class BundleComponentActivator im
      *
      * @throws IllegalStateException If the bundle has already been uninstalled.
      */
-    private void initialize( String descriptorLocations )
+    private void initialize(String descriptorLocations)
     {
-        log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] descriptor locations {1}",
-                new Object[] {m_bundle.getBundleId(), descriptorLocations}, null, null, null );
+        log(LogService.LOG_DEBUG,
+            "BundleComponentActivator : Bundle [{0}] descriptor locations {1}",
+            new Object[] { m_bundle.getBundleId(), descriptorLocations }, null, null,
+            null);
 
         // 112.4.1: The value of the the header is a comma separated list of XML entries within the Bundle
-        StringTokenizer st = new StringTokenizer( descriptorLocations, ", " );
+        StringTokenizer st = new StringTokenizer(descriptorLocations, ", ");
 
-        while ( st.hasMoreTokens() )
+        while (st.hasMoreTokens())
         {
             String descriptorLocation = st.nextToken();
 
-            URL[] descriptorURLs = findDescriptors( m_bundle, descriptorLocation );
-            if ( descriptorURLs.length == 0 )
+            URL[] descriptorURLs = findDescriptors(m_bundle, descriptorLocation);
+            if (descriptorURLs.length == 0)
             {
                 // 112.4.1 If an XML document specified by the header cannot be located in the bundle and its attached
                 // fragments, SCR must log an error message with the Log Service, if present, and continue.
-                log( LogService.LOG_ERROR, "Component descriptor entry ''{0}'' not found", new Object[]
-                    { descriptorLocation }, null, null, null );
+                log(LogService.LOG_ERROR, "Component descriptor entry ''{0}'' not found",
+                    new Object[] { descriptorLocation }, null, null, null);
                 continue;
             }
 
             // load from the descriptors
-            for ( URL descriptorURL : descriptorURLs )
+            for (URL descriptorURL : descriptorURLs)
             {
-                loadDescriptor( descriptorURL );
+                loadDescriptor(descriptorURL);
             }
         }
     }
 
-
     /**
      * Called outside the constructor so that the m_managers field is completely initialized.
      * A component might possibly start a thread to enable other components, which could access m_managers
@@ -169,21 +318,27 @@ public class BundleComponentActivator im
     void initialEnable()
     {
         //enable all the enabled components
-        for ( ComponentHolder<?> componentHolder : m_managers )
+        for (ComponentHolder<?> componentHolder : m_managers)
         {
-            log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] May enable component holder {1}",
-                    new Object[] {m_bundle.getBundleId(), componentHolder.getComponentMetadata().getName()}, null, null, null );
-
-            if ( componentHolder.getComponentMetadata().isEnabled() )
-            {
-                log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] Enabling component holder {1}",
-                        new Object[] {m_bundle.getBundleId(), componentHolder.getComponentMetadata().getName()}, null, null, null );
+            log(LogService.LOG_DEBUG,
+                "BundleComponentActivator : Bundle [{0}] May enable component holder {1}",
+                new Object[] { m_bundle.getBundleId(),
+                        componentHolder.getComponentMetadata().getName() }, null, null,
+                null);
+
+            if (componentHolder.getComponentMetadata().isEnabled())
+            {
+                log(LogService.LOG_DEBUG,
+                    "BundleComponentActivator : Bundle [{0}] Enabling component holder {1}",
+                    new Object[] { m_bundle.getBundleId(),
+                            componentHolder.getComponentMetadata().getName() }, null,
+                    null, null);
 
                 try
                 {
-                    componentHolder.enableComponents( false );
+                    componentHolder.enableComponents(false);
                 }
-                catch ( Throwable t )
+                catch (Throwable t)
                 {
                     // caught on unhandled RuntimeException or Error
                     // (e.g. ClassDefNotFoundError)
@@ -191,26 +346,30 @@ public class BundleComponentActivator im
                     // make sure the component is properly disabled, just in case
                     try
                     {
-                        componentHolder.disableComponents( false );
+                        componentHolder.disableComponents(false);
                     }
-                    catch ( Throwable ignore )
+                    catch (Throwable ignore)
                     {
                     }
 
-                    log( LogService.LOG_ERROR,
+                    log(LogService.LOG_ERROR,
                         "BundleComponentActivator : Bundle [{0}] Unexpected failure enabling component holder {1}",
-                        new Object[] { m_bundle.getBundleId(), componentHolder.getComponentMetadata().getName() }, null, null, t );
+                        new Object[] { m_bundle.getBundleId(),
+                                componentHolder.getComponentMetadata().getName() }, null,
+                        null, t);
                 }
             }
             else
             {
-                log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] Will not enable component holder {1}",
-                        new Object[] {m_bundle.getBundleId(), componentHolder.getComponentMetadata().getName()}, null, null, null );
+                log(LogService.LOG_DEBUG,
+                    "BundleComponentActivator : Bundle [{0}] Will not enable component holder {1}",
+                    new Object[] { m_bundle.getBundleId(),
+                            componentHolder.getComponentMetadata().getName() }, null,
+                    null, null);
             }
         }
     }
 
-
     /**
      * Finds component descriptors based on descriptor location.
      *
@@ -218,21 +377,22 @@ public class BundleComponentActivator im
      * @param descriptorLocation descriptor location
      * @return array of descriptors or empty array if none found
      */
-    static URL[] findDescriptors( final Bundle bundle, final String descriptorLocation )
+    static URL[] findDescriptors(final Bundle bundle, final String descriptorLocation)
     {
-        if ( bundle == null || descriptorLocation == null || descriptorLocation.trim().length() == 0 )
+        if (bundle == null || descriptorLocation == null
+            || descriptorLocation.trim().length() == 0)
         {
             return new URL[0];
         }
 
         // split pattern and path
-        final int lios = descriptorLocation.lastIndexOf( "/" );
+        final int lios = descriptorLocation.lastIndexOf("/");
         final String path;
         final String filePattern;
-        if ( lios > 0 )
+        if (lios > 0)
         {
-            path = descriptorLocation.substring( 0, lios );
-            filePattern = descriptorLocation.substring( lios + 1 );
+            path = descriptorLocation.substring(0, lios);
+            filePattern = descriptorLocation.substring(lios + 1);
         }
         else
         {
@@ -241,23 +401,22 @@ public class BundleComponentActivator im
         }
 
         // find the entries
-        final Enumeration<URL> entries = bundle.findEntries( path, filePattern, false );
-        if ( entries == null || !entries.hasMoreElements() )
+        final Enumeration<URL> entries = bundle.findEntries(path, filePattern, false);
+        if (entries == null || !entries.hasMoreElements())
         {
             return new URL[0];
         }
 
         // create the result list
         List<URL> urls = new ArrayList<URL>();
-        while ( entries.hasMoreElements() )
+        while (entries.hasMoreElements())
         {
-            urls.add( entries.nextElement() );
+            urls.add(entries.nextElement());
         }
-        return urls.toArray( new URL[urls.size()] );
+        return urls.toArray(new URL[urls.size()]);
     }
 
-
-    private void loadDescriptor( final URL descriptorURL )
+    private void loadDescriptor(final URL descriptorURL)
     {
         // simple path for log messages
         final String descriptorLocation = descriptorURL.getPath();
@@ -267,117 +426,125 @@ public class BundleComponentActivator im
         {
             stream = descriptorURL.openStream();
 
-            BufferedReader in = new BufferedReader( new InputStreamReader( stream, "UTF-8" ) );
-            XmlHandler handler = new XmlHandler( m_bundle, this, getConfiguration().isFactoryEnabled(), getConfiguration().keepInstances() );
+            BufferedReader in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
+            XmlHandler handler = new XmlHandler(m_bundle, this,
+                getConfiguration().isFactoryEnabled(), getConfiguration().keepInstances());
             KXml2SAXParser parser;
 
-            parser = new KXml2SAXParser( in );
+            parser = new KXml2SAXParser(in);
 
-            parser.parseXML( handler );
+            parser.parseXML(handler);
 
             // 112.4.2 Component descriptors may contain a single, root component element
             // or one or more component elements embedded in a larger document
-            for ( Object o : handler.getComponentMetadataList() )
+            for (Object o : handler.getComponentMetadataList())
             {
-                ComponentMetadata metadata = ( ComponentMetadata ) o;
+                ComponentMetadata metadata = (ComponentMetadata) o;
                 ComponentRegistryKey key = null;
                 try
                 {
                     // check and reserve the component name (if not null)
-                    if ( metadata.getName() != null )
+                    if (metadata.getName() != null)
                     {
-                        key = m_componentRegistry.checkComponentName( m_bundle, metadata.getName() );
+                        key = m_componentRegistry.checkComponentName(m_bundle,
+                            metadata.getName());
                     }
 
                     // validate the component metadata
-                    metadata.validate( this );
+                    metadata.validate(this);
 
                     // Request creation of the component manager
-                    ComponentHolder<?> holder = m_componentRegistry.createComponentHolder( this, metadata );
+                    ComponentHolder<?> holder = m_componentRegistry.createComponentHolder(
+                        this, metadata);
 
                     // register the component after validation
-                    m_componentRegistry.registerComponentHolder( key, holder );
-                    m_managers.add( holder );
+                    m_componentRegistry.registerComponentHolder(key, holder);
+                    m_managers.add(holder);
 
-                    log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] ComponentHolder created for {1}",
-                            new Object[] {m_bundle.getBundleId(), metadata.getName()}, null, null, null );
+                    log(LogService.LOG_DEBUG,
+                        "BundleComponentActivator : Bundle [{0}] ComponentHolder created for {1}",
+                        new Object[] { m_bundle.getBundleId(), metadata.getName() },
+                        null, null, null);
 
                 }
-                catch ( Throwable t )
+                catch (Throwable t)
                 {
                     // There is a problem with this particular component, we'll log the error
                     // and proceed to the next one
-                    log( LogService.LOG_ERROR, "Cannot register Component", metadata, null, t );
+                    log(LogService.LOG_ERROR, "Cannot register Component", metadata,
+                        null, t);
 
                     // make sure the name is not reserved any more
-                    if ( key != null )
+                    if (key != null)
                     {
-                        m_componentRegistry.unregisterComponentHolder( key );
+                        m_componentRegistry.unregisterComponentHolder(key);
                     }
                 }
             }
         }
-        catch ( IOException ex )
+        catch (IOException ex)
         {
             // 112.4.1 If an XML document specified by the header cannot be located in the bundle and its attached
             // fragments, SCR must log an error message with the Log Service, if present, and continue.
 
-            log( LogService.LOG_ERROR, "Problem reading descriptor entry ''{0}''", new Object[]
-                { descriptorLocation }, null, null, ex );
+            log(LogService.LOG_ERROR, "Problem reading descriptor entry ''{0}''",
+                new Object[] { descriptorLocation }, null, null, ex);
         }
-        catch ( Exception ex )
+        catch (Exception ex)
         {
-            log( LogService.LOG_ERROR, "General problem with descriptor entry ''{0}''", new Object[]
-                { descriptorLocation }, null, null, ex );
+            log(LogService.LOG_ERROR, "General problem with descriptor entry ''{0}''",
+                new Object[] { descriptorLocation }, null, null, ex);
         }
         finally
         {
-            if ( stream != null )
+            if (stream != null)
             {
                 try
                 {
                     stream.close();
                 }
-                catch ( IOException ignore )
+                catch (IOException ignore)
                 {
                 }
             }
         }
     }
 
-
     /**
     * Dispose of this component activator instance and all the component
     * managers.
     */
-    void dispose( int reason )
+    void dispose(int reason)
     {
-        if ( m_active.compareAndSet( true, false ))
+        if (m_active.compareAndSet(true, false))
         {
-            log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] will destroy {1} instances", new Object[]
-                    { m_bundle.getBundleId(), m_managers.size() }, null, null, null );
+            log(LogService.LOG_DEBUG,
+                "BundleComponentActivator : Bundle [{0}] will destroy {1} instances",
+                new Object[] { m_bundle.getBundleId(), m_managers.size() }, null, null,
+                null);
 
-            for (ComponentHolder<?> holder: m_managers )
+            for (ComponentHolder<?> holder : m_managers)
             {
                 try
                 {
-                    holder.disposeComponents( reason );
+                    holder.disposeComponents(reason);
                 }
-                catch ( Exception e )
+                catch (Exception e)
                 {
-                    log( LogService.LOG_ERROR, "BundleComponentActivator : Exception invalidating", holder
-                            .getComponentMetadata(), null, e );
+                    log(LogService.LOG_ERROR,
+                        "BundleComponentActivator : Exception invalidating",
+                        holder.getComponentMetadata(), null, e);
                 }
                 finally
                 {
-                    m_componentRegistry.unregisterComponentHolder( m_bundle, holder.getComponentMetadata()
-                            .getName() );
+                    m_componentRegistry.unregisterComponentHolder(m_bundle,
+                        holder.getComponentMetadata().getName());
                 }
 
             }
 
-            log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] STOPPED", new Object[]
-                    {m_bundle.getBundleId()}, null, null, null );
+            log(LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] STOPPED",
+                new Object[] { m_bundle.getBundleId() }, null, null, null);
 
             m_logService.close();
             m_closeLatch.countDown();
@@ -388,7 +555,7 @@ public class BundleComponentActivator im
             {
                 m_closeLatch.await(m_configuration.lockTimeout(), TimeUnit.MILLISECONDS);
             }
-            catch ( InterruptedException e )
+            catch (InterruptedException e)
             {
                 //ignore interruption during concurrent shutdown.
             }
@@ -396,7 +563,6 @@ public class BundleComponentActivator im
 
     }
 
-
     /**
      * Returns <true> if this instance is active, that is if components
      * may be activated for this component. The active flag is set early
@@ -409,7 +575,6 @@ public class BundleComponentActivator im
         return m_active.get();
     }
 
-
     /**
     * Returns the BundleContext
     *
@@ -420,13 +585,11 @@ public class BundleComponentActivator im
         return m_context;
     }
 
-
     public ScrConfiguration getConfiguration()
     {
         return m_configuration;
     }
 
-
     /**
      * Implements the <code>ComponentContext.enableComponent(String)</code>
      * method by first finding the component(s) for the <code>name</code> and
@@ -436,24 +599,25 @@ public class BundleComponentActivator im
      * @param name The name of the component to enable or <code>null</code> to
      *      enable all components.
      */
-    public void enableComponent( final String name )
+    public void enableComponent(final String name)
     {
-        final List<ComponentHolder<?>> holder = getSelectedComponents( name );
-        for ( ComponentHolder<?> aHolder : holder )
+        final List<ComponentHolder<?>> holder = getSelectedComponents(name);
+        for (ComponentHolder<?> aHolder : holder)
         {
             try
             {
-                log( LogService.LOG_DEBUG, "Enabling Component", aHolder.getComponentMetadata(), null, null );
-                aHolder.enableComponents( true );
+                log(LogService.LOG_DEBUG, "Enabling Component",
+                    aHolder.getComponentMetadata(), null, null);
+                aHolder.enableComponents(true);
             }
-            catch ( Throwable t )
+            catch (Throwable t)
             {
-                log( LogService.LOG_ERROR, "Cannot enable component", aHolder.getComponentMetadata(), null, t );
+                log(LogService.LOG_ERROR, "Cannot enable component",
+                    aHolder.getComponentMetadata(), null, t);
             }
         }
     }
 
-
     /**
      * Implements the <code>ComponentContext.disableComponent(String)</code>
      * method by first finding the component(s) for the <code>name</code> and
@@ -463,24 +627,25 @@ public class BundleComponentActivator im
      * @param name The name of the component to disable or <code>null</code> to
      *      disable all components.
      */
-    public void disableComponent( final String name )
+    public void disableComponent(final String name)
     {
-        final List<ComponentHolder<?>> holder = getSelectedComponents( name );
-        for ( ComponentHolder<?> aHolder : holder )
+        final List<ComponentHolder<?>> holder = getSelectedComponents(name);
+        for (ComponentHolder<?> aHolder : holder)
         {
             try
             {
-                log( LogService.LOG_DEBUG, "Disabling Component", aHolder.getComponentMetadata(), null, null );
-                aHolder.disableComponents( true );
+                log(LogService.LOG_DEBUG, "Disabling Component",
+                    aHolder.getComponentMetadata(), null, null);
+                aHolder.disableComponents(true);
             }
-            catch ( Throwable t )
+            catch (Throwable t)
             {
-                log( LogService.LOG_ERROR, "Cannot disable component", aHolder.getComponentMetadata(), null, t );
+                log(LogService.LOG_ERROR, "Cannot disable component",
+                    aHolder.getComponentMetadata(), null, t);
             }
         }
     }
 
-
     /**
      * Returns an array of {@link ComponentHolder} instances which match the
      * <code>name</code>. If the <code>name</code> is <code>null</code> an
@@ -496,32 +661,34 @@ public class BundleComponentActivator im
      *      to the <code>name</code> parameter or <code>null</code> if no
      *      component manager with the given name is currently registered.
      */
-    private List<ComponentHolder<?>> getSelectedComponents( String name )
+    private List<ComponentHolder<?>> getSelectedComponents(String name)
     {
         // if all components are selected
-        if ( name == null )
+        if (name == null)
         {
             return m_managers;
         }
 
-        ComponentHolder<?> componentHolder = m_componentRegistry.getComponentHolder( m_bundle, name );
+        ComponentHolder<?> componentHolder = m_componentRegistry.getComponentHolder(
+            m_bundle, name);
         if (componentHolder != null)
         {
-            return Collections.<ComponentHolder<?>>singletonList( componentHolder );
+            return Collections.<ComponentHolder<?>> singletonList(componentHolder);
         }
 
         // if the component is not known
         return Collections.emptyList();
     }
 
-
     //---------- Component ID support
 
-    public long registerComponentId(AbstractComponentManager<?> componentManager) {
+    public long registerComponentId(AbstractComponentManager<?> componentManager)
+    {
         return m_componentRegistry.registerComponentId(componentManager);
     }
 
-    public void unregisterComponentId(AbstractComponentManager<?> componentManager) {
+    public void unregisterComponentId(AbstractComponentManager<?> componentManager)
+    {
         m_componentRegistry.unregisterComponentId(componentManager.getId());
     }
 
@@ -534,48 +701,50 @@ public class BundleComponentActivator im
      *
      * @param task The component task to execute
      */
-    public void schedule( Runnable task )
+    public void schedule(Runnable task)
     {
-        if ( isActive() )
+        if (isActive())
         {
             ComponentActorThread cat = m_componentActor;
-            if ( cat != null )
+            if (cat != null)
             {
-                cat.schedule( task );
+                cat.schedule(task);
             }
             else
             {
-                log( LogService.LOG_DEBUG, "Component Actor Thread not running, calling synchronously", null, null, null );
+                log(LogService.LOG_DEBUG,
+                    "Component Actor Thread not running, calling synchronously", null,
+                    null, null);
                 try
                 {
-                    synchronized ( this )
+                    synchronized (this)
                     {
                         task.run();
                     }
                 }
-                catch ( Throwable t )
+                catch (Throwable t)
                 {
-                    log( LogService.LOG_WARNING, "Unexpected problem executing task", null, null, t );
+                    log(LogService.LOG_WARNING, "Unexpected problem executing task",
+                        null, null, t);
                 }
             }
         }
         else
         {
-            log( LogService.LOG_WARNING, "BundleComponentActivator is not active; not scheduling {0}", new Object[]
-                { task }, null, null, null );
+            log(LogService.LOG_WARNING,
+                "BundleComponentActivator is not active; not scheduling {0}",
+                new Object[] { task }, null, null, null);
         }
     }
 
-
     /**
      * Returns <code>true</code> if logging for the given level is enabled.
      */
-    public boolean isLogEnabled( int level )
+    public boolean isLogEnabled(int level)
     {
         return m_configuration.getLogLevel() >= level;
     }
 
-
     /**
      * Method to actually emit the log message. If the LogService is available,
      * the message will be logged through the LogService. Otherwise the message
@@ -585,20 +754,20 @@ public class BundleComponentActivator im
      * @param pattern The <code>java.text.MessageFormat</code> message format
      *      string for preparing the message
      * @param arguments The format arguments for the <code>pattern</code>
- *      string.
+    *      string.
      * @param componentId
      * @param ex An optional <code>Throwable</code> whose stack trace is written,
      */
-    public void log( int level, String pattern, Object[] arguments, ComponentMetadata metadata, Long componentId, Throwable ex )
+    public void log(int level, String pattern, Object[] arguments,
+        ComponentMetadata metadata, Long componentId, Throwable ex)
     {
-        if ( isLogEnabled( level ) )
+        if (isLogEnabled(level))
         {
-            final String message = MessageFormat.format( pattern, arguments );
-            log( level, message, metadata, componentId, ex );
+            final String message = MessageFormat.format(pattern, arguments);
+            log(level, message, metadata, componentId, ex);
         }
     }
 
-
     /**
      * Method to actually emit the log message. If the LogService is available,
      * the message will be logged through the LogService. Otherwise the message
@@ -609,16 +778,18 @@ public class BundleComponentActivator im
      * @param componentId
      * @param ex An optional <code>Throwable</code> whose stack trace is written,
      */
-    public void log( int level, String message, ComponentMetadata metadata, Long componentId, Throwable ex )
+    public void log(int level, String message, ComponentMetadata metadata,
+        Long componentId, Throwable ex)
     {
-        if ( isLogEnabled( level ) )
+        if (isLogEnabled(level))
         {
             // prepend the metadata name to the message
-            if ( metadata != null )
+            if (metadata != null)
             {
-                if ( componentId != null )
+                if (componentId != null)
                 {
-                    message = "[" + metadata.getName() + "(" + componentId + ")] " + message;
+                    message = "[" + metadata.getName() + "(" + componentId + ")] "
+                        + message;
                 }
                 else
                 {
@@ -627,33 +798,35 @@ public class BundleComponentActivator im
             }
 
             ServiceTracker<LogService, LogService> logService = m_logService;
-            if ( logService != null )
+            if (logService != null)
             {
                 LogService logger = logService.getService();
-                if ( logger == null )
+                if (logger == null)
                 {
-                    Activator.log( level, m_bundle, message, ex );
+                    Activator.log(level, m_bundle, message, ex);
                 }
                 else
                 {
-                    logger.log( level, message, ex );
+                    logger.log(level, message, ex);
                 }
             }
             else
             {
                 // BCA has been disposed off, bundle context is probably invalid. Try to log something.
-                Activator.log( level, null, message, ex );
+                Activator.log(level, null, message, ex);
             }
         }
     }
 
-    public void missingServicePresent( ServiceReference<?> serviceReference )
+    public void missingServicePresent(ServiceReference<?> serviceReference)
     {
-        m_componentRegistry.missingServicePresent( serviceReference, m_componentActor );
+        m_componentRegistry.missingServicePresent(serviceReference, m_componentActor);
     }
 
-    public <T> void registerMissingDependency( DependencyManager<?, T> dependencyManager, ServiceReference<T> serviceReference, int trackingCount )
+    public <T> void registerMissingDependency(DependencyManager<?, T> dependencyManager,
+        ServiceReference<T> serviceReference, int trackingCount)
     {
-        m_componentRegistry.registerMissingDependency(dependencyManager, serviceReference, trackingCount );
+        m_componentRegistry.registerMissingDependency(dependencyManager,
+            serviceReference, trackingCount);
     }
 }

Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java?rev=1692966&r1=1692965&r2=1692966&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java Mon Jul 27 22:01:59 2015
@@ -91,7 +91,7 @@ public class ConfigurableComponentHolder
      * 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;
+    private volatile Integer m_factoryPidIndex;
 
     /**
      * the non-factory configurations shared between all instances.
@@ -132,7 +132,7 @@ public class ConfigurableComponentHolder
      * by this field is also contained in the map</li>
      * <ul>
      */
-    private AbstractComponentManager<S> m_singleComponent;
+    private volatile AbstractComponentManager<S> m_singleComponent;
 
     /**
      * Whether components have already been enabled by calling the
@@ -143,8 +143,8 @@ public class ConfigurableComponentHolder
      */
     private volatile boolean m_enabled;
     private final Object enableLock = new Object();
-    private Promise<Void> m_enablePromise;
-    private Promise<Void> m_disablePromise = Promises.resolved(null);
+    private volatile Promise<Void> m_enablePromise;
+    private volatile Promise<Void> m_disablePromise = Promises.resolved(null);
 
     private final ComponentMethods m_componentMethods;
 

Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurationSupport.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurationSupport.java?rev=1692966&r1=1692965&r2=1692966&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurationSupport.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/config/ConfigurationSupport.java Mon Jul 27 22:01:59 2015
@@ -300,11 +300,14 @@ public class ConfigurationSupport implem
                         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 );
-                            }
+                        	// The below seems to be unnecessary - and if put in, the behaviour is not spec compliant anymore:
+                        	// if a component has a required configuration and a modified method, the component must not be
+                        	// reactivated
+                            // 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() );
                         }
                     }

Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Annotations.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Annotations.java?rev=1692966&r1=1692965&r2=1692966&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Annotations.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Annotations.java Mon Jul 27 22:01:59 2015
@@ -31,6 +31,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.osgi.framework.Bundle;
+import org.osgi.service.component.ComponentException;
 
 public class Annotations
 {
@@ -53,56 +54,68 @@ public class Annotations
                 complexFields.put(key, method);
                 continue;
             }
-            if (returnType.isArray())
+            try
             {
-                Class<?> componentType = returnType.getComponentType();
-                if ( componentType.isInterface() || componentType.isAnnotation())
+                if (returnType.isArray())
                 {
-                    complexFields.put(key, method);
-                    continue;
+                    Class<?> componentType = returnType.getComponentType();
+                    if (componentType.isInterface() || componentType.isAnnotation())
+                    {
+                        complexFields.put(key, method);
+                        continue;
+                    }
+                    cooked = coerceToArray(componentType, raw, b);
+                }
+                else
+                {
+                    cooked = Coercions.coerce(returnType, raw, b);
                 }
-                cooked = coerceToArray(componentType, raw, b);
             }
-            else
+            catch (ComponentException e)
             {
-                cooked = Coercions.coerce( returnType, raw, b );
+                cooked = new Invalid(e);
             }
             m.put( name, cooked );
         }
         if (!complexFields.isEmpty())
-        {
-            if (!supportsInterfaces )
+        { 
+            if (supportsInterfaces )
             {
-            //error
-                return null;//??
-            }
-            Map<String, List<Map<String, Object>>> nested = extractSubMaps(complexFields.keySet(), props);
-            for (Map.Entry<String, Method> entry: complexFields.entrySet())
-            {
-                List<Map<String, Object>> proplist = nested.get(entry.getKey());
-                Method method = entry.getValue();
-                Class<?> returnType  = method.getReturnType();
-                if (returnType.isArray())
+                Map<String, List<Map<String, Object>>> nested = extractSubMaps(complexFields.keySet(), props);
+                for (Map.Entry<String, Method> entry: complexFields.entrySet())
                 {
-                    Class<?> componentType = returnType.getComponentType();
-                    Object result = Array.newInstance(componentType, proplist.size());
-                    for (int i = 0; i < proplist.size(); i++)
+                    List<Map<String, Object>> proplist = nested.get(entry.getKey());
+                    Method method = entry.getValue();
+                    Class<?> returnType  = method.getReturnType();
+                    if (returnType.isArray())
                     {
-                        Map<String, Object> rawElement = proplist.get(i);
-                        Object cooked = toObject(componentType, rawElement, b, supportsInterfaces);
-                        Array.set(result, i, cooked);
+                        Class<?> componentType = returnType.getComponentType();
+                        Object result = Array.newInstance(componentType, proplist.size());
+                        for (int i = 0; i < proplist.size(); i++)
+                        {
+                            Map<String, Object> rawElement = proplist.get(i);
+                            Object cooked = toObject(componentType, rawElement, b, supportsInterfaces);
+                            Array.set(result, i, cooked);
+                        }
+                        m.put(method.getName(), result);
                     }
-                    m.put(method.getName(), result);
-                }
-                else
-                {
-                    if (!proplist.isEmpty())
+                    else
                     {
-                        Object cooked = toObject(returnType, proplist.get(0), b, supportsInterfaces);
-                        m.put(method.getName(), cooked);
+                        if (!proplist.isEmpty())
+                        {
+                            Object cooked = toObject(returnType, proplist.get(0), b, supportsInterfaces);
+                            m.put(method.getName(), cooked);
+                        }
                     }
                 }
             }
+            else
+            {
+                for (Method method: complexFields.values())
+                {
+                    m.put(method.getName(), new Invalid("Invalid annotation member type" + method.getReturnType().getName() + " for member: " + method.getName()));
+                }
+            }
         }
         
         InvocationHandler h = new Handler(m);
@@ -207,9 +220,8 @@ public class Annotations
         return b.toString();
     }
 
-    private static class Handler implements InvocationHandler 
+    private final static class Handler implements InvocationHandler 
     {
-        
         private final Map<String, Object> values;
        
         public Handler(Map<String, Object> values)
@@ -219,9 +231,34 @@ public class Annotations
 
         public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
         {
-            return values.get(method.getName());
+            Object value = values.get(method.getName());
+            if (value instanceof Invalid)
+            {
+                throw new ComponentException(((Invalid)value).getMessage());
+            }
+            return value;
+        }
+        
+    }
+    
+    private final static class Invalid 
+    {
+        private final String message;
+        
+        public Invalid(ComponentException e)
+        {
+            this.message = e.getMessage();
         }
         
+        public Invalid(String message)
+        {
+            this.message = message;
+        }
+
+        public String getMessage()
+        {
+            return message;
+        }
     }
 
 }

Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethod.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethod.java?rev=1692966&r1=1692965&r2=1692966&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethod.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethod.java Mon Jul 27 22:01:59 2015
@@ -43,8 +43,6 @@ implements org.apache.felix.scr.impl.hel
 {
     private final String m_referenceClassName;
 
-    private final ReferenceMetadata.ReferenceScope m_referenceScope;
-
     private enum ParamType {
         serviceReference,
         serviceObjects,
@@ -57,11 +55,10 @@ implements org.apache.felix.scr.impl.hel
 
 
     public BindMethod( final String methodName,
-            final Class<?> componentClass, final String referenceClassName, final DSVersion dsVersion, final boolean configurableServiceProperties, ReferenceScope referenceScope )
+            final Class<?> componentClass, final String referenceClassName, final DSVersion dsVersion, final boolean configurableServiceProperties )
     {
         super( methodName, componentClass, dsVersion, configurableServiceProperties );
         m_referenceClassName = referenceClassName;
-        m_referenceScope = referenceScope;
     }
 
 

Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethods.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethods.java?rev=1692966&r1=1692965&r2=1692966&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethods.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/BindMethods.java Mon Jul 27 22:01:59 2015
@@ -25,7 +25,7 @@ import org.apache.felix.scr.impl.metadat
 import org.apache.felix.scr.impl.metadata.ReferenceMetadata;
 
 /**
- * @version $Rev: 1637793 $ $Date: 2014-11-10 06:51:04 +0100 (Mon, 10 Nov 2014) $
+ * @version $Rev: 1690372 $ $Date: 2015-07-11 16:47:48 +0200 (Sat, 11 Jul 2015) $
  */
 public class BindMethods implements ReferenceMethods
 {
@@ -36,24 +36,23 @@ public class BindMethods implements Refe
     public BindMethods( ReferenceMetadata m_dependencyMetadata, Class<?> instanceClass,
             final DSVersion dsVersion, final boolean configurableServiceProperties )
     {
-        ReferenceMetadata.ReferenceScope referenceScope = m_dependencyMetadata.getScope();
         m_bind = new org.apache.felix.scr.impl.helper.BindMethod(
                 m_dependencyMetadata.getBind(),
                 instanceClass,
                 m_dependencyMetadata.getInterface(),
-                dsVersion, configurableServiceProperties, referenceScope
+                dsVersion, configurableServiceProperties
         );
         m_updated = new org.apache.felix.scr.impl.helper.UpdatedMethod(
                 m_dependencyMetadata.getUpdated(),
                 instanceClass,
                 m_dependencyMetadata.getInterface(),
-                dsVersion, configurableServiceProperties, referenceScope
+                dsVersion, configurableServiceProperties
         );
         m_unbind = new org.apache.felix.scr.impl.helper.UnbindMethod(
                 m_dependencyMetadata.getUnbind(),
                 instanceClass,
                 m_dependencyMetadata.getInterface(),
-                dsVersion, configurableServiceProperties, referenceScope
+                dsVersion, configurableServiceProperties
         );
     }
 

Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Coercions.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Coercions.java?rev=1692966&r1=1692965&r2=1692966&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Coercions.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/Coercions.java Mon Jul 27 22:01:59 2015
@@ -37,6 +37,7 @@ public class Coercions
 //    | Double | Byte | Short
 //| Character | Boolean
     private static final byte byte0 = 0;
+    private static final char char0 = 0;
     private static final double double0 = 0;
     private static final float float0 = 0;
     private static final int int0 = 0;
@@ -53,6 +54,10 @@ public class Coercions
         {
             return coerceToBoolean(raw);
         }
+        if (type == Character.class || type == char.class)
+        {
+            return coerceToChar(raw);
+        }
         if (type == Class.class)
         {
             return coerceToClass(raw, bundle);
@@ -123,7 +128,37 @@ public class Coercions
         {
             return 0;
         }
-        throw new ComponentException( "Unrecognized input type: " + o);
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
+    }
+    
+    public static char coerceToChar(Object o)
+    {
+        o = multipleToSingle( o, byte0 );
+        if (o instanceof Character)
+        {
+            return (Character)o;
+        }
+        if (o instanceof String)
+        {
+            if (((String)o).length() > 0) 
+            {
+                return ((String)o).charAt(0);
+            }
+            return char0;
+        }
+        if (o instanceof Boolean)
+        {
+            return (Boolean)o? 1: char0;
+        }
+        if (o instanceof Number)
+        {
+            return (char)((Number)o).intValue();
+        }
+        if (o == null) 
+        {
+            return char0;
+        }
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
     }
     
     public static double coerceToDouble(Object o)
@@ -160,7 +195,7 @@ public class Coercions
         {
             return 0;
         }
-        throw new ComponentException( "Unrecognized input type: " + o);
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
     }
     
     public static float coerceToFloat(Object o)
@@ -197,7 +232,7 @@ public class Coercions
         {
             return 0;
         }
-        throw new ComponentException( "Unrecognized input type: " + o);
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
     }
     
     public static int coerceToInteger(Object o)
@@ -234,7 +269,7 @@ public class Coercions
         {
             return 0;
         }
-        throw new ComponentException( "Unrecognized input type: " + o);
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
     }
     
     public static long coerceToLong(Object o)
@@ -271,7 +306,7 @@ public class Coercions
         {
             return 0;
         }
-        throw new ComponentException( "Unrecognized input type: " + o);
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
     }
     
     public static short coerceToShort(Object o)
@@ -308,7 +343,7 @@ public class Coercions
         {
             return 0;
         }
-        throw new ComponentException( "Unrecognized input type: " + o);
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
     }
     
     public static String coerceToString(Object o)
@@ -350,13 +385,13 @@ public class Coercions
         }
         if (o instanceof Number)
         {
-            return ((Number)o).intValue() != 0;
+            return ((Number)o).doubleValue() != 0D;
         }
         if (o == null) 
         {
             return false;
         }
-        throw new ComponentException( "Unrecognized input type: " + o);
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
     }
     
     public static Class<?> coerceToClass(Object o, Bundle b)
@@ -377,7 +412,7 @@ public class Coercions
                 throw new ComponentException(e);
             }
         }
-        throw new ComponentException( "Unrecognized input type: " + o);
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
     }
     
     public static <T extends Enum<T>> T coerceToEnum(Object o, Class<T> clazz)
@@ -398,7 +433,7 @@ public class Coercions
         {
             return null;
         }
-        throw new ComponentException( "Unrecognized input type: " + o);
+        throw new ComponentException( "Unrecognized input value: " + o + " of type: " + o.getClass());
     }
     
     private static Object multipleToSingle(Object o, Object defaultValue)

Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/ComponentServiceObjectsHelper.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/ComponentServiceObjectsHelper.java?rev=1692966&r1=1692965&r2=1692966&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/ComponentServiceObjectsHelper.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/helper/ComponentServiceObjectsHelper.java Mon Jul 27 22:01:59 2015
@@ -18,11 +18,9 @@
  */
 package org.apache.felix.scr.impl.helper;
 
-
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collection;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
@@ -31,7 +29,6 @@ import org.osgi.framework.ServiceObjects
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentServiceObjects;
 
-
 /**
  * Utility class for handling references using a ComponentServiceObjects
  * to get services.
@@ -40,9 +37,9 @@ public class ComponentServiceObjectsHelp
 {
     private final BundleContext bundleContext;
 
-    private final Map<ServiceReference, ServiceObjects> serviceObjectsMap = new HashMap<ServiceReference, ServiceObjects>();
+    private final ConcurrentMap<ServiceReference<?>, ComponentServiceObjectsImpl> services = new ConcurrentHashMap<ServiceReference<?>, ComponentServiceObjectsImpl>();
 
-    private final Map<ServiceObjects, List<Object>> services = new HashMap<ServiceObjects, List<Object>>();
+    private final List<ComponentServiceObjectsImpl> closedServices = new ArrayList<ComponentServiceObjectsImpl>();
 
     private final ConcurrentMap<ServiceReference, Object> prototypeInstances = new ConcurrentHashMap<ServiceReference, Object>();
 
@@ -53,86 +50,57 @@ public class ComponentServiceObjectsHelp
 
     public void cleanup()
     {
-        synchronized ( this )
+    	Collection<ComponentServiceObjectsImpl> csos = services.values();
+        services.clear();
+        for(final ComponentServiceObjectsImpl cso : csos)
         {
-            for(final Map.Entry<ServiceObjects, List<Object>> entry : services.entrySet())
-            {
-                for(final Object service : entry.getValue())
-                {
-                    entry.getKey().ungetService(service);
-                }
-            }
-            services.clear();
-            serviceObjectsMap.clear();
+        	cso.deactivate();
+        }
+        synchronized ( this.closedServices )
+        {
+        	csos = new ArrayList<ComponentServiceObjectsImpl>(this.closedServices);
+        	this.closedServices.clear();
+        }
+        for(final ComponentServiceObjectsImpl cso : csos)
+        {
+        	cso.deactivate();
         }
         prototypeInstances.clear();
     }
 
     public ComponentServiceObjects getServiceObjects(final ServiceReference<?> ref)
     {
-        synchronized ( this )
+        ComponentServiceObjectsImpl cso = this.services.get(ref);
+        if ( cso == null )
         {
-            ServiceObjects<?> so = this.serviceObjectsMap.get(ref);
-            if ( so == null )
+            final ServiceObjects serviceObjects = this.bundleContext.getServiceObjects(ref);
+            if ( serviceObjects != null )
             {
-                so = this.bundleContext.getServiceObjects(ref);
-                if ( so != null )
+                cso = new ComponentServiceObjectsImpl(serviceObjects);
+                final ComponentServiceObjectsImpl oldCSO = this.services.putIfAbsent(ref, cso);
+                if ( oldCSO != null )
                 {
-                    this.serviceObjectsMap.put(ref, so);
+                	cso = oldCSO;
                 }
             }
+        }
+        return cso;
+    }
 
-            if ( so != null )
-            {
-                List<Object> services = this.services.get(so);
-                if ( services == null )
-                {
-                    services = new ArrayList<Object>();
-                    this.services.put(so, services);
-                }
-                final ServiceObjects serviceObjects = so;
-                final List<Object> serviceList = services;
-
-                return new ComponentServiceObjects() 
-                {
-
-                    public Object getService() 
-                    {
-                        final Object service = serviceObjects.getService();
-                        if ( service != null )
-                        {
-                            synchronized ( serviceList )
-                            {
-                                serviceList.add(service);
-                            }
-                        }
-                        return service;
-                    }
-
-                    public void ungetService(final Object service) 
-                    {
-                        boolean remove;
-                        synchronized ( serviceList )
-                        {
-                            remove = serviceList.remove(service);
-                        }
-                        if ( remove ) {
-                            serviceObjects.ungetService(service);
-                        }
-                    }
-
-                    public ServiceReference<?> getServiceReference() 
-                    {
-                        return ref;
-                    }
-                };
-            }
+    public void closeServiceObjects(final ServiceReference<?> ref) {
+        ComponentServiceObjectsImpl cso = this.services.remove(ref);
+        if ( cso != null )
+        {
+        	synchronized ( closedServices )
+        	{
+        		closedServices.add(cso);
+        	}
+            cso.close();
         }
-        return null;
+        prototypeInstances.remove(ref);
     }
 
-    
-    public <T> T getPrototypeRefInstance(final ServiceReference<T> ref, ServiceObjects<T> serviceObjects) 
+    public <T> T getPrototypeRefInstance(final ServiceReference<T> ref, ServiceObjects<T> serviceObjects)
     {
     	T service = (T) prototypeInstances.get(ref);
     	if ( service == null )
@@ -148,5 +116,116 @@ public class ComponentServiceObjectsHelp
     	}
     	return service;
     }
-   
+
+    private static final class ComponentServiceObjectsImpl implements ComponentServiceObjects
+    {
+        private final List<Object> instances = new ArrayList<Object>();
+
+        private volatile ServiceObjects serviceObjects;
+
+        private volatile boolean deactivated = false;
+
+        public ComponentServiceObjectsImpl(final ServiceObjects so)
+        {
+            this.serviceObjects = so;
+        }
+
+        public void deactivate()
+        {
+        	this.deactivated = true;
+        	close();
+        }
+
+        /**
+         * Close this instance and unget all services.
+         */
+        public void close()
+        {
+            final ServiceObjects so = this.serviceObjects;
+            this.serviceObjects = null;
+            if ( so != null )
+            {
+            	final List<Object> localInstances = new ArrayList<Object>();
+                synchronized ( this.instances )
+                {
+                	localInstances.addAll(this.instances);
+                	this.instances.clear();
+                }
+                for(final Object obj : localInstances)
+                {
+                    try
+                    {
+                        so.ungetService(obj);
+                    }
+                    catch ( final IllegalStateException ise )
+                    {
+                        // ignore (this happens if the bundle is not valid anymore)
+                    }
+                    catch ( final IllegalArgumentException iae )
+                    {
+                        // ignore (this happens if the service has not been returned by the service objects)
+                    }
+                }
+            }
+        }
+
+        public Object getService()
+        {
+        	if ( this.deactivated )
+        	{
+        		throw new IllegalStateException();
+        	}
+            final ServiceObjects so = this.serviceObjects;
+            Object service = null;
+            if ( so != null )
+            {
+                service = so.getService();
+                if ( service != null )
+                {
+                    synchronized ( this.instances )
+                    {
+                        this.instances.add(service);
+                    }
+                }
+            }
+            return service;
+        }
+
+        public void ungetService(final Object service)
+        {
+        	if ( this.deactivated )
+        	{
+        		throw new IllegalStateException();
+        	}
+            final ServiceObjects so = this.serviceObjects;
+            if ( so != null )
+            {
+                boolean remove;
+                synchronized ( instances )
+                {
+                    remove = instances.remove(service);
+                }
+                if ( remove ) {
+                    so.ungetService(service);
+                }
+            }
+        }
+
+        public ServiceReference<?> getServiceReference()
+        {
+            final ServiceObjects so = this.serviceObjects;
+            if ( so != null )
+            {
+                return so.getServiceReference();
+            }
+            return null;
+        }
+
+		@Override
+		public String toString() {
+			return "ComponentServiceObjectsImpl [instances=" + instances + ", serviceObjects=" + serviceObjects
+					+ ", deactivated=" + deactivated + ", hashCode=" + this.hashCode() + "]";
+		}
+
+    }
  }



Mime
View raw message