use of loghub.configuration.ConfigListener.ObjectReference in project LogHub by fbacchella.
the class Configuration method parseObjectDescription.
private <T, C> T parseObjectDescription(ConfigListener.ObjectDescription desc, ThrowingFunction<Class<T>, T> constructor, String currentPipeLineName, int depth, AtomicInteger numSubpipe) throws ConfigException {
try {
@SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) classLoader.loadClass(desc.clazz);
T object = constructor.apply(clazz);
for (Entry<String, ObjectReference> i : desc.beans.entrySet()) {
ObjectReference ref = i.getValue();
Object beanValue;
if (ref instanceof ConfigListener.ObjectWrapped) {
beanValue = ((ConfigListener.ObjectWrapped) ref).wrapped;
if (beanValue instanceof ConfigListener.Pipenode) {
beanValue = getProcessor((ConfigListener.Pipenode) beanValue, currentPipeLineName, depth, numSubpipe);
}
} else if (ref instanceof ConfigListener.ObjectDescription) {
beanValue = parseObjectDescription((ConfigListener.ObjectDescription) ref, emptyConstructor, currentPipeLineName, depth + 1, numSubpipe);
} else if (ref instanceof ConfigListener.Source) {
ConfigListener.Source source = (ConfigListener.Source) ref;
beanValue = sources.get(source.source);
} else if (ref == null) {
beanValue = null;
} else {
throw new ConfigException(String.format("Invalid class '%s': %s", desc.clazz, ref.getClass().getCanonicalName()), desc.stream.getSourceName(), desc.ctx.start);
}
try {
BeansManager.beanSetter(object, i.getKey(), beanValue);
} catch (InvocationTargetException ex) {
throw new ConfigException(String.format("Invalid bean '%s.%s': %s", desc.clazz, i.getKey(), ex.getCause()), desc.stream.getSourceName(), desc.ctx.start, ex.getCause());
}
}
return object;
} catch (ClassNotFoundException e) {
throw new ConfigException(String.format("Unknown class '%s'", desc.clazz), desc.stream.getSourceName(), desc.ctx.start);
} catch (ConfigException e) {
throw e;
} catch (RuntimeException | ExceptionInInitializerError e) {
Throwable rootCause = e;
if (e.getCause() != null) {
rootCause = e.getCause();
}
String message = rootCause.getMessage();
if (message == null) {
message = rootCause.getClass().getSimpleName();
}
throw new ConfigException(String.format("Invalid class '%s': %s", desc.clazz, message), desc.stream.getSourceName(), desc.ctx.start, rootCause);
}
}
Aggregations