You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2007/08/06 09:58:24 UTC

svn commit: r563057 - in /felix/sandbox/fmeschbe/configdamin_bundled_config: ./ src/ src/main/java/org/apache/felix/cm/impl/ src/test/resources/ src/test/resources/org/ src/test/resources/org/apache/ src/test/resources/org/apache/felix/ src/test/resour...

Author: fmeschbe
Date: Mon Aug  6 00:58:23 2007
New Revision: 563057

URL: http://svn.apache.org/viewvc?view=rev&rev=563057
Log:
Copy ConfigAdmin to sandbox as playground

Added:
    felix/sandbox/fmeschbe/configdamin_bundled_config/
      - copied from r563052, felix/trunk/configadmin/
    felix/sandbox/fmeschbe/configdamin_bundled_config/pom.xml
      - copied unchanged from r563056, felix/trunk/configadmin/pom.xml
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/
      - copied from r563056, felix/trunk/configadmin/src/
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest0.ini   (with props)
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest1.ini   (with props)
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest2.ini   (with props)
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3.ini   (with props)
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CR.ini
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CRLF.ini
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_LFCR.ini
Modified:
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationAdapter.java
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java

Modified: felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationAdapter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationAdapter.java?view=diff&rev=563057&r1=563056&r2=563057
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationAdapter.java (original)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationAdapter.java Mon Aug  6 00:58:23 2007
@@ -25,7 +25,7 @@
  * The <code>ConfigurationAdapter</code> TODO
  *
  * @author fmeschbe
- * @version $Rev:$, $Date:$
+ * @version $Rev:$, $Date$
  */
 public class ConfigurationAdapter implements Configuration
 {

Modified: felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java?view=diff&rev=563057&r1=563056&r2=563057
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java (original)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java Mon Aug  6 00:58:23 2007
@@ -20,6 +20,8 @@
 
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
 import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.Comparator;
@@ -32,10 +34,13 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
+import java.util.StringTokenizer;
 import java.util.TreeSet;
 
 import org.apache.felix.cm.PersistenceManager;
+import org.apache.felix.cm.file.ConfigurationHandler;
 import org.apache.felix.cm.file.FilePersistenceManager;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -99,6 +104,13 @@
      */
     public static final String CM_CONFIG_DIR = "felix.cm.dir";
 
+    /**
+     * The name of the Bundle Manifest Header containing the names of entries in
+     * the bundle which contain configuration to be added to the configuration
+     * store (value is "Felix-Configuration").
+     */
+    public static final String FELIX_CONFIGURATION = "Felix-Configuration";
+    
     // random number generator to create configuration PIDs for factory
     // configurations
     private static SecureRandom numberGenerator;
@@ -453,60 +465,114 @@
 
     public void bundleChanged( BundleEvent event )
     {
-        if ( event.getType() == BundleEvent.UNINSTALLED )
+        if ( event.getType() == BundleEvent.INSTALLED )
         {
-            String location = event.getBundle().getLocation();
-
+            handleBundleInstalled( event.getBundle() );
+        }
+        else if ( event.getType() == BundleEvent.UNINSTALLED )
+        {
+            handleBundleUninstalled( event.getBundle().getLocation() );
+        }
+    }
+    
+    private void handleBundleInstalled( Bundle bundle) {
+        String configFiles = (String) bundle.getHeaders().get( FELIX_CONFIGURATION );
+        if (configFiles == null) {
+            // no configuration files contained, nothing to do
+            return;
+        }
+        
+        StringTokenizer tokener = new StringTokenizer(configFiles, ",");
+        while (tokener.hasMoreTokens()) {
+            String token = tokener.nextToken().trim();
+            if (token.length() == 0) {
+                // ignore empty tokens (whitespace only)
+                continue;
+            }
+            
+            URL url = bundle.getEntry( token );
+            if (url == null) {
+                log( LogService.LOG_INFO, "Configuration entry " + token + " missing from bundle "
+                    + bundle.getBundleId() + "/" + bundle.getSymbolicName(), null );
+                continue;
+            }
+            
+            InputStream ins = null;
             try
             {
-                PersistenceManager[] pmList = getPersistenceManagers();
-                for ( int i = 0; i < pmList.length; i++ )
+                ins = url.openStream();
+                Dictionary dict = ConfigurationHandler.read( ins );
+            } catch (IOException ioe) {
+                log( LogService.LOG_WARNING, "Problem reading from configuration entry " + token + " in bundle "
+                    + bundle.getBundleId() + "/" + bundle.getSymbolicName(), ioe );
+            }
+            finally
+            {
+                if ( ins != null )
                 {
-                    Enumeration configs = pmList[i].getDictionaries();
-                    while ( configs.hasMoreElements() )
+                    try
+                    {
+                        ins.close();
+                    }
+                    catch ( IOException ignore )
                     {
-                        Dictionary config = ( Dictionary ) configs.nextElement();
+                    }
+                }
+            }
+        }
+    }
 
-                        String pid = ( String ) config.get( Constants.SERVICE_PID );
-                        if ( pid != null )
+    private void handleBundleUninstalled( String bundleLocation )
+    {
+        try
+        {
+            PersistenceManager[] pmList = getPersistenceManagers();
+            for ( int i = 0; i < pmList.length; i++ )
+            {
+                Enumeration configs = pmList[i].getDictionaries();
+                while ( configs.hasMoreElements() )
+                {
+                    Dictionary config = ( Dictionary ) configs.nextElement();
+
+                    String pid = ( String ) config.get( Constants.SERVICE_PID );
+                    if ( pid != null )
+                    {
+                        ConfigurationImpl cfg = getCachedConfiguration( pid );
+                        if ( cfg == null )
                         {
-                            ConfigurationImpl cfg = getCachedConfiguration( pid );
-                            if ( cfg == null )
-                            {
-                                cfg = new ConfigurationImpl( this, pmList[i], config );
-                            }
+                            cfg = new ConfigurationImpl( this, pmList[i], config );
+                        }
 
-                            if ( location.equals( cfg.getBundleLocation() ) )
-                            {
-                                cfg.setBundleLocation( null );
-                            }
+                        if ( bundleLocation.equals( cfg.getBundleLocation() ) )
+                        {
+                            cfg.setBundleLocation( null );
                         }
-                        else
+                    }
+                    else
+                    {
+
+                        Factory factory = Factory.getFactory( pmList[i], config );
+                        if ( factory != null )
                         {
+                            Factory cachedFactory = ( Factory ) factories.get( factory.getFactoryPid() );
+                            if ( cachedFactory != null )
+                            {
+                                factory = cachedFactory;
+                            }
 
-                            Factory factory = Factory.getFactory( pmList[i], config );
-                            if ( factory != null )
+                            if ( bundleLocation.equals( factory.getBundleLocation() ) )
                             {
-                                Factory cachedFactory = ( Factory ) factories.get( factory.getFactoryPid() );
-                                if ( cachedFactory != null )
-                                {
-                                    factory = cachedFactory;
-                                }
-
-                                if ( location.equals( factory.getBundleLocation() ) )
-                                {
-                                    factory.setBundleLocation( null );
-                                }
+                                factory.setBundleLocation( null );
                             }
                         }
                     }
                 }
-
-            }
-            catch ( Exception e )
-            {
-                log( LogService.LOG_WARNING, "Problem unbinding configurations for bundle " + location, e );
             }
+
+        }
+        catch ( Exception e )
+        {
+            log( LogService.LOG_WARNING, "Problem unbinding configurations for bundle " + bundleLocation, e );
         }
     }
 

Added: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest0.ini
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest0.ini?view=auto&rev=563057
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest0.ini (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest0.ini Mon Aug  6 00:58:23 2007
@@ -0,0 +1,2 @@
+[Section1]
+Entry
\ No newline at end of file

Propchange: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest0.ini
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest1.ini
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest1.ini?view=auto&rev=563057
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest1.ini (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest1.ini Mon Aug  6 00:58:23 2007
@@ -0,0 +1,4 @@
+# This is a comment
+[Section1]
+# Another comment
+Entry
\ No newline at end of file

Propchange: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest1.ini
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest2.ini
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest2.ini?view=auto&rev=563057
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest2.ini (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest2.ini Mon Aug  6 00:58:23 2007
@@ -0,0 +1,11 @@
+# This is a comment
+[Section1]
+# Another comment
+Entry
+
+# A comment after blank lines
+
+Another Entry
+
+Entry 3 \
+# comment not read as a comment
\ No newline at end of file

Propchange: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest2.ini
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3.ini
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3.ini?view=auto&rev=563057
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3.ini (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3.ini Mon Aug  6 00:58:23 2007
@@ -0,0 +1,5 @@
+[Section1]
+Entry
+# comment to not get an empty line, don't care while testing
+[Section2]
+Section2Entry

Propchange: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3.ini
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CR.ini
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CR.ini?view=auto&rev=563057
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CR.ini (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CR.ini Mon Aug  6 00:58:23 2007
@@ -0,0 +1 @@
+[Section1]
Entry
# comment to not get an empty line, don't care while testing
[Section2]
Section2Entry
\ No newline at end of file

Added: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CRLF.ini
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CRLF.ini?view=auto&rev=563057
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CRLF.ini (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_CRLF.ini Mon Aug  6 00:58:23 2007
@@ -0,0 +1,5 @@
+[Section1]
+Entry
+# comment to not get an empty line, don't care while testing
+[Section2]
+Section2Entry

Added: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_LFCR.ini
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_LFCR.ini?view=auto&rev=563057
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_LFCR.ini (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/resources/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest3_LFCR.ini Mon Aug  6 00:58:23 2007
@@ -0,0 +1,6 @@
+[Section1]
+
Entry
+
# comment to not get an empty line, don't care while testing
+
[Section2]
+
Section2Entry
+