Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008, 2010 VMware Inc. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: VMware Inc. - initial contribution /
 
 
 package org.eclipse.virgo.nano.config.internal;
 
 import java.util.Map;
 
 import  org.osgi.service.cm.Configuration;
 import  org.osgi.service.cm.ConfigurationAdmin;
 
ConfigurationPublisher, publishes kernel configuration to ConfigurationAdmin.

Properties files in config directories are read in and applied to Configurations owned by ConfigurationAdmin. A file called name.properties results in a Configuration with the service pid name.

Concurrent Semantics
Thread-safe.

 
 final class ConfigurationPublisher {
 
     private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
     
     private final ConfigurationAdmin configAdmin;
 
     private final PropertiesSource[] sources;
 
     
     private final static String USER_REGION_CONFIGURATION_PID = "org.eclipse.virgo.kernel.userregion";
 
     ConfigurationPublisher(ConfigurationAdmin configAdminPropertiesSource... sources) {
         this. = configAdmin;
         this. = (sources == null ? new PropertiesSource[0] : sources);
     }
 
     void publishConfigurations() throws IOException {
         for (PropertiesSource source : this.) {
             Map<StringPropertiesconfigurationProperties = source.getConfigurationProperties();
             if (configurationProperties != null) {
                 for (Entry<StringPropertiesentry : configurationProperties.entrySet()) {
                     populateConfigurationWithProperties(entry.getKey(), entry.getValue());
                 }
             }
         }
     }
     
     	ConfigurationExporter configurationExporter = createConfigurationExporterService();
         context.registerService(ConfigurationExporter.classconfigurationExporternull);
     }
 
 		Configuration kernelregionConfiguration = this..getConfiguration();
     	Configuration userregionConfiguration = this..getConfiguration();
     	
         ConfigurationExporter configurationExporter = new StandardConfigurationExporter(userregionConfigurationkernelregionConfiguration);
 		return configurationExporter;
 	}
 
     @SuppressWarnings("unchecked")
     private void populateConfigurationWithProperties(@NonNull String pid, @NonNull Properties propertiesthrows IOException {
         Configuration config = getConfiguration(pidproperties);
 
         Dictionary configProperties = config.getProperties();
         if (configProperties == null) {
             configProperties = new Hashtable();
         }
 
         for (Object key : new IterableEnumeration(properties.keys())) {
             Object value = properties.get(key);
             configProperties.put(keyvalue);
        }
        try {
        	config.update(configProperties);
        } catch (RuntimeException e) {
			.error(String.format("Failed to update configuration for pid '%s'"pid), e);
		}
    }

    

Parameters:
pid
properties
Returns:
Throws:
java.io.IOException
    private Configuration getConfiguration(String pidProperties propertiesthrows IOException {
        Configuration result = null;
        String factoryPid = properties.getProperty(ConfigurationAdmin.SERVICE_FACTORYPID);
        if (StringUtils.hasText(factoryPid)) {
            result = this..createFactoryConfiguration(factoryPidnull);
        } else {
            result = this..getConfiguration(pidnull);
        }
        return result;
    }
New to GrepCode? Check out our FAQ X