Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 34673 invoked from network); 13 Sep 2005 03:38:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 13 Sep 2005 03:38:42 -0000 Received: (qmail 40976 invoked by uid 500); 13 Sep 2005 03:38:39 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 40918 invoked by uid 500); 13 Sep 2005 03:38:39 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 40905 invoked by uid 99); 13 Sep 2005 03:38:38 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Sep 2005 20:38:38 -0700 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 12 Sep 2005 20:38:50 -0700 Received: (qmail 34560 invoked by uid 65534); 13 Sep 2005 03:38:37 -0000 Message-ID: <20050913033837.34557.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: erodriguez@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 );