当前位置: 首页>>代码示例>>Java>>正文


Java ContextAwareBase类代码示例

本文整理汇总了Java中ch.qos.logback.core.spi.ContextAwareBase的典型用法代码示例。如果您正苦于以下问题:Java ContextAwareBase类的具体用法?Java ContextAwareBase怎么用?Java ContextAwareBase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ContextAwareBase类属于ch.qos.logback.core.spi包,在下文中一共展示了ContextAwareBase类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureObject

import ch.qos.logback.core.spi.ContextAwareBase; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:gnieh,项目名称:logback-config,代码行数:55,代码来源:ConfigConfigurator.java

示例2: printPeriodicity

import ch.qos.logback.core.spi.ContextAwareBase; //导入依赖的package包/类
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.");
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:39,代码来源:RollingCalendar.java


注:本文中的ch.qos.logback.core.spi.ContextAwareBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。