/** * Configure an object of a given class. * * @param loggerContext * the context to assign to this object if it is * {@link ContextAwareBase} * @param clazz * the class to instantiate * @param config * a configuration containing the object's properties - each * top-level key except for "class" must have a corresponding * setter method, or an adder method in the case of lists * @param children * a list which, if not null, will be filled with any child * objects assigned as properties * @return the object instantiated with all properties assigned * @throws ReflectiveOperationException * if any setter/adder method is missing or if the class cannot * be instantiated with a no-argument constructor */ private <T> T configureObject(LoggerContext loggerContext, Class<T> clazz, Config config, List<Object> children) throws ReflectiveOperationException { T object = clazz.newInstance(); if (object instanceof ContextAwareBase) ((ContextAwareBase) object).setContext(loggerContext); ConfigPropertySetter propertySetter = new ConfigPropertySetter(beanCache, object); propertySetter.setContext(loggerContext); for (Entry<String, ConfigValue> entry : config.withoutPath("class").root().entrySet()) { ConfigValue value = entry.getValue(); switch (value.valueType()) { case OBJECT: Config subConfig = config.getConfig("\"" + entry.getKey() + "\""); if (subConfig.hasPath("class")) { Class<?> childClass = Class.forName(subConfig.getString("class")); Object child = this.configureObject(loggerContext, childClass, subConfig, null); String propertyName = NameUtils.toLowerCamelCase(entry.getKey()); propertySetter.setRawProperty(propertyName, child); if (children != null) children.add(child); } else { propertySetter.setProperty(entry.getKey(), config); } break; default: propertySetter.setProperty(entry.getKey(), config); break; } } return object; }
public void printPeriodicity(ContextAwareBase cab) { switch (periodicityType) { case TOP_OF_MILLISECOND: cab.addInfo("Roll-over every millisecond."); break; case TOP_OF_SECOND: cab.addInfo("Roll-over every second."); break; case TOP_OF_MINUTE: cab.addInfo("Roll-over every minute."); break; case TOP_OF_HOUR: cab.addInfo("Roll-over at the top of every hour."); break; case HALF_DAY: cab.addInfo("Roll-over at midday and midnight."); break; case TOP_OF_DAY: cab.addInfo("Roll-over at midnight."); break; case TOP_OF_WEEK: cab.addInfo("Rollover at the start of week."); break; case TOP_OF_MONTH: cab.addInfo("Rollover at start of every month."); break; default: cab.addInfo("Unknown periodicity."); } }