Package: ConfigurationInitialiser

ConfigurationInitialiser

nameinstructionbranchcomplexitylinemethod
ConfigurationInitialiser()
M: 6 C: 8
57%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
initializeConsoleConfigurationConvertor(BundleContext, ConfigurationAdmin)
M: 6 C: 11
65%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
initializeDumpContributor(BundleContext, ConfigurationAdmin)
M: 6 C: 15
71%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
publishConfiguration(BundleContext, EventLogger, KernelConfiguration, ConfigurationAdmin)
M: 6 C: 46
88%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
start(BundleContext, EventLogger)
M: 11 C: 36
77%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 10
91%
M: 0 C: 1
100%
stop()
M: 6 C: 7
54%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.nano.config.internal;
13:
14: import java.io.IOException;
15:
16: import org.eclipse.virgo.medic.dump.DumpContributor;
17: import org.eclipse.virgo.medic.eventlog.EventLogger;
18: import org.eclipse.virgo.nano.config.internal.commandline.CommandLinePropertiesSource;
19: import org.eclipse.virgo.nano.config.internal.ovf.OvfPropertiesSource;
20: import org.eclipse.virgo.util.osgi.ServiceRegistrationTracker;
21: import org.osgi.framework.BundleContext;
22: import org.osgi.framework.ServiceReference;
23: import org.osgi.service.cm.ConfigurationAdmin;
24:
25: /**
26: * ConfigurationInitialiser
27: * <p />
28: *
29: * <strong>Concurrent Semantics</strong><br />
30: * threadsafe
31: *
32: */
33: public final class ConfigurationInitialiser {
34:
35: private final ServiceRegistrationTracker tracker = new ServiceRegistrationTracker();
36:
37: private ConsoleConfigurationConvertor consoleConfigurationConvertor;
38:
39: public KernelConfiguration start(BundleContext context, EventLogger eventLogger) throws IOException {
40:
41: //The ConfigurationAdmin service is already available because the caller of this method(CoreBundleActivator.activate)
42: //is a DS component that statically requires it
43: ServiceReference<ConfigurationAdmin> configurationAdminReference = context.getServiceReference(ConfigurationAdmin.class);
44:
45: ConfigurationAdmin configAdmin = null;
46:
47:• if (configurationAdminReference != null) {
48: configAdmin = (ConfigurationAdmin) context.getService(configurationAdminReference);
49: }
50:
51:• if (configAdmin == null) {
52: throw new IllegalStateException("ConfigurationAdmin service missing");
53: }
54: KernelConfiguration configuration = new KernelConfiguration(context);
55:
56: publishConfiguration(context, eventLogger, configuration, configAdmin);
57: initializeDumpContributor(context, configAdmin);
58: initializeConsoleConfigurationConvertor(context, configAdmin);
59: return configuration;
60:
61: }
62:
63: private void publishConfiguration(BundleContext context, EventLogger eventLogger, KernelConfiguration configuration,
64: ConfigurationAdmin configAdmin) throws IOException {
65: PropertiesSource[] sources = new PropertiesSource[] { new UserConfigurationPropertiesSource(configuration.getConfigDirectories()),
66: new OvfPropertiesSource(context, eventLogger), new KernelConfigurationPropertiesSource(configuration),
67: new CommandLinePropertiesSource(context, eventLogger) };
68: ConfigurationPublisher configPublisher = new ConfigurationPublisher(configAdmin, sources);
69: configPublisher.publishConfigurations();
70: configPublisher.registerConfigurationExporterService(context);
71: }
72:
73: private void initializeDumpContributor(BundleContext context, ConfigurationAdmin configAdmin) {
74: ConfigurationAdminDumpContributor dumpContributor = new ConfigurationAdminDumpContributor(configAdmin);
75: this.tracker.track(context.registerService(DumpContributor.class.getName(), dumpContributor, null));
76: }
77:
78: private void initializeConsoleConfigurationConvertor(BundleContext context, ConfigurationAdmin configAdmin) {
79: consoleConfigurationConvertor = new ConsoleConfigurationConvertor(context, configAdmin);
80: consoleConfigurationConvertor.start();
81: }
82:
83: public void stop() {
84: this.tracker.unregisterAll();
85: consoleConfigurationConvertor.stop();
86: }
87: }