Example usage for org.springframework.core.env PropertySource getClass

List of usage examples for org.springframework.core.env PropertySource getClass

Introduction

In this page you can find the example usage for org.springframework.core.env PropertySource getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:ch.sdi.core.impl.cfg.ConfigUtils.java

/**
 * Tries to retrieve the named PropertySource from the environment. If not found it creates a
 * new one./*from  w ww  .  j  av  a 2 s  .c  o  m*/
 * <p>
 *
 * @param aEnv
 * @param aPropertySourceName
 * @return the embedded property map
 * @throws SdiException if the found property source is not instance of PropertiesPropertySource
 */
public static Map<String, Object> getOrCreatePropertySource(ConfigurableEnvironment aEnv,
        String aPropertySourceName) throws SdiException {
    MutablePropertySources mps = aEnv.getPropertySources();
    PropertySource<?> ps = mps.get(aPropertySourceName);
    PropertiesPropertySource pps = null;

    if (ps == null) {
        Properties props = new Properties();
        pps = new PropertiesPropertySource(aPropertySourceName, props);
        mps.addFirst(pps);
    } else {
        if (!(ps instanceof PropertiesPropertySource)) {
            throw new SdiException("Found property source is not instance of PropertiesPropertySource "
                    + " but: " + ps.getClass().getName(), SdiException.EXIT_CODE_CONFIG_ERROR);
        } // if !( ps instanceof PropertiesPropertySource )

        pps = (PropertiesPropertySource) ps;
    }

    Map<String, Object> map = pps.getSource();
    return map;
}

From source file:io.gravitee.common.util.EnvironmentUtils.java

public static Map<String, Object> getAllProperties(PropertySource<?> aPropSource) {
    Map<String, Object> result = new HashMap<>();

    if (aPropSource instanceof CompositePropertySource) {
        CompositePropertySource cps = (CompositePropertySource) aPropSource;
        cps.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps)));
        return result;
    }//from  w ww . j  a v  a  2  s . com

    if (aPropSource instanceof EnumerablePropertySource<?>) {
        EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource;
        Arrays.asList(ps.getPropertyNames()).forEach(key -> result.put(key, ps.getProperty(key)));
        return result;
    }

    // note: Most descendants of PropertySource are EnumerablePropertySource. There are some
    // few others like JndiPropertySource or StubPropertySource
    LOGGER.debug("Given PropertySource is instanceof " + aPropSource.getClass().getName()
            + " and cannot be iterated");

    return result;
}

From source file:ch.sdi.core.impl.cfg.ConfigUtils.java

/**
 * Returns a collection of all property names in the given PropertySource.
 * <p>/*from   w ww.  j  a va  2s .c  o m*/
 * @param aPropSource
 * @return
 */
public static Collection<String> getAllPropertyNames(PropertySource<?> aPropSource) {
    Collection<String> result = new HashSet<>();

    if (aPropSource instanceof CompositePropertySource) {
        CompositePropertySource cps = (CompositePropertySource) aPropSource;
        cps.getPropertySources().forEach(ps -> result.addAll(getAllPropertyNames(ps)));
        return result;
    }

    if (aPropSource instanceof EnumerablePropertySource<?>) {
        EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource;
        Arrays.asList(ps.getPropertyNames()).forEach(key -> result.add(key));
        return result;
    }

    // note: Most descendants of PropertySource are EnumerablePropertySource. There are some
    // few others like JndiPropertySource or StubPropertySource
    myLog.debug("Given PropertySource is instanceof " + aPropSource.getClass().getName()
            + " and cannot be iterated");

    return result;
}

From source file:io.gravitee.repository.jdbc.config.DataSourceFactory.java

public Map<String, Object> getAllProperties(PropertySource<?> aPropSource) {
    Map<String, Object> result = new HashMap<>();

    if (aPropSource instanceof CompositePropertySource) {
        CompositePropertySource cps = (CompositePropertySource) aPropSource;
        cps.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps)));
        return result;
    }/*  w  w  w  .j a v a  2  s. com*/

    if (aPropSource instanceof EnumerablePropertySource<?>) {
        EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource;
        Arrays.asList(ps.getPropertyNames()).forEach(key -> result.put(key, ps.getProperty(key)));
        return result;
    }

    // note: Most descendants of PropertySource are EnumerablePropertySource. There are some
    // few others like JndiPropertySource or StubPropertySource
    logger.debug("Given PropertySource is instanceof " + aPropSource.getClass().getName()
            + " and cannot be iterated");

    return result;

}