directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r280052 - in /directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration: ./ impl/
Date Sun, 11 Sep 2005 00:25:05 GMT
Author: erodriguez
Date: Sat Sep 10 17:25:00 2005
New Revision: 280052

URL: http://svn.apache.org/viewcvs?rev=280052&view=rev
Log:
Refactoring to remove tangles:
o  Removed load, PID generation, delete, update, and list configs from Config Admin Factory.
o  Moved load and PID generation to Config Admin.
o  Moved update and delete to ConfigurationImpl.
o  Moved all Configuration generation and list retrieval to the store.
o  Widened some Hashtable's to Dictionary's.

Config Admin Factory is now only dealing with service dynamics and, therefore, ready for an
update to use Service Binder.

Modified:
    directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/ConfigurationStore.java
    directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminFactory.java
    directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminImpl.java
    directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationDictionary.java
    directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationImpl.java

Modified: directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/ConfigurationStore.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/ConfigurationStore.java?rev=280052&r1=280051&r2=280052&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/ConfigurationStore.java
(original)
+++ directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/ConfigurationStore.java
Sat Sep 10 17:25:00 2005
@@ -22,12 +22,20 @@
 import java.util.Enumeration;
 
 import org.apache.configuration.impl.ConfigurationDictionary;
-
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
 
 public interface ConfigurationStore
 {
     public abstract Enumeration listPids();
 
+    public abstract Configuration[] listConfigurations( String filter ) throws IOException,
InvalidSyntaxException;
+
+    public abstract Configuration getNewConfiguration( String bundleLocation, String factoryPid,
String servicePid );
+
+    public abstract Configuration getNewConfiguration( String bundleLocation, String factoryPid,
String servicePid,
+            ConfigurationDictionary properties );
+
     public abstract ConfigurationDictionary load( String pid ) throws IOException;
 
     public abstract ConfigurationDictionary[] loadAll( String factoryPid ) throws IOException;
@@ -39,6 +47,6 @@
     public abstract void deleteAll( String factoryPid ) throws IOException;
 
     public abstract String generatePid( String factoryPid ) throws IOException;
-    
+
     public abstract void setConfigurationListener( ConfigurationListener configurationListener
);
 }

Modified: directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminFactory.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminFactory.java?rev=280052&r1=280051&r2=280052&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminFactory.java
(original)
+++ directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminFactory.java
Sat Sep 10 17:25:00 2005
@@ -18,11 +18,8 @@
 package org.apache.configuration.impl;
 
 import java.io.IOException;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
-import java.util.Enumeration;
+import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
 
@@ -33,7 +30,6 @@
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleListener;
 import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceFactory;
@@ -94,7 +90,7 @@
         lookForAlreadyRegisteredServices();
     }
 
-    public void configurationChanged( Hashtable configuration )
+    public void configurationChanged( Dictionary configuration )
     {
         try
         {
@@ -106,6 +102,44 @@
         }
     }
 
+    public Object getService( Bundle bundle, ServiceRegistration registration )
+    {
+        return new ConfigurationAdminImpl( store, bundle );
+    }
+
+    public void ungetService( Bundle bundle, ServiceRegistration registration, Object service
)
+    {
+        // For now we do nothing here
+    }
+
+    public void bundleChanged( BundleEvent event )
+    {
+        if ( event.getType() == BundleEvent.UNINSTALLED )
+        {
+            String uninstalledBundleLocation = event.getBundle().getLocation();
+            existingBundleLocations.remove( uninstalledBundleLocation );
+            findAndUnbindConfigurationsDynamicallyBoundTo( uninstalledBundleLocation );
+        }
+        else
+            if ( event.getType() == BundleEvent.INSTALLED )
+            {
+                String installedBundleLocation = event.getBundle().getLocation();
+                existingBundleLocations.put( installedBundleLocation, installedBundleLocation
);
+            }
+    }
+
+    public void serviceChanged( ServiceEvent event )
+    {
+        ServiceReference sr = event.getServiceReference();
+        int eventType = event.getType();
+        String[] objectClasses = (String[]) sr.getProperty( "objectClass" );
+
+        for ( int ii = 0; ii < objectClasses.length; ++ii )
+        {
+            serviceChanged( sr, eventType, objectClasses[ ii ] );
+        }
+    }
+
     private void lookForAlreadyRegisteredServices()
     {
         notifyRegisteredServices( ConfigurationPlugin.class.getName() );
@@ -187,7 +221,7 @@
                 + DYNAMIC_BUNDLE_LOCATION + "=" + Boolean.TRUE + "))";
         try
         {
-            Configuration[] configurations = listConfigurations( filter );
+            Configuration[] configurations = store.listConfigurations( filter );
             for ( int ii = 0; configurations != null && ii < configurations.length;
++ii )
             {
                 configurations[ ii ].setBundleLocation( null );
@@ -290,7 +324,7 @@
         }
     }
 
-    private void updateTargetServicesMatching( ConfigurationDictionary cd ) throws IOException
+    void updateTargetServicesMatching( ConfigurationDictionary cd ) throws IOException
     {
         String servicePid = (String) cd.get( Constants.SERVICE_PID );
 
@@ -438,159 +472,6 @@
         {
             log.error( "Invalid syntax in ldap filter " + filter, e );
             return new ServiceReference[ 0 ];
-        }
-    }
-
-    void delete( final ConfigurationImpl config ) throws IOException
-    {
-        try
-        {
-            AccessController.doPrivileged( new PrivilegedExceptionAction()
-            {
-                public Object run() throws IOException
-                {
-                    ConfigurationDictionary cd = store.delete( config.getPid() );
-
-                    if ( cd != null )
-                    {
-                        updateTargetServicesMatching( cd );
-                    }
-
-                    return null;
-                }
-            } );
-        }
-        catch ( PrivilegedActionException e )
-        {
-            throw (IOException) e.getException();
-        }
-    }
-
-    void update( final ConfigurationImpl config ) throws IOException
-    {
-        try
-        {
-            AccessController.doPrivileged( new PrivilegedExceptionAction()
-            {
-                public Object run() throws IOException
-                {
-                    store.store( config.getPid(), config.getFactoryPid(), config.getConfigurationDictionary()
);
-                    updateTargetServicesMatching( config.getConfigurationDictionary() );
-                    return null;
-                }
-            } );
-        }
-        catch ( PrivilegedActionException e )
-        {
-            throw (IOException) e.getException();
-        }
-    }
-
-    String generatePid( final String factoryPid ) throws IOException
-    {
-        try
-        {
-            return (String) AccessController.doPrivileged( new PrivilegedExceptionAction()
-            {
-                public Object run() throws IOException
-                {
-                    return store.generatePid( factoryPid );
-                }
-            } );
-        }
-        catch ( PrivilegedActionException e )
-        {
-            throw (IOException) e.getException();
-        }
-    }
-
-    ConfigurationDictionary load( final String pid ) throws IOException
-    {
-        try
-        {
-            return (ConfigurationDictionary) AccessController.doPrivileged( new PrivilegedExceptionAction()
-            {
-                public Object run() throws IOException
-                {
-                    return store.load( pid );
-                }
-            } );
-        }
-        catch ( PrivilegedActionException e )
-        {
-            throw (IOException) e.getException();
-        }
-    }
-
-    Configuration[] listConfigurations( String filterString ) throws IOException, InvalidSyntaxException
-    {
-        Enumeration configurationPids = store.listPids();
-
-        List results = new ArrayList();
-
-        while ( configurationPids.hasMoreElements() )
-        {
-            String pid = (String) configurationPids.nextElement();
-            ConfigurationDictionary config = store.load( pid );
-
-            if ( config == null )
-            {
-                continue;
-            }
-
-            if ( filterString == null )
-            {
-                results.add( new ConfigurationImpl( this, config ) );
-            }
-            else
-            {
-                Filter filter = ConfigurationFactory.bc.createFilter( filterString );
-
-                if ( filter.match( config ) )
-                {
-                    results.add( new ConfigurationImpl( this, config ) );
-                }
-            }
-        }
-
-        return (Configuration[]) results.toArray( new Configuration[ results.size() ] );
-    }
-
-    public Object getService( Bundle bundle, ServiceRegistration registration )
-    {
-        return new ConfigurationAdminImpl( this, bundle );
-    }
-
-    public void ungetService( Bundle bundle, ServiceRegistration registration, Object service
)
-    {
-        // For now we do nothing here
-    }
-
-    public void bundleChanged( BundleEvent event )
-    {
-        if ( event.getType() == BundleEvent.UNINSTALLED )
-        {
-            String uninstalledBundleLocation = event.getBundle().getLocation();
-            existingBundleLocations.remove( uninstalledBundleLocation );
-            findAndUnbindConfigurationsDynamicallyBoundTo( uninstalledBundleLocation );
-        }
-        else
-            if ( event.getType() == BundleEvent.INSTALLED )
-            {
-                String installedBundleLocation = event.getBundle().getLocation();
-                existingBundleLocations.put( installedBundleLocation, installedBundleLocation
);
-            }
-    }
-
-    public void serviceChanged( ServiceEvent event )
-    {
-        ServiceReference sr = event.getServiceReference();
-        int eventType = event.getType();
-        String[] objectClasses = (String[]) sr.getProperty( "objectClass" );
-
-        for ( int ii = 0; ii < objectClasses.length; ++ii )
-        {
-            serviceChanged( sr, eventType, objectClasses[ ii ] );
         }
     }
 

Modified: directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminImpl.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminImpl.java?rev=280052&r1=280051&r2=280052&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminImpl.java
(original)
+++ directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminImpl.java
Sat Sep 10 17:25:00 2005
@@ -22,6 +22,7 @@
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
+import org.apache.configuration.ConfigurationStore;
 import org.osgi.framework.AdminPermission;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.InvalidSyntaxException;
@@ -38,14 +39,14 @@
 {
     private static final AdminPermission ADMIN_PERMISSION = new AdminPermission();
 
-    private final ConfigurationAdminFactory factory;
     private Bundle callingBundle;
     private String callingBundleLocation;
+    private ConfigurationStore store;
 
-    ConfigurationAdminImpl( ConfigurationAdminFactory factory, Bundle callingBundle )
+    ConfigurationAdminImpl( ConfigurationStore store, Bundle callingBundle )
     {
+        this.store = store;
         this.callingBundle = callingBundle;
-        this.factory = factory;
         this.callingBundleLocation = callingBundle.getLocation();
     }
 
@@ -56,8 +57,7 @@
 
     public Configuration createFactoryConfiguration( String factoryPid, String location )
throws IOException
     {
-        ConfigurationImpl config = new ConfigurationImpl( factory, location, factoryPid,
this.factory
-                .generatePid( factoryPid ) );
+        Configuration config = store.getNewConfiguration( location, factoryPid, generatePid(
factoryPid ) );
 
         config.update();
 
@@ -70,7 +70,7 @@
 
         try
         {
-            dictionary = factory.load( pid );
+            dictionary = load( pid );
         }
         catch ( IOException e )
         {
@@ -79,7 +79,7 @@
 
         if ( dictionary == null )
         {
-            return new ConfigurationImpl( factory, callingBundleLocation, null, pid );
+            return store.getNewConfiguration( callingBundleLocation, null, pid );
         }
 
         String bundleLocation = (String) dictionary.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION
);
@@ -93,7 +93,7 @@
 
         String factoryPid = (String) dictionary.get( ConfigurationAdmin.SERVICE_FACTORYPID
);
 
-        return new ConfigurationImpl( factory, bundleLocation, factoryPid, pid, dictionary
);
+        return store.getNewConfiguration( bundleLocation, factoryPid, pid, dictionary );
     }
 
     public Configuration getConfiguration( String pid, String location ) throws IOException
@@ -102,7 +102,7 @@
 
         try
         {
-            dictionary = this.factory.load( pid );
+            dictionary = load( pid );
         }
         catch ( IOException e )
         {
@@ -111,7 +111,7 @@
 
         if ( dictionary == null )
         {
-            ConfigurationImpl c = new ConfigurationImpl( factory, location, null, pid );
+            Configuration c = store.getNewConfiguration( location, null, pid );
 
             if ( location != null )
             {
@@ -124,7 +124,25 @@
         String bundleLocation = (String) dictionary.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION
);
         String factoryPid = (String) dictionary.get( ConfigurationAdmin.SERVICE_FACTORYPID
);
 
-        return new ConfigurationImpl( factory, bundleLocation, factoryPid, pid, dictionary
);
+        return store.getNewConfiguration( bundleLocation, factoryPid, pid, dictionary );
+    }
+
+    private ConfigurationDictionary load( final String pid ) throws IOException
+    {
+        try
+        {
+            return (ConfigurationDictionary) AccessController.doPrivileged( new PrivilegedExceptionAction()
+            {
+                public Object run() throws IOException
+                {
+                    return store.load( pid );
+                }
+            } );
+        }
+        catch ( PrivilegedActionException e )
+        {
+            throw (IOException) e.getException();
+        }
     }
 
     public Configuration[] listConfigurations( final String filterString ) throws IOException,
InvalidSyntaxException
@@ -137,7 +155,7 @@
             {
                 public Object run() throws IOException, InvalidSyntaxException
                 {
-                    return factory.listConfigurations( filterString );
+                    return store.listConfigurations( filterString );
                 }
             } );
         }
@@ -154,5 +172,23 @@
         }
 
         return configurations;
+    }
+
+    private String generatePid( final String factoryPid ) throws IOException
+    {
+        try
+        {
+            return (String) AccessController.doPrivileged( new PrivilegedExceptionAction()
+            {
+                public Object run() throws IOException
+                {
+                    return store.generatePid( factoryPid );
+                }
+            } );
+        }
+        catch ( PrivilegedActionException e )
+        {
+            throw (IOException) e.getException();
+        }
     }
 }

Modified: directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationDictionary.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationDictionary.java?rev=280052&r1=280051&r2=280052&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationDictionary.java
(original)
+++ directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationDictionary.java
Sat Sep 10 17:25:00 2005
@@ -68,7 +68,7 @@
         allowedPrimitiveTypes.put( Boolean.TYPE, Boolean.TYPE );
     }
 
-    private final static Hashtable classToPrimitiveType = new Hashtable();
+    private final static Map classToPrimitiveType = new HashMap();
 
     static
     {
@@ -92,7 +92,7 @@
      * A dictionary holding the key-value pairs of the configuration with
      * the keys in the original case they were entered in.
      */
-    final Hashtable originalCase;
+    final Dictionary originalCase;
 
     public ConfigurationDictionary()
     {
@@ -104,7 +104,7 @@
      * 
      * @param dictionary The original dictionary.
      */
-    public ConfigurationDictionary( Hashtable dictionary )
+    public ConfigurationDictionary( Dictionary dictionary )
     {
         this.lowercaseToOriginalCase = new Hashtable();
         this.originalCase = dictionary;
@@ -214,7 +214,7 @@
         return originalCase.size();
     }
 
-    Hashtable getOriginal()
+    Dictionary getOriginal()
     {
         return originalCase;
     }

Modified: directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationImpl.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationImpl.java?rev=280052&r1=280051&r2=280052&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationImpl.java
(original)
+++ directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationImpl.java
Sat Sep 10 17:25:00 2005
@@ -18,8 +18,12 @@
 package org.apache.configuration.impl;
 
 import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Dictionary;
 
+import org.apache.configuration.ConfigurationStore;
 import org.osgi.framework.Constants;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
@@ -29,12 +33,12 @@
 /**
  * The configuration information for a ManagedService or ManagedServiceFactory object.
  */
-class ConfigurationImpl implements Configuration
+public class ConfigurationImpl implements Configuration
 {
     /** the log for this class */
     private static final Logger log = LoggerFactory.getLogger( ConfigurationImpl.class );
 
-    private final ConfigurationAdminFactory factory;
+    private final ConfigurationStore store;
     private final String factoryPid;
     private final String servicePid;
 
@@ -43,16 +47,16 @@
 
     private ConfigurationDictionary properties;
 
-    ConfigurationImpl( ConfigurationAdminFactory factory, String bundleLocation, String factoryPid,
String servicePid )
+    ConfigurationImpl( ConfigurationStore store, String bundleLocation, String factoryPid,
String servicePid )
     {
-        this( factory, bundleLocation, factoryPid, servicePid, null );
+        this( store, bundleLocation, factoryPid, servicePid, null );
     }
 
-    ConfigurationImpl( ConfigurationAdminFactory factory, String bundleLocation, String factoryPid,
String servicePid,
+    ConfigurationImpl( ConfigurationStore store, String bundleLocation, String factoryPid,
String servicePid,
             ConfigurationDictionary properties )
     {
         this.bundleLocation = bundleLocation;
-        this.factory = factory;
+        this.store = store;
         this.factoryPid = factoryPid;
         this.servicePid = servicePid;
         this.properties = properties;
@@ -63,20 +67,20 @@
         }
     }
 
-    ConfigurationImpl( ConfigurationAdminFactory factory, ConfigurationDictionary properties
)
+    ConfigurationImpl( ConfigurationStore store, ConfigurationDictionary properties )
     {
         this.bundleLocation = (String) properties.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION
);
         this.factoryPid = (String) properties.get( ConfigurationAdmin.SERVICE_FACTORYPID
);
         this.servicePid = (String) properties.get( Constants.SERVICE_PID );
 
-        this.factory = factory;
+        this.store = store;
         this.properties = properties;
     }
 
     public void delete() throws IOException
     {
         throwIfDeleted();
-        factory.delete( this );
+        delete( this );
         deleted = true;
     }
 
@@ -190,7 +194,46 @@
     {
         throwIfDeleted();
         ensureAutoPropertiesAreWritten();
-        factory.update( this );
+        update( this );
+    }
+
+    void delete( final ConfigurationImpl config ) throws IOException
+    {
+        try
+        {
+            AccessController.doPrivileged( new PrivilegedExceptionAction()
+            {
+                public Object run() throws IOException
+                {
+                    store.delete( config.getPid() );
+
+                    return null;
+                }
+            } );
+        }
+        catch ( PrivilegedActionException e )
+        {
+            throw (IOException) e.getException();
+        }
+    }
+
+    void update( final ConfigurationImpl config ) throws IOException
+    {
+        try
+        {
+            AccessController.doPrivileged( new PrivilegedExceptionAction()
+            {
+                public Object run() throws IOException
+                {
+                    store.store( config.getPid(), config.getFactoryPid(), config.getConfigurationDictionary()
);
+                    return null;
+                }
+            } );
+        }
+        catch ( PrivilegedActionException e )
+        {
+            throw (IOException) e.getException();
+        }
     }
 
     void ensureAutoPropertiesAreWritten()



Mime
View raw message