io.confound.system.jndi.provider.SystemJndiConfigurationConcernProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of confound-system-jndi-provider Show documentation
Show all versions of confound-system-jndi-provider Show documentation
Csar concern provider for a JNDI configuration, with overriding system properties or environment variables.
/*
* Copyright © 2018 GlobalMentor, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.confound.system.jndi.provider;
import static io.confound.Confound.*;
import java.util.stream.Stream;
import javax.naming.NamingException;
import io.confound.DefaultConfigurationConcern;
import io.confound.config.ConfigurationException;
import io.confound.config.jndi.JndiConfiguration;
import io.csar.Concern;
import io.csar.ConcernProvider;
/**
* Automatically creates a configuration concern that loads a configuration from JNDI, which can be overridden by system properties or environment variables.
* @author Garret Wilson
*/
public class SystemJndiConfigurationConcernProvider implements ConcernProvider {
@Override
public Stream concerns() {
final JndiConfiguration jndiConfiguration;
try {
jndiConfiguration = new JndiConfiguration();
} catch(final NamingException namingException) {
throw new ConfigurationException(namingException);
}
return Stream.of(new DefaultConfigurationConcern(jndiConfiguration.withFallback(getSystemConfiguration())));
}
}