本文整理汇总了Java中org.apache.tamaya.ConfigException类的典型用法代码示例。如果您正苦于以下问题:Java ConfigException类的具体用法?Java ConfigException怎么用?Java ConfigException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigException类属于org.apache.tamaya包,在下文中一共展示了ConfigException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterProperty
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
if(matches !=null){
if(!value.getKey().matches(matches)) {
return value;
}
}
Subject s = javax.security.auth.Subject.getSubject(AccessController.getContext());
for(Principal principal:s.getPrincipals()){
for(String role:rolesArray) {
if(principal.getName().equals(role)){
return value;
}
}
}
switch(policy){
case THROW_EXCPETION:
throw new ConfigException("Unauthorized access to '"+value.getKey()+"', not in " + roles);
case WARN_ONLY:
LOG.warning("Unauthorized access to '"+value.getKey()+"', not in " + roles);
return value;
case HIDE:
default:
return null;
}
}
示例2: read
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Override
public void read(Document document, ConfigurationBuilder configBuilder) {
NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-source-order");
if(nodeList.getLength()==0){
LOG.finer("No property source ordering defined.");
return;
}
if(nodeList.getLength()>1){
throw new ConfigException("Only one property source order can be applied.");
}
Node node = nodeList.item(0);
String type = node.getAttributes().getNamedItem("type").getNodeValue();
ItemFactory<Comparator> comparatorFactory = ItemFactoryManager.getInstance().getFactory(Comparator.class, type);
Comparator comparator = comparatorFactory.create(ComponentConfigurator.extractParameters(node));
ComponentConfigurator.configure(comparator, node);
LOG.finer("Sorting property sources using comparator: " + comparator.getClass().getName());
configBuilder.sortPropertySources(comparator);
}
示例3: read
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Override
public void read(Document document, ConfigurationBuilder configBuilder) {
NodeList nodeList = document.getDocumentElement().getElementsByTagName("combination-policy");
if(nodeList.getLength()==0){
LOG.finest("No explicit combination policy configured, using default.");
return;
}
if(nodeList.getLength()>1){
throw new ConfigException("Only one combination policy can be applied.");
}
Node node = nodeList.item(0);
String type = node.getAttributes().getNamedItem("class").getNodeValue();
LOG.finest("Loading combination policy configured: " + type);
ItemFactory<PropertyValueCombinationPolicy> policyFactory = ItemFactoryManager.getInstance().getFactory(PropertyValueCombinationPolicy.class, type);
PropertyValueCombinationPolicy policy = policyFactory.create(ComponentConfigurator.extractParameters(node));
ComponentConfigurator.configure(policy, node);
configBuilder.setPropertyValueCombinationPolicy(policy);
}
示例4: read
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Override
public void read(Document document, ConfigurationBuilder configBuilder) {
NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-filter-order");
if(nodeList.getLength()==0){
LOG.finer("No property filter ordering configured.");
return;
}
if(nodeList.getLength()>1){
throw new ConfigException("Only one property filter order can be applied.");
}
Node node = nodeList.item(0);
String type = node.getAttributes().getNamedItem("type").getNodeValue();
ItemFactory<Comparator> comparatorFactory = ItemFactoryManager.getInstance().getFactory(Comparator.class, type);
Comparator comparator = comparatorFactory.create(ComponentConfigurator.extractParameters(node));
ComponentConfigurator.configure(comparator, node);
LOG.finer("Sorting property filters using comparator: " + comparator.getClass().getName());
configBuilder.sortPropertyFilter(comparator);
}
示例5: createConfigBuilder
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
/**
* Performs initialization of a new configuration
* context to the {@link MetaConfigurationReader} instances found in the current
* {@link org.apache.tamaya.spi.ServiceContext} and returns the corresponding builder
* instance.
* @param metaConfig URL for loading the {@code tamaya-config.xml} meta-configuration.
* @return a new configuration context builder, never null.
* @throws ConfigException If the URL cannot be read.
*/
public static ConfigurationBuilder createConfigBuilder(URL metaConfig){
URL configFile = Objects.requireNonNull(metaConfig);
LOG.info("TAMAYA: Loading tamaya-config.xml...");
Document document = null;
try {
document = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(configFile.openStream());
ConfigurationBuilder builder = ConfigurationProvider.getConfigurationBuilder();
for(MetaConfigurationReader reader: ServiceContextManager.getServiceContext().getServices(
MetaConfigurationReader.class
)){
LOG.fine("TAMAYA: Executing MetaConfig-Reader: " + reader.getClass().getName() + "...");
reader.read(document, builder);
}
return builder;
} catch (SAXException | IOException | ParserConfigurationException e) {
throw new ConfigException("Cannot read meta-config deom " + metaConfig, e);
}
}
示例6: resolveAndConvert
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Produces
@ConfigProperty
public Object resolveAndConvert(final InjectionPoint injectionPoint) {
LOGGER.finest( () -> "Inject: " + injectionPoint);
final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
String key = annotation.name();
if(key.isEmpty()){
key = getDefaultKey(injectionPoint);
}
// unless the extension is not installed, this should never happen because the extension
// enforces the resolvability of the config
String defaultTextValue = annotation.defaultValue().equals(ConfigProperty.UNCONFIGURED_VALUE) ? null : annotation.defaultValue();
ConversionContext conversionContext = createConversionContext(key, injectionPoint);
Object value = resolveValue(defaultTextValue, conversionContext, injectionPoint);
if (value == null) {
throw new ConfigException(String.format(
"Can't resolve any of the possible config keys: %s to the required target type: %s, supported formats: %s",
key, conversionContext.getTargetType(), conversionContext.getSupportedFormats().toString()));
}
LOGGER.finest(String.format("Injecting %s for key %s in class %s", key, value.toString(), injectionPoint.toString()));
return value;
}
示例7: loadDefaultServiceProvider
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
/**
* Load the {@link ServiceContext} to be used.
*
* @return {@link ServiceContext} to be used for loading the services.
*/
private static ServiceContext loadDefaultServiceProvider() {
ServiceContext highestServiceContext = null;
try {
int highestOrdinal = 0;
for (ServiceContext serviceContext : ServiceLoader.load(ServiceContext.class)) {
if (highestServiceContext == null
|| serviceContext.ordinal() > highestOrdinal) {
highestServiceContext = serviceContext;
highestOrdinal = serviceContext.ordinal();
}
}
} catch (Exception e) {
throw new ConfigException("ServiceContext not loadable", e);
}
if (highestServiceContext==null){
throw new ConfigException("No ServiceContext found");
}
LOG.info("Using Service Context of type: " + highestServiceContext.getClass().getName());
return highestServiceContext;
}
示例8: loadPropertySourcesByName
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
private Collection<? extends PropertySource> loadPropertySourcesByName(String filename) {
List<PropertySource> propertySources = new ArrayList<>();
Enumeration<URL> propertyLocations;
try {
propertyLocations = ServiceContextManager.getServiceContext()
.getResources(filename, currentThread().getContextClassLoader());
} catch (IOException e) {
String msg = format("Error while searching for %s", filename);
throw new ConfigException(msg, e);
}
while (propertyLocations.hasMoreElements()) {
URL currentUrl = propertyLocations.nextElement();
SimplePropertySource sps = new SimplePropertySource(currentUrl);
propertySources.add(sps);
}
return propertySources;
}
示例9: load
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
/**
* loads the Properties from the given URL
*
* @param propertiesFile {@link URL} to load Properties from
* @return loaded {@link Properties}
* @throws IllegalStateException in case of an error while reading properties-file
*/
private static Map<String, PropertyValue> load(URL propertiesFile) {
boolean isXML = isXMLPropertieFiles(propertiesFile);
Map<String, PropertyValue> properties = new HashMap<>();
try (InputStream stream = propertiesFile.openStream()) {
Properties props = new Properties();
if (stream != null) {
if (isXML) {
props.loadFromXML(stream);
} else {
props.load(stream);
}
}
String source = propertiesFile.toString();
for (String key : props.stringPropertyNames()) {
properties.put(key, PropertyValue.of(key, props.getProperty(key), source));
}
} catch (IOException e) {
throw new ConfigException("Error loading properties from " + propertiesFile, e);
}
return properties;
}
示例10: convert
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Override
public T convert(String value, ConversionContext context) {
context.addSupportedFormats(getClass(), "<String -> "+factoryMethod.toGenericString());
if (!Modifier.isStatic(factoryMethod.getModifiers())) {
throw new ConfigException(factoryMethod.toGenericString() +
" is not a static method. Only static " +
"methods can be used as factory methods.");
}
try {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
factoryMethod.setAccessible(true);
return null;
}
});
Object invoke = factoryMethod.invoke(null, value);
return targetType.cast(invoke);
} catch (Exception e) {
throw new ConfigException("Failed to decode '" + value + "'", e);
}
}
示例11: convertValue
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> T convertValue(String key, String value, TypeLiteral<T> type) {
if (value != null) {
List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
ConversionContext context = new ConversionContext.Builder(this, this.configurationContext, key, type)
.build();
for (PropertyConverter<T> converter : converters) {
try {
T t = converter.convert(value, context);
if (t != null) {
return t;
}
} catch (Exception e) {
LOG.log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: " + value, e);
}
}
// if the target type is a String, we can return the value, no conversion required.
if(type.equals(TypeLiteral.of(String.class))){
return (T)value;
}
// unsupported type, throw an exception
throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key +
", supported formats: " + context.getSupportedFormats());
}
return null;
}
示例12: convert
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Override
public Supplier convert(String value, ConversionContext context) {
return () -> {
try{
Type targetType = context.getTargetType().getType();
ParameterizedType pt = (ParameterizedType) targetType;
if(String.class.equals(pt.getActualTypeArguments()[0])){
return value;
}
ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0]));
Object o = context.getConfiguration().query(converter);
if(o==null){
throw new ConfigException("No such value: " + context.getKey());
}
return o;
}catch(Exception e){
throw new ConfigException("Error evaluating config value.", e);
}
};
}
示例13: convert
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Override
public Optional convert(String value, ConversionContext context) {
if(value==null){
return Optional.empty();
}
try{
Type targetType = context.getTargetType().getType();
ParameterizedType pt = (ParameterizedType) targetType;
if(String.class.equals(pt.getActualTypeArguments()[0])){
return Optional.of(value);
}
ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0]));
return Optional.ofNullable(context.getConfiguration().query(converter));
}catch(Exception e){
throw new ConfigException("Error evaluating config value.", e);
}
}
示例14: getAdapter
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Override
public <T> PropertyAdapter<T> getAdapter(Class<T> targetType, WithPropertyAdapter adapterAnnot){
PropertyAdapter adapter = null;
Class<? extends PropertyAdapter> configuredAdapter = null;
if(adapterAnnot != null){
configuredAdapter = adapterAnnot.value();
if(!configuredAdapter.equals(PropertyAdapter.class)){
try{
adapter = configuredAdapter.newInstance();
}
catch(Exception e){
throw new ConfigException("Invalid adapter configured.", e);
}
}
}
if(adapter == null){
adapter = adapters.get(targetType);
}
return adapter;
}
示例15: read
import org.apache.tamaya.ConfigException; //导入依赖的package包/类
@Override
public void read(Document document, ConfigurationBuilder configBuilder) {
NodeList nodeList = document.getDocumentElement().getElementsByTagName("property-filters");
if(nodeList.getLength()==0){
LOG.finer("No property filters configured.");
return;
}
if(nodeList.getLength()>1){
throw new ConfigException("Only one single property-filters section allowed.");
}
nodeList = nodeList.item(0).getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
Node node = nodeList.item(i);
if(node.getNodeType()!=Node.ELEMENT_NODE) {
continue;
}
String type = node.getNodeName();
if ("defaults".equals(type)) {
LOG.finer("Adding default property filters...");
configBuilder.addDefaultPropertyFilters();
continue;
}
ItemFactory<PropertyFilter> filterFactory = ItemFactoryManager.getInstance().getFactory(PropertyFilter.class, type);
if(filterFactory==null){
LOG.severe("No such property filter: " + type);
continue;
}
Map<String,String> params = ComponentConfigurator.extractParameters(node);
PropertyFilter filter = filterFactory.create(params);
if(filter!=null) {
ComponentConfigurator.configure(filter, params);
LOG.finer("Adding configured property filter: " + filter.getClass().getName());
configBuilder.addPropertyFilters(filter);
}
}
}