use of org.apache.knox.gateway.config.ConfigurationAdapter in project knox by apache.
the class ConfigurationAdapterFactory method loadAdapters.
private static void loadAdapters() {
Map<Class<?>, Class<? extends ConfigurationAdapter>> all = new HashMap<>();
ServiceLoader<ConfigurationAdapterDescriptor> loader = ServiceLoader.load(ConfigurationAdapterDescriptor.class);
if (loader != null) {
Iterator<ConfigurationAdapterDescriptor> i = loader.iterator();
if (i != null) {
while (i.hasNext()) {
ConfigurationAdapterDescriptor descriptor = i.next();
Map<Class<?>, Class<? extends ConfigurationAdapter>> add = descriptor.providedConfigurationAdapters();
if (add != null) {
all.putAll(add);
}
}
}
}
ADAPTERS = Collections.unmodifiableMap(all);
}
use of org.apache.knox.gateway.config.ConfigurationAdapter in project knox by apache.
the class BeanConfigurationAdapterDescriptorTest method testDescriptor.
@Test
public void testDescriptor() {
ConfigurationAdapterDescriptor descriptor = new BeanConfigurationAdapterDescriptor();
Map<Class<?>, Class<? extends ConfigurationAdapter>> map = descriptor.providedConfigurationAdapters();
assertThat(map, hasKey((Class) Object.class));
Class<? extends ConfigurationAdapter> type = map.get(Object.class);
assertThat("Descriptor didn't return " + BeanConfigurationAdapter.class.getName(), type == BeanConfigurationAdapter.class);
}
use of org.apache.knox.gateway.config.ConfigurationAdapter in project knox by apache.
the class ConfigurationAdapterFactory method get.
public static ConfigurationAdapter get(Object config) throws ConfigurationException {
if (config == null) {
throw new NullPointerException("Configuration adapter instantiation impossible for null config object.");
}
try {
Map<Class<?>, Class<? extends ConfigurationAdapter>> adapters = getAdapters();
Class configType = config.getClass();
Class adapterType = findAdapterTypeForConfigTypeOrParent(adapters, configType);
if (adapterType == null) {
throw new ConfigurationException("No configuration adapter found for config type " + configType.getName());
}
Constructor c = findConstructorForConfigType(adapterType, configType);
if (!c.isAccessible()) {
c.setAccessible(true);
}
Object adapter = c.newInstance(config);
return ConfigurationAdapter.class.cast(adapter);
} catch (ConfigurationException e) {
throw e;
} catch (Exception e) {
throw new ConfigurationException("Configuration adapter instantiation failed.", e);
}
}
Aggregations