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 Contributors: VMware Inc. - initial contribution /
 package org.eclipse.virgo.nano.config.internal.ovf;
 import java.util.Map;
 import java.util.Set;
Implementation of org.eclipse.virgo.nano.config.internal.PropertiesSource that reads properties from an OVF document.

The path to the OVF document is specified using the org.eclipse.virgo.nano.config.ovf framework property.

In order for a property in the OVF document to be exported to OVF its key should have the following format:

Any property keys not starting with the cm: prefix are not exported to config admin. Further, any cm: properties not having both and PID and and name portion will cause an exception.

Concurrent Semantics

 public final class OvfPropertiesSource implements PropertiesSource {
     static final String FRAMEWORK_PROPERTY_OVF = "org.eclipse.virgo.nano.config.ovf";
     private static final String PROPERTY_PREFIX = "cm:";
     private static final String PROPERTY_DELIMITER = ":";
     private final BundleContext bundleContext;
     private final EventLogger eventLogger;
     public OvfPropertiesSource(BundleContext bundleContextEventLogger eventLogger) {
         this. = bundleContext;
         this. = eventLogger;

         Properties sourceProperties = readSourceProperties();
         if (sourceProperties != null) {
             return translateProperties(sourceProperties);
         } else {
             return null;
     private Map<StringPropertiestranslateProperties(Properties sourceProperties) {
         Map<StringPropertiesresult = new HashMap<StringProperties>();
         Set<StringpropertyNames = sourceProperties.stringPropertyNames();
         for (String propertyName : propertyNames) {
             ConfigAdminProperty prop = tryReadConfigAdminProperty(propertyName);
             if(prop != null) {
                 Properties p = result.get(;
                 if(p == null) {
                     p = new Properties();
         return result;

Attempts to convert a property name into a valid configuration admin property based on the format laid out in OvfPropertiesSource.

propertyName the unparsed property name
a OvfPropertiesSource.ConfigAdminProperty or null if the property is not prefixed with cm:
    private ConfigAdminProperty tryReadConfigAdminProperty(String propertyName) {
        ConfigAdminProperty result = null;
        if(propertyName.startsWith()) {
            String parsed = propertyName.substring(.length());
            String[] components = parsed.split();
            if(components.length != 2) {
                throw new IllegalArgumentException("Invalid configuration admin property '" + propertyName + "' found in OVF.");
            } else {
                result = new ConfigAdminProperty();
       = components[0];
                result.key = components[1];
        return result;
    private Properties readSourceProperties() {
        Properties result = null;
        File ovfFile = determineOvfFile();
        if (ovfFile != null) {
            if (!ovfFile.exists()) {
            } else {
                result = readOvfFile(ovfFile);
        return result;
    private File determineOvfFile() {
        File result = null;
        if (path != null) {
            result = new File(path);
        return result;
    private Properties readOvfFile(File ovfFile) {
        Properties result = null;
        Reader reader = null;
        try {
            reader = new FileReader(ovfFile);
            OvfEnvironmentPropertiesReader ovfReader = new OvfEnvironmentPropertiesReader();
            result = ovfReader.readProperties(reader);
        } catch (IOException ex) {
        } finally {
        return result;
    private static class ConfigAdminProperty {
        String pid;
        String key;
New to GrepCode? Check out our FAQ X