FELIX-3481 Add helper class to manage configurations with targeted PIDs
FELIX-3577 Start factoring out some inner classes

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1356232 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceFactoryTracker.java b/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceFactoryTracker.java
new file mode 100644
index 0000000..c9a36ca
--- /dev/null
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceFactoryTracker.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.cm.impl.helper;
+
+import java.util.Dictionary;
+
+import org.apache.felix.cm.impl.ConfigurationImpl;
+import org.apache.felix.cm.impl.ConfigurationManager;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class ManagedServiceFactoryTracker extends BaseTracker<ManagedServiceFactory>
+{
+
+    public ManagedServiceFactoryTracker( ConfigurationManager cm )
+    {
+        super( cm, ManagedServiceFactory.class );
+    }
+
+
+    @Override
+    protected boolean isFactory()
+    {
+        return true;
+    }
+
+
+    @Override
+    public void provide( ServiceReference<ManagedServiceFactory> reference, final ConfigurationImpl config, final Dictionary<String, ?> rawProps )
+    {
+        ManagedServiceFactory service = getRealService( reference );
+        if ( service != null )
+        {
+            try
+            {
+                Dictionary props = getProperties( rawProps, config.getFactoryPid(), reference );
+                service.updated( config.getPid(), props );
+            }
+            catch ( Throwable t )
+            {
+                this.cm.handleCallBackError( t, reference, config );
+            }
+            finally
+            {
+                this.ungetRealService( reference );
+            }
+        }
+    }
+
+
+    @Override
+    public void remove( ServiceReference<ManagedServiceFactory> reference, final ConfigurationImpl config )
+    {
+        ManagedServiceFactory service = this.getRealService( reference );
+        if ( service != null )
+        {
+            try
+            {
+                service.deleted( config.getPid() );
+            }
+            catch ( Throwable t )
+            {
+                this.cm.handleCallBackError( t, reference, config );
+            }
+            finally
+            {
+                this.ungetRealService( reference );
+            }
+        }
+    }
+}
\ No newline at end of file