package com.ctrip.framework.apollo.spring.config;

import com.ctrip.framework.apollo.Config;

import org.springframework.core.env.PropertySource;

/**
 * Property source wrapper for Config
 *
 * @author Jason Song(song_s@ctrip.com)
 */
public class ConfigPropertySource extends PropertySource<Config> {
  public ConfigPropertySource(String name, Config source) {
    super(name, source);
  }

  @Override
  public Object getProperty(String name) {
    return this.source.getProperty(name, null);
  }
}

package com.ctrip.framework.apollo.spring.config;

import java.util.Set;
import org.springframework.core.env.EnumerablePropertySource;

import com.ctrip.framework.apollo.Config;

/**
 * Property source wrapper for Config
 *
 * @author Jason Song(song_s@ctrip.com)
 */
public class ConfigPropertySource extends EnumerablePropertySource<Config> {
  private static final String[] EMPTY_ARRAY = new String[0];

  public ConfigPropertySource(String name, Config source) {
    super(name, source);
  }

  @Override
  public String[] getPropertyNames() {
    Set<String> propertyNames = this.source.getPropertyNames();
    if (propertyNames.isEmpty()) {
      return EMPTY_ARRAY;
    }
    return propertyNames.toArray(new String[propertyNames.size()]);
  }

  @Override
  public Object getProperty(String name) {
    return this.source.getProperty(name, null);
  }
}

fix for Spring 4.1.2 that composite property source should extend EnumerablePropertySource