org.apache.log4j.helpers.OptionConverter#instantiateByClassName ( )源码实例Demo

下面列出了org.apache.log4j.helpers.OptionConverter#instantiateByClassName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cacheonix-core   文件: AppenderDynamicMBean.java
public
Object invoke(String operationName, Object params[], String signature[])
  throws MBeanException,
  ReflectionException {

  if(operationName.equals("activateOptions") &&
                   appender instanceof OptionHandler) {
    OptionHandler oh = (OptionHandler) appender;
    oh.activateOptions();
    return "Options activated.";
  } else if (operationName.equals("setLayout")) {
    Layout layout = (Layout) OptionConverter.instantiateByClassName((String)
						      params[0],
						      Layout.class,
						      null);
    appender.setLayout(layout);
    registerLayoutMBean(layout);
  }
  return null;
}
 
源代码2 项目: cacheonix-core   文件: RendererMap.java
/**
    Add a renderer to a hierarchy passed as parameter.
 */
 static
 public
 void addRenderer(RendererSupport repository, String renderedClassName,
	   String renderingClassName) {
   LogLog.debug("Rendering class: ["+renderingClassName+"], Rendered class: ["+
	 renderedClassName+"].");
   ObjectRenderer renderer = (ObjectRenderer)
            OptionConverter.instantiateByClassName(renderingClassName,
					    ObjectRenderer.class,
					    null);
   if(renderer == null) {
     LogLog.error("Could not instantiate renderer ["+renderingClassName+"].");
     return;
   } else {
     try {
Class renderedClass = Loader.loadClass(renderedClassName);
repository.setRenderer(renderedClass, renderer);
     } catch(ClassNotFoundException e) {
LogLog.error("Could not find class ["+renderedClassName+"].", e);
     }
   }
 }
 
源代码3 项目: logging-log4j2   文件: XmlConfiguration.java
/**
 * Used internally to parse an {@link ErrorHandler} element.
 */
private void parseErrorHandler(Element element, Appender appender) {
    ErrorHandler eh = (ErrorHandler) OptionConverter.instantiateByClassName(
            subst(element.getAttribute(CLASS_ATTR)),
            ErrorHandler.class,
            null);

    if (eh != null) {
        eh.setAppender(appender);

        PropertySetter propSetter = new PropertySetter(eh);
        forEachElement(element.getChildNodes(), (currentElement) -> {
            String tagName = currentElement.getTagName();
            if (tagName.equals(PARAM_TAG)) {
                setParameter(currentElement, propSetter);
            }
        });
        propSetter.activate();
        appender.setErrorHandler(eh);
    }
}
 
源代码4 项目: logging-log4j2   文件: XmlConfigurationFactory.java
/**
 * Used internally to parse an {@link ErrorHandler} element.
 */
private void parseErrorHandler(Element element, Appender appender) {
    ErrorHandler eh = (ErrorHandler) OptionConverter.instantiateByClassName(
            subst(element.getAttribute(CLASS_ATTR)),
            ErrorHandler.class,
            null);

    if (eh != null) {
        eh.setAppender(appender);

        PropertySetter propSetter = new PropertySetter(eh);
        forEachElement(element.getChildNodes(), (currentElement) -> {
            String tagName = currentElement.getTagName();
            if (tagName.equals(PARAM_TAG)) {
                setParameter(currentElement, propSetter);
            }
        });
        propSetter.activate();
        appender.setErrorHandler(eh);
    }
}
 
源代码5 项目: cacheonix-core   文件: PropertyConfigurator.java
/**
   Check the provided <code>Properties</code> object for a
   {@link org.apache.log4j.spi.LoggerFactory LoggerFactory}
   entry specified by {@link #LOGGER_FACTORY_KEY}.  If such an entry
   exists, an attempt is made to create an instance using the default
   constructor.  This instance is used for subsequent Category creations
   within this configurator.

   @see #parseCatsAndRenderers
 */
protected void configureLoggerFactory(Properties props) {
  String factoryClassName = OptionConverter.findAndSubst(LOGGER_FACTORY_KEY,
					   props);
  if(factoryClassName != null) {
    LogLog.debug("Setting category factory to ["+factoryClassName+"].");
    loggerFactory = (LoggerFactory)
         OptionConverter.instantiateByClassName(factoryClassName,
					 LoggerFactory.class,
					 loggerFactory);
    PropertySetter.setProperties(loggerFactory, props, FACTORY_PREFIX + ".");
  }
}
 
源代码6 项目: cacheonix-core   文件: LoggerDynamicMBean.java
void addAppender(String appenderClass, String appenderName) {
  cat.debug("addAppender called with "+appenderClass+", "+appenderName);
  Appender appender = (Appender)
     OptionConverter.instantiateByClassName(appenderClass,
			      org.apache.log4j.Appender.class,
			      null);
  appender.setName(appenderName);
  logger.addAppender(appender);

  //appenderMBeanRegistration();

}
 
源代码7 项目: cacheonix-core   文件: DOMConfigurator.java
/**
    Used internally to parse a filter element.
  */
 protected
 void parseFilters(Element element, Appender appender) {
   String clazz = subst(element.getAttribute(CLASS_ATTR));
   Filter filter = (Filter) OptionConverter.instantiateByClassName(clazz,
                                               Filter.class, null);
   
   if(filter != null) {
     PropertySetter propSetter = new PropertySetter(filter);
     NodeList children = element.getChildNodes();
     final int length 	= children.getLength();

     for (int loop = 0; loop < length; loop++) {
Node currentNode = children.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
  Element currentElement = (Element) currentNode;
  String tagName = currentElement.getTagName();
  if(tagName.equals(PARAM_TAG)) {
           setParameter(currentElement, propSetter);
  } else {
           quietParseUnrecognizedElement(filter, currentElement, props);
     }
}
     }
     propSetter.activate();
     LogLog.debug("Adding filter of type ["+filter.getClass()
	   +"] to appender named ["+appender.getName()+"].");
     appender.addFilter(filter);
   }    
 }
 
源代码8 项目: cacheonix-core   文件: DOMConfigurator.java
/**
 * Creates an object and processes any nested param elements
 * but does not call activateOptions.  If the class also supports
 * UnrecognizedElementParser, the parseUnrecognizedElement method
 * will be call for any child elements other than param.
 *
 * @param element       element, may not be null.
 * @param props         properties
 * @param expectedClass interface or class expected to be implemented
 *                      by created class
 * @return created class or null.
 * @throws Exception thrown if the contain object should be abandoned.
 * @since 1.2.15
 */
public static Object parseElement(final Element element,
                                         final Properties props,
                                         final Class expectedClass) throws Exception {
    String clazz = subst(element.getAttribute("class"), props);
    Object instance = OptionConverter.instantiateByClassName(clazz,
            expectedClass, null);

    if (instance != null) {
        PropertySetter propSetter = new PropertySetter(instance);
        NodeList children = element.getChildNodes();
        final int length = children.getLength();

        for (int loop = 0; loop < length; loop++) {
            Node currentNode = children.item(loop);
            if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
                Element currentElement = (Element) currentNode;
                String tagName = currentElement.getTagName();
                if (tagName.equals("param")) {
                    setParameter(currentElement, propSetter, props);
                } else {
                     parseUnrecognizedElement(instance, currentElement, props);
                }
            }
        }
        return instance;
    }
    return null;
}
 
源代码9 项目: cacheonix-core   文件: SMTPAppender.java
/**
   The <b>EvaluatorClass</b> option takes a string value
   representing the name of the class implementing the {@link
   TriggeringEventEvaluator} interface. A corresponding object will
   be instantiated and assigned as the triggering event evaluator
   for the SMTPAppender.
 */
public
void setEvaluatorClass(String value) {
    evaluator = (TriggeringEventEvaluator)
              OptionConverter.instantiateByClassName(value,
			   TriggeringEventEvaluator.class,
				       evaluator);
}
 
源代码10 项目: logging-log4j2   文件: XmlConfiguration.java
/**
 * Creates an object and processes any nested param elements
 * but does not call activateOptions.  If the class also supports
 * UnrecognizedElementParser, the parseUnrecognizedElement method
 * will be call for any child elements other than param.
 *
 * @param element       element, may not be null.
 * @param props         properties
 * @param expectedClass interface or class expected to be implemented
 *                      by created class
 * @return created class or null.
 * @throws Exception thrown if the contain object should be abandoned.
 * @since 1.2.15
 */
public Object parseElement(final Element element, final Properties props,
        @SuppressWarnings("rawtypes") final Class expectedClass) throws Exception {
    String clazz = subst(element.getAttribute("class"), props);
    Object instance = OptionConverter.instantiateByClassName(clazz,
            expectedClass, null);

    if (instance != null) {
        PropertySetter propSetter = new PropertySetter(instance);
        NodeList children = element.getChildNodes();
        final int length = children.getLength();

        for (int loop = 0; loop < length; loop++) {
            Node currentNode = children.item(loop);
            if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
                Element currentElement = (Element) currentNode;
                String tagName = currentElement.getTagName();
                if (tagName.equals("param")) {
                    setParameter(currentElement, propSetter, props);
                } else {
                    parseUnrecognizedElement(instance, currentElement, props);
                }
            }
        }
        return instance;
    }
    return null;
}
 
源代码11 项目: logging-log4j2   文件: XmlConfigurationFactory.java
/**
 * Creates an object and processes any nested param elements
 * but does not call activateOptions.  If the class also supports
 * UnrecognizedElementParser, the parseUnrecognizedElement method
 * will be call for any child elements other than param.
 *
 * @param element       element, may not be null.
 * @param props         properties
 * @param expectedClass interface or class expected to be implemented
 *                      by created class
 * @return created class or null.
 * @throws Exception thrown if the contain object should be abandoned.
 * @since 1.2.15
 */
public static Object parseElement(final Element element, final Properties props,
        @SuppressWarnings("rawtypes") final Class expectedClass) throws Exception {
    String clazz = subst(element.getAttribute("class"), props);
    Object instance = OptionConverter.instantiateByClassName(clazz,
            expectedClass, null);

    if (instance != null) {
        PropertySetter propSetter = new PropertySetter(instance);
        NodeList children = element.getChildNodes();
        final int length = children.getLength();

        for (int loop = 0; loop < length; loop++) {
            Node currentNode = children.item(loop);
            if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
                Element currentElement = (Element) currentNode;
                String tagName = currentElement.getTagName();
                if (tagName.equals("param")) {
                    setParameter(currentElement, propSetter, props);
                } else {
                    parseUnrecognizedElement(instance, currentElement, props);
                }
            }
        }
        return instance;
    }
    return null;
}
 
源代码12 项目: cacheonix-core   文件: DOMConfigurator.java
/**
    Used internally to parse an {@link ErrorHandler} element.
  */
 protected
 void parseErrorHandler(Element element, Appender appender) {
   ErrorHandler eh = (ErrorHandler) OptionConverter.instantiateByClassName(
                                      subst(element.getAttribute(CLASS_ATTR)),
                                      org.apache.log4j.spi.ErrorHandler.class, 
				       null);
   
   if(eh != null) {
     eh.setAppender(appender);

     PropertySetter propSetter = new PropertySetter(eh);
     NodeList children = element.getChildNodes();
     final int length 	= children.getLength();

     for (int loop = 0; loop < length; loop++) {
Node currentNode = children.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
  Element currentElement = (Element) currentNode;
  String tagName = currentElement.getTagName();
  if(tagName.equals(PARAM_TAG)) {
           setParameter(currentElement, propSetter);
  } else if(tagName.equals(APPENDER_REF_TAG)) {
    eh.setBackupAppender(findAppenderByReference(currentElement));
  } else if(tagName.equals(LOGGER_REF)) {
    String loggerName = currentElement.getAttribute(REF_ATTR);	    
    Logger logger = (catFactory == null) ? repository.getLogger(loggerName)
               : repository.getLogger(loggerName, catFactory);
    eh.setLogger(logger);
  } else if(tagName.equals(ROOT_REF)) {
    Logger root = repository.getRootLogger();
    eh.setLogger(root);
  } else {
         quietParseUnrecognizedElement(eh, currentElement, props);
     }
}
     }
     propSetter.activate();
     appender.setErrorHandler(eh);
   }
 }
 
源代码13 项目: olat   文件: IMAppender.java
/**
 * The <b>EvaluatorClass </b> option takes a string value representing the name of the class implementing the {@linkTriggeringEventEvaluator} interface. A
 * corresponding object will be instantiated and assigned as the triggering event evaluator for the SMTPAppender.
 */
public void setEvaluatorClass(final String value) {
    evaluator = (TriggeringEventEvaluator) OptionConverter.instantiateByClassName(value, TriggeringEventEvaluator.class, evaluator);
}
 
源代码14 项目: olat   文件: IMAppender.java
/**
 * The <b>EvaluatorClass </b> option takes a string value representing the name of the class implementing the {@linkTriggeringEventEvaluator} interface. A
 * corresponding object will be instantiated and assigned as the triggering event evaluator for the SMTPAppender.
 */
public void setEvaluatorClass(final String value) {
    evaluator = (TriggeringEventEvaluator) OptionConverter.instantiateByClassName(value, TriggeringEventEvaluator.class, evaluator);
}