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 static org.eclipse.virgo.util.io.IOUtils.closeQuietly;
import  org.osgi.service.cm.Configuration;
import  org.osgi.service.cm.ConfigurationAdmin;
    private static final String PROPERTY_PATTERN = "%s:\t%s\n";
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    private final ConfigurationAdmin configurationAdmin;
    public ConfigurationAdminDumpContributor(ConfigurationAdmin configurationAdmin) {
        this. = configurationAdmin;
    }
    public void contribute(Dump dumpthrows DumpContributionFailedException {
        StringBuilder sb = new StringBuilder();
        try {
            for (Configuration configuration : .listConfigurations(null)) {
                appendHeader(sbconfiguration.getPid());
                appendProperties(sbconfiguration.getProperties());
                appendFooter(sb);
            }
        } catch (Exception e) {
            .warn("Could not enumerate existing configurations");
        }
        Writer out = null;
        try {
            out = dump.createFileWriter("configurationAdmin.properties");
            out.write(sb.toString());
        } catch (IOException e) {
            .warn("Could not write configurationAdmin dump");
        } finally {
            closeQuietly(out);
        }
    }
    public String getName() {
        return "configurationAdmin";
    }
    private void appendHeader(StringBuilder sbString pid) {
        for (int i = 0; i < pid.length() + 4; i++) {
            sb.append("#");
        }
        sb.append("\n# ").append(pid).append(" #\n");
        for (int i = 0; i < pid.length() + 4; i++) {
            sb.append("#");
        }
        sb.append("\n\n");
    }
    private void appendProperties(StringBuilder sbDictionary properties) {
        Enumeration keys = properties.keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            appendProperty(sbkeyproperties.get(key));
        }
    }
    private void appendProperty(StringBuilder sbObject keyObject value) {
        sb.append(String.format(keyvalue));
    }
    private void appendFooter(StringBuilder sb) {
        sb.append("\n\n");
    }
New to GrepCode? Check out our FAQ X