// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.prefs.AbstractPreferences;
import java.util.prefs.BackingStoreException;

public class EnvPreferences extends AbstractPreferences {
    private String tree;
    private String name;
    public EnvPreferences(AbstractPreferences parent, String name, String tree) {
        super(parent, name);
        this.tree = tree;
        this.name = name;
    }
    @Override
    protected void putSpi(String key, String value) {
        throw new RuntimeException("Definition of properties not supported");
    }
    @Override
    protected String getSpi(String key) {
        String lognam = tree + name + "_" + key;
        return System.getenv(lognam.toLowerCase());
    }
    @Override
    protected void removeSpi(String key) {
        throw new RuntimeException("Remove of properties not supported");
    }
    @Override
    protected void removeNodeSpi() throws BackingStoreException {
        throw new RuntimeException("Remove of properties not supported");
    }
    @Override
    protected String[] keysSpi() throws BackingStoreException {
        throw new RuntimeException("Wildcard lookup of properties not supported");
    }
    @Override
    protected String[] childrenNamesSpi() throws BackingStoreException {
        throw new RuntimeException("Wildcard lookup of properties not supported");
    }
    @Override
    protected AbstractPreferences childSpi(String name) {
        return new EnvPreferences(this, this.name + "_" + name, tree);
    }
    @Override
    protected void syncSpi() throws BackingStoreException {
        // nothing
    }
    @Override
    protected void flushSpi() throws BackingStoreException {
        // nothing
    }
}
