public void addObject(Object object) { Arrays.stream(object.getClass().getDeclaredMethods()) .filter(method -> method.isAnnotationPresent(Config.class)) .forEach(method -> addSupplier(() -> { method.setAccessible(true); try { return method.invoke(object); } catch (Exception e) { throw ConfigurationException.wrap(e, ConfigurationErrorCode.CANNOT_SUPPLY_CONFIGURATION_OBJECT) .put("class", object.getClass()) .put("method", method.getName()); } }, Coffig.pathOf(method))); }
private String computeConfigKey(Configuration configuration, Class<?> fieldType) { return configuration.value().length > 0 ? Joiner.on(".").join(configuration.value()) : Coffig.pathOf(fieldType); }
private TreeNode retrieveTreeNode(Supplier<Object> supplier) { Object o = supplier.get(); TreeNode treeNode = coffig.getMapper().unmap(o, o.getClass()); String prefix = suppliers.get(supplier); if (prefix == null || prefix.isEmpty()) { prefix = Coffig.pathOf(o.getClass()); } if (prefix != null && !prefix.isEmpty()) { MapNode mapNode = new MapNode(); mapNode.set(prefix, treeNode); return mapNode; } else { return treeNode; } } }
public Optional<Object> getOptional(Type configurationType, String... path) { LOGGER.trace( "Accessing configuration path '" + Arrays.toString(path) + "' and mapping it to '" + configurationType .getTypeName() + "'"); if (isDirty()) { refresh(); } String joinedPath; if (path != null && path.length > 0) { joinedPath = String.join(".", (CharSequence[]) path); } else { joinedPath = pathOf(rawClassOf(configurationType)); } Optional<TreeNode> resolvedTree; if (joinedPath == null || joinedPath.isEmpty()) { resolvedTree = Optional.of(this.configurationTree); } else { resolvedTree = this.configurationTree.get(joinedPath); } return resolvedTree.map(treeNode -> mapper.map(treeNode, configurationType)); }