All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fish.payara.microprofile.config.spi.InjectedPayaraConfig Maven / Gradle / Ivy

There is a newer version: 4.1.2.181
Show newest version
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fish.payara.microprofile.config.spi;

import java.io.Serializable;
import java.util.Optional;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigSource;

/**
 *
 * @author Steve Millidge 
 */
public class InjectedPayaraConfig implements Config, Serializable {
    
    private transient Config delegate;
    private String appName;
    
    public InjectedPayaraConfig(Config delegate, String appName) {
        this.delegate = delegate;
        this.appName = appName;
    }
    @Override
    public  T getValue(String propertyName, Class propertyType) {
        ensureDelegate();
        return delegate.getValue(propertyName, propertyType);
    }

    @Override
    public  Optional getOptionalValue(String propertyName, Class propertyType) {
        ensureDelegate();
        return delegate.getOptionalValue(propertyName, propertyType);
    }

    @Override
    public Iterable getPropertyNames() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Iterable getConfigSources() {
        ensureDelegate();
        return delegate.getConfigSources();
    }
    
    private void ensureDelegate() {
        if (delegate == null) {
            delegate = (PayaraConfig) ((ConfigProviderResolverImpl)ConfigProviderResolverImpl.instance()).getNamedConfig(appName);
        }
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy