diff options
author | Roberto E. Escobar | 2014-03-06 16:58:37 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2014-03-06 16:58:37 +0000 |
commit | be08b1d0e2364628eb76759ed35bf8ca18dbef59 (patch) | |
tree | 8048d1c8ed9b5a3fcd6aa03c2c7418dcb3017af9 /plugins/org.eclipse.osee.config.admin | |
parent | fd54b39d05fe63f384b5810e23ee2c11a1df97c2 (diff) | |
download | org.eclipse.osee-be08b1d0e2364628eb76759ed35bf8ca18dbef59.tar.gz org.eclipse.osee-be08b1d0e2364628eb76759ed35bf8ca18dbef59.tar.xz org.eclipse.osee-be08b1d0e2364628eb76759ed35bf8ca18dbef59.zip |
feature[ats_ATS8941]: Create OSEE Config Admin
Change-Id: I3264c7f38ba3782f759b9520f0f81a89cbb3652c
Diffstat (limited to 'plugins/org.eclipse.osee.config.admin')
14 files changed, 630 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.config.admin/.classpath b/plugins/org.eclipse.osee.config.admin/.classpath new file mode 100644 index 00000000000..ad32c83a788 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.osee.config.admin/.project b/plugins/org.eclipse.osee.config.admin/.project new file mode 100644 index 00000000000..4715ed06333 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.osee.config.admin</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ds.core.builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.eclipse.osee.config.admin/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.config.admin/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..3b72a985514 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: OSEE Config Admin (Incubation) +Bundle-SymbolicName: org.eclipse.osee.config.admin +Bundle-Version: 0.17.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Vendor: Eclipse Open System Engineering Environment +Bundle-ActivationPolicy: lazy +Service-Component: OSGI-INF/*.xml +Import-Package: org.eclipse.osee.framework.jdk.core.type, + org.eclipse.osee.framework.jdk.core.util, + org.eclipse.osee.framework.jdk.core.util.io, + org.eclipse.osee.logger, + org.json, + org.osgi.service.cm diff --git a/plugins/org.eclipse.osee.config.admin/OSGI-INF/config.manager.xml b/plugins/org.eclipse.osee.config.admin/OSGI-INF/config.manager.xml new file mode 100644 index 00000000000..8f49803a222 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/OSGI-INF/config.manager.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" configuration-policy="optional" deactivate="stop" immediate="true"> + <implementation class="org.eclipse.osee.config.admin.internal.ConfigManagerImpl"/> + <reference bind="setLogger" cardinality="1..1" interface="org.eclipse.osee.logger.Log" name="Log" policy="static"/> + <reference bind="setConfigAdmin" cardinality="1..1" interface="org.osgi.service.cm.ConfigurationAdmin" name="ConfigurationAdmin" policy="static"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.config.admin/OSGI-INF/metatype/config.manager.metatypes.xml b/plugins/org.eclipse.osee.config.admin/OSGI-INF/metatype/config.manager.metatypes.xml new file mode 100644 index 00000000000..bb9ac446553 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/OSGI-INF/metatype/config.manager.metatypes.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.1.0"> + <OCD name="config.manager.metatypes" description="Configuration Manager component config" id="config.manager.metatypes" + localization="org.eclipse.osee.config.admin.internal.ConfigManagerConfiguration"> + <AD name="CM Config File" id="cm.config.file" required="true" type="String" /> + <AD name="CM Poll Time" id="cm.poll.time" required="true" type="Long" default="3" /> + <AD name="CM Poll Time Unit" id="cm.poll.time.unit" required="true" type="String" default="SECONDS"> + <Option label="Days" value="DAYS" /> + <Option label="Hours" value="HOURS" /> + <Option label="Micro Seconds" value="MICROSECONDS" /> + <Option label="Milli Seconds" value="MILLISECONDS" /> + <Option label="Minutes" value="MINUTES" /> + <Option label="Nano Seconds" value="NANOSECONDS" /> + <Option label="Seconds" value="SECONDS" /> + </AD> + </OCD> + <Designate pid="org.eclipse.osee.config.admin.internal.ConfigManagerImpl"> + <Object ocdref="config.manager.metatypes" /> + </Designate> +</metatype:MetaData>
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.config.admin/build.properties b/plugins/org.eclipse.osee.config.admin/build.properties new file mode 100644 index 00000000000..c58ea2178c3 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/ diff --git a/plugins/org.eclipse.osee.config.admin/pom.xml b/plugins/org.eclipse.osee.config.admin/pom.xml new file mode 100644 index 00000000000..2d896963ed8 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/pom.xml @@ -0,0 +1,34 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.eclipse.osee</groupId> + <artifactId>org.eclipse.osee.x.core.parent</artifactId> + <version>0.17.0-SNAPSHOT</version> + <relativePath>../../plugins/org.eclipse.osee.x.core.parent</relativePath> + </parent> + + <artifactId>org.eclipse.osee.config.admin</artifactId> + <packaging>eclipse-plugin</packaging> + <name>OSEE Config Admin - (Incubation)</name> + + <build> + <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 --> + <resources> + <resource> + <directory>src</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-source-plugin</artifactId> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerConfiguration.java b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerConfiguration.java new file mode 100644 index 00000000000..0b5ff52cafc --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerConfiguration.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.config.admin.internal; + +import java.util.concurrent.TimeUnit; + +/** + * @author Roberto E. Escobar + */ +public interface ConfigManagerConfiguration { + + String getConfigFile(); + + long getPollTime(); + + TimeUnit getTimeUnit(); + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerConfigurationBuilder.java b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerConfigurationBuilder.java new file mode 100644 index 00000000000..0b1ec52295d --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerConfigurationBuilder.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.config.admin.internal; + +import static org.eclipse.osee.config.admin.internal.ConfigManagerConstants.CONFIGURATION_FILE; +import static org.eclipse.osee.config.admin.internal.ConfigManagerConstants.CONFIGURATION_POLL_TIME; +import static org.eclipse.osee.config.admin.internal.ConfigManagerConstants.CONFIGURATION_POLL_TIME_UNIT; +import static org.eclipse.osee.config.admin.internal.ConfigManagerConstants.DEFAULT_POLL_TIME; +import static org.eclipse.osee.config.admin.internal.ConfigManagerConstants.DEFAULT_POLL_TIME_UNIT; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.eclipse.osee.framework.jdk.core.util.Strings; + +/** + * @author Roberto E. Escobar + */ +public class ConfigManagerConfigurationBuilder { + + private final ConfigManagerConfigurationImpl config = new ConfigManagerConfigurationImpl(); + + private ConfigManagerConfigurationBuilder() { + //Builder class + } + + public static ConfigManagerConfigurationBuilder newBuilder() { + return new ConfigManagerConfigurationBuilder(); + } + + public ConfigManagerConfiguration build() { + return config.clone(); + } + + public ConfigManagerConfigurationBuilder properties(Map<String, Object> props) { + config.loadProperties(props); + return this; + } + + public ConfigManagerConfigurationBuilder pollTime(long pollTime, TimeUnit pollTimeUnit) { + config.setPollTime(pollTime); + config.setPollTimeUnit(pollTimeUnit); + return this; + } + + public ConfigManagerConfigurationBuilder configUri(String configUri) { + config.setConfigFile(configUri); + return this; + } + + private static final class ConfigManagerConfigurationImpl implements ConfigManagerConfiguration, Cloneable { + + private String configFile; + private long pollTime; + private TimeUnit pollTimeUnit; + + @Override + public synchronized ConfigManagerConfigurationImpl clone() { + ConfigManagerConfigurationImpl cloned = new ConfigManagerConfigurationImpl(); + cloned.configFile = this.configFile; + cloned.pollTime = this.pollTime; + cloned.pollTimeUnit = this.pollTimeUnit; + return cloned; + } + + @Override + public String getConfigFile() { + return configFile; + } + + @Override + public long getPollTime() { + return pollTime; + } + + @Override + public TimeUnit getTimeUnit() { + return pollTimeUnit; + } + + public void setConfigFile(String configFile) { + this.configFile = configFile; + } + + public void setPollTime(long pollTime) { + this.pollTime = pollTime; + } + + public void setPollTimeUnit(TimeUnit pollTimeUnit) { + this.pollTimeUnit = pollTimeUnit; + } + + public void loadProperties(Map<String, Object> props) { + if (props != null) { + setConfigFile(get(props, CONFIGURATION_FILE, ConfigUtil.getDefaultConfig())); + setPollTime(getLong(props, CONFIGURATION_POLL_TIME, DEFAULT_POLL_TIME)); + setPollTimeUnit(getTimeUnit(props, CONFIGURATION_POLL_TIME_UNIT, DEFAULT_POLL_TIME_UNIT)); + } + } + + private TimeUnit getTimeUnit(Map<String, Object> props, String pollTimeUnit, TimeUnit defaultPollTimeUnit) { + String value = get(props, pollTimeUnit, defaultPollTimeUnit); + TimeUnit toReturn = TimeUnit.SECONDS; + for (TimeUnit unit : TimeUnit.values()) { + if (unit.name().equalsIgnoreCase(value)) { + toReturn = unit; + break; + } + } + return toReturn; + } + + private long getLong(Map<String, Object> props, String key, Long defaultValue) { + String toReturn = get(props, key, String.valueOf(defaultValue)); + return Strings.isNumeric(toReturn) ? Long.parseLong(toReturn) : 3L; + } + + private String get(Map<String, Object> props, String key, Enum<?> defaultValue) { + return get(props, key, defaultValue != null ? defaultValue.name() : null); + } + + private String get(Map<String, Object> props, String key, String defaultValue) { + String toReturn = defaultValue; + Object object = props.get(key); + if (object != null) { + toReturn = String.valueOf(object); + } + return toReturn; + } + + @Override + public String toString() { + return "ConfigManagerConfigurationImpl [configFile=" + configFile + ", pollTime=" + pollTime + ", pollTimeUnit=" + pollTimeUnit + "]"; + } + + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerConstants.java b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerConstants.java new file mode 100644 index 00000000000..99d186b5935 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerConstants.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.config.admin.internal; + +import java.util.concurrent.TimeUnit; + +/** + * Class to collect configuration constants such as keys and default values. + * + * @author Roberto E. Escobar + */ +public final class ConfigManagerConstants { + + private ConfigManagerConstants() { + // Constants class + } + + public static final String NAMESPACE = "cm"; + + private static String qualify(String value) { + return String.format("%s.%s", NAMESPACE, value); + } + + public static final String CONFIGURATION_FILE = qualify("config.file"); + public static final String CONFIGURATION_POLL_TIME = qualify("poll.time"); + public static final String CONFIGURATION_POLL_TIME_UNIT = qualify("poll.time.unit"); + + public static final long DEFAULT_POLL_TIME = 3L; + public static final TimeUnit DEFAULT_POLL_TIME_UNIT = TimeUnit.SECONDS; + +} diff --git a/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerImpl.java b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerImpl.java new file mode 100644 index 00000000000..52658e2c35c --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigManagerImpl.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.config.admin.internal; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.Dictionary; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.jdk.core.util.io.FileChangeEvent; +import org.eclipse.osee.framework.jdk.core.util.io.FileChangeType; +import org.eclipse.osee.framework.jdk.core.util.io.FileWatcher; +import org.eclipse.osee.framework.jdk.core.util.io.IFileWatcherListener; +import org.eclipse.osee.logger.Log; +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; + +/** + * @author Roberto E. Escobar + */ +public class ConfigManagerImpl implements IFileWatcherListener, ConfigWriter { + + private final ConfigParser parser = new ConfigParser(); + + private Log logger; + private ConfigurationAdmin configAdmin; + + private ConfigManagerConfiguration config; + private final AtomicReference<FileWatcher> watcherRef = new AtomicReference<FileWatcher>(); + + public void setLogger(Log logger) { + this.logger = logger; + } + + public void setConfigAdmin(ConfigurationAdmin configAdmin) { + this.configAdmin = configAdmin; + } + + public void start(Map<String, Object> properties) { + logger.trace("Starting ConfigurationManagerImpl..."); + + update(properties); + } + + public void stop() { + logger.trace("Stopping ConfigurationManagerImpl..."); + + FileWatcher watcher = watcherRef.get(); + close(watcher); + } + + public void update(Map<String, Object> properties) { + logger.trace("Configuring ConfigurationManagerImpl..."); + + config = ConfigManagerConfigurationBuilder.newBuilder()// + .properties(properties) // + .build(); + configure(config); + } + + private void configure(ConfigManagerConfiguration config) { + logger.info("Configuration Manager settings: [%s]", config); + String path = config.getConfigFile(); + if (Strings.isValid(path)) { + File configFile = new File(path); + if (configFile.exists() && configFile.canRead()) { + logger.warn("Reading configuration from: [%s]", configFile); + long pollTime = config.getPollTime(); + TimeUnit timeUnit = config.getTimeUnit(); + + FileWatcher newWatcher = new FileWatcher(pollTime, timeUnit); + newWatcher.addFile(configFile); + newWatcher.addListener(this); + + FileWatcher oldWatcher = watcherRef.getAndSet(newWatcher); + close(oldWatcher); + newWatcher.start(); + + processFile(configFile); + } else { + logger.warn("Config file [%s] is not readable", configFile); + } + } else { + logger.warn("Invalid configuration file: [%s]", path); + } + } + + private void close(FileWatcher watcher) { + if (watcher != null) { + watcher.stop(); + watcher.removeListener(this); + } + } + + @Override + public void filesModified(Collection<FileChangeEvent> fileChangeEvents) { + for (FileChangeEvent event : fileChangeEvents) { + if (event.getChangeType() == FileChangeType.MODIFIED) { + File file = event.getFile(); + processFile(file); + } + } + } + + private void processFile(File file) { + try { + String source = Lib.fileToString(file); + parser.process(this, source); + } catch (Exception ex) { + logger.error(ex, "Error processing config [%s]", file); + } + } + + @Override + public void handleException(Exception ex) { + logger.error(ex, "Error monitoring framework configuration [%s]", config); + } + + @Override + public void write(String serviceId, Dictionary<String, Object> properties) { + Configuration configuration; + try { + configuration = configAdmin.getConfiguration(serviceId, null); + configuration.update(properties); + } catch (IOException ex) { + throw new OseeCoreException(ex); + } + if (logger.isDebugEnabled()) { + StringBuilder builder = new StringBuilder(); + ConfigUtil.writeConfig(configuration, builder); + logger.debug(builder.toString()); + } + } + +} diff --git a/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigParser.java b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigParser.java new file mode 100644 index 00000000000..74dc68e9de7 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigParser.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.config.admin.internal; + +import java.util.Hashtable; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Parses JSON String with the following format: + * + * <pre> + * { + * "config": + * [ + * { + * "serviceId": "service-1", + * "key1": "val1", + * "key2": "val2" + * }, + * { + * "serviceId": "service-2", + * "a": "34242", + * "b": "hello" + * }, + * { + * "serviceId": "service-3" + * } + * ] + * }; + * + * <pre/> + * + * @author Roberto E. Escobar + */ +public class ConfigParser { + + private static final String SERVICE_ID_FIELD = "serviceId"; + private static final String CONFIG_OBJECT = "config"; + + public void process(ConfigWriter writer, String source) { + if (Strings.isValid(source)) { + try { + JSONObject jsonObject = new JSONObject(source); + JSONArray jsonArray = jsonObject.getJSONArray(CONFIG_OBJECT); + for (int index = 0; index < jsonArray.length(); index++) { + JSONObject object = jsonArray.getJSONObject(index); + String serviceId = null; + Hashtable<String, Object> properties = new Hashtable<String, Object>(); + String[] names = JSONObject.getNames(object); + for (String key : names) { + String value = object.getString(key); + if (key.equalsIgnoreCase(SERVICE_ID_FIELD)) { + serviceId = value; + } else { + properties.put(key, value); + } + } + if (Strings.isValid(serviceId)) { + writer.write(serviceId, properties); + } + } + } catch (JSONException ex) { + throw new OseeCoreException(ex); + } + } + } +} diff --git a/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigUtil.java b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigUtil.java new file mode 100644 index 00000000000..36c5c39c441 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigUtil.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.config.admin.internal; + +import java.util.Dictionary; +import java.util.Enumeration; +import org.osgi.service.cm.Configuration; + +/** + * @author Roberto E. Escobar + */ +public final class ConfigUtil { + + private ConfigUtil() { + // Utility class + } + + public static String getDefaultConfig() { + return System.getProperty(ConfigManagerConstants.CONFIGURATION_FILE, ""); + } + + public static void writeConfig(Configuration config, StringBuilder buffer) { + buffer.append("PID = ").append(config.getPid()).append("\n"); + String factoryPid = config.getFactoryPid(); + if (factoryPid != null) { + buffer.append("FactoryPID = ").append(factoryPid).append("\n"); + } + String location = config.getBundleLocation(); + location = location != null ? location : " < unbound > "; + + buffer.append("Bundle-Location : ").append(location).append("\n"); + + buffer.append("Contents :\n"); + Dictionary<String, Object> dict = config.getProperties(); + if (dict != null) { + Enumeration<String> keys = dict.keys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + Object value = dict.get(key); + buffer.append("\t").append(key).append("=").append(value).append("\n"); + } + } + } +} diff --git a/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigWriter.java b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigWriter.java new file mode 100644 index 00000000000..1e46c0a83c1 --- /dev/null +++ b/plugins/org.eclipse.osee.config.admin/src/org/eclipse/osee/config/admin/internal/ConfigWriter.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2014 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.config.admin.internal; + +import java.util.Dictionary; + +/** + * @author Roberto E. Escobar + */ +public interface ConfigWriter { + + void write(String serviceId, Dictionary<String, Object> props); + +} |