directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r280479 - /directory/sandbox/trunk/osgi-spec/trunk/configuration/src/main/java/org/apache/configuration/impl/ConfigurationAdminFactory.java
Date Tue, 13 Sep 2005 03:38:37 GMT
Author: erodriguez
Date: Mon Sep 12 20:38:32 2005
New Revision: 280479

URL: http://svn.apache.org/viewcvs?rev=280479&view=rev
Log:
o  changed store listener to an anonymous inner class
o  updated some printStackTrace's to logging statements

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

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=280479&r1=280478&r2=280479&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
Mon Sep 12 20:38:32 2005
@@ -50,29 +50,27 @@
 /**
  * ConfigurationAdmin implementation
  */
-public class ConfigurationAdminFactory implements ServiceFactory, ServiceListener, BundleListener,
-        ConfigurationListener, Lifecycle
+public class ConfigurationAdminFactory implements ServiceFactory, ServiceListener, BundleListener,
Lifecycle
 {
     /** the log for this class */
     private static final Logger log = LoggerFactory.getLogger( ConfigurationAdminFactory.class
);
 
-    private Hashtable locationToPids = new Hashtable();
-    private Hashtable existingBundleLocations = new Hashtable();
-    private JndiConfigurationStore store;
-    private PluginManager pluginManager;
-    private ConfigurationDispatcher configurationDispatcher;
-
     private static final String ANY_LOCATION = "*";
     private static final String FILTER = "(|(objectClass=" + ManagedServiceFactory.class.getName()
+ ")"
             + "(objectClass=" + ManagedService.class.getName() + ")" + "(objectClass="
             + ConfigurationPlugin.class.getName() + "))";
 
-    static String DYNAMIC_BUNDLE_LOCATION = "dynamic.service.bundleLocation";
-
-    public static BundleContext bc;
+    public static final String DYNAMIC_BUNDLE_LOCATION = "dynamic.service.bundleLocation";
 
+    private Hashtable locationToPids = new Hashtable();
+    private Hashtable existingBundleLocations = new Hashtable();
+    private JndiConfigurationStore store;
+    private PluginManager pluginManager;
+    private ConfigurationDispatcher configurationDispatcher;
     private InitialContextFactory factory;
 
+    public static BundleContext bc;
+
     public ConfigurationAdminFactory( ServiceBinderContext sbc )
     {
         bc = sbc.getBundleContext();
@@ -86,7 +84,7 @@
     public void activate()
     {
         store = new JndiConfigurationStore( factory );
-        store.setConfigurationListener( this );
+        setConfigurationListener();
 
         pluginManager = new PluginManager();
 
@@ -99,9 +97,9 @@
             bc.addServiceListener( this, FILTER );
             bc.addBundleListener( this );
         }
-        catch ( InvalidSyntaxException ignored )
+        catch ( InvalidSyntaxException ise )
         {
-            ignored.printStackTrace();
+            log.error( ise.getMessage(), ise );
         }
 
         lookForAlreadyRegisteredServices();
@@ -133,18 +131,6 @@
         log.debug( getName() + " has unbound from " + factory );
     }
 
-    public void configurationChanged( Dictionary configuration )
-    {
-        try
-        {
-            updateTargetServicesMatching( new ConfigurationDictionary( configuration ) );
-        }
-        catch ( IOException ioe )
-        {
-            ioe.printStackTrace();
-        }
-    }
-
     public Object getService( Bundle bundle, ServiceRegistration registration )
     {
         log.debug( getName() + " has received a ServiceFactory.getService() call" );
@@ -185,6 +171,24 @@
         }
     }
 
+    private void setConfigurationListener()
+    {
+        store.setConfigurationListener( new ConfigurationListener()
+        {
+            public void configurationChanged( Dictionary configuration )
+            {
+                try
+                {
+                    updateTargetServicesMatching( new ConfigurationDictionary( configuration
) );
+                }
+                catch ( IOException ioe )
+                {
+                    log.error( ioe.getMessage(), ioe );
+                }
+            }
+        } );
+    }
+
     private void lookForAlreadyRegisteredServices()
     {
         notifyRegisteredServices( ConfigurationPlugin.class.getName() );
@@ -223,19 +227,19 @@
         return bundleLocation != null && existingBundleLocations.get( bundleLocation
) == null;
     }
 
-    private ConfigurationDictionary bindLocationIfNecessary( ServiceReference[] srs, ConfigurationDictionary
d )
+    private ConfigurationDictionary bindLocationIfNecessary( ServiceReference[] srs, ConfigurationDictionary
config )
             throws IOException
     {
-        if ( srs == null || srs.length == 0 || d == null )
+        if ( srs == null || srs.length == 0 || config == null )
         {
-            return d;
+            return config;
         }
 
-        String configLocation = (String) d.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION
);
+        String configLocation = (String) config.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION
);
 
         if ( isNonExistingBundleLocation( configLocation ) )
         {
-            Boolean dynamicLocation = (Boolean) d.get( DYNAMIC_BUNDLE_LOCATION );
+            Boolean dynamicLocation = (Boolean) config.get( DYNAMIC_BUNDLE_LOCATION );
 
             if ( dynamicLocation != null && dynamicLocation.booleanValue() )
             {
@@ -245,19 +249,19 @@
 
         if ( configLocation == null )
         {
-            String fpid = (String) d.get( ConfigurationAdmin.SERVICE_FACTORYPID );
-            String pid = (String) d.get( Constants.SERVICE_PID );
+            String factoryPid = (String) config.get( ConfigurationAdmin.SERVICE_FACTORYPID
);
+            String servicePid = (String) config.get( Constants.SERVICE_PID );
             String serviceLocation = srs[ 0 ].getBundle().getLocation();
 
-            ConfigurationDictionary copy = d.createCopy();
+            ConfigurationDictionary copy = config.createCopy();
             copy.put( ConfigurationAdmin.SERVICE_BUNDLELOCATION, serviceLocation );
             copy.put( DYNAMIC_BUNDLE_LOCATION, Boolean.TRUE );
 
-            store.store( pid, fpid, copy );
+            store.store( servicePid, factoryPid, copy );
             return copy;
         }
 
-        return d;
+        return config;
     }
 
     private void findAndUnbindConfigurationsDynamicallyBoundTo( String bundleLocation )
@@ -272,9 +276,13 @@
                 configurations[ ii ].setBundleLocation( null );
             }
         }
-        catch ( Exception e )
+        catch ( IOException ioe )
+        {
+            log.error( "Error loading configurations while unbinding configurations bound
to " + bundleLocation, ioe );
+        }
+        catch ( InvalidSyntaxException ise )
         {
-            log.error( "Error while unbinding configurations bound to " + bundleLocation,
e );
+            log.error( "Error with filter while unbinding configurations bound to " + bundleLocation,
ise );
         }
     }
 
@@ -369,7 +377,7 @@
         }
     }
 
-    void updateTargetServicesMatching( ConfigurationDictionary cd ) throws IOException
+    private void updateTargetServicesMatching( ConfigurationDictionary cd ) throws IOException
     {
         String servicePid = (String) cd.get( Constants.SERVICE_PID );
 



Mime
View raw message