@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { inError = false; String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Mandatory \"" + CLASS_ATTRIBUTE + "\" attribute not set for <loggerContextListener> element"); inError = true; return; } try { lcl = (LoggerContextListener) OptionHelper.instantiateByClassName(className, LoggerContextListener.class, context); if (lcl instanceof ContextAware) { ((ContextAware) lcl).setContext(context); } ec.pushObject(lcl); addInfo("Adding LoggerContextListener of type [" + className + "] to the object stack"); } catch (Exception oops) { inError = true; addError("Could not create LoggerContextListener of type " + className + "].", oops); } }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Missing class name for receiver. Near [" + name + "] line " + getLineNumber(ic)); inError = true; return; } try { addInfo("About to instantiate receiver of type [" + className + "]"); receiver = (ReceiverBase) OptionHelper.instantiateByClassName(className, ReceiverBase.class, context); receiver.setContext(context); ic.pushObject(receiver); } catch (Exception ex) { inError = true; addError("Could not create a receiver of type [" + className + "].", ex); throw new ActionException(ex); } }
private static StatusListener createListenerPerClassName(LoggerContext loggerContext, String listenerClass) { try { return (StatusListener) OptionHelper.instantiateByClassName( listenerClass, StatusListener.class, loggerContext); } catch (Exception e) { // printing on the console is the best we can do e.printStackTrace(); return null; } } }
public static Object instantiateByClassName(String className, Class<?> superClass, Context context) throws IncompatibleClassException, DynamicClassLoadingException { ClassLoader classLoader = Loader.getClassLoaderOfObject(context); return instantiateByClassName(className, superClass, classLoader); }
public void addRule(ElementSelector elementSelector, String actionClassName) { Action action = null; try { action = (Action) OptionHelper.instantiateByClassName(actionClassName, Action.class, context); } catch (Exception e) { addError("Could not instantiate class [" + actionClassName + "]", e); } if (action != null) { addRule(elementSelector, action); } }
/** * Attempt to create a converter using the information found in * 'converterMap'. * * @param kn * @return */ @SuppressWarnings("unchecked") DynamicConverter<E> createConverter(SimpleKeywordNode kn) { String keyword = (String) kn.getValue(); String converterClassStr = (String) converterMap.get(keyword); if (converterClassStr != null) { try { return (DynamicConverter) OptionHelper.instantiateByClassName( converterClassStr, DynamicConverter.class, context); } catch (Exception e) { addError("Failed to instantiate converter class [" + converterClassStr + "] for keyword ["+keyword+"]", e); return null; } } else { addError("There is no conversion class registered for conversion word [" + keyword + "]"); return null; } }
/** * Attempt to create a converter using the information found in * 'compositeConverterMap'. * * @param cn * @return */ @SuppressWarnings("unchecked") CompositeConverter<E> createCompositeConverter(CompositeNode cn) { String keyword = (String) cn.getValue(); String converterClassStr = (String) converterMap.get(keyword); if (converterClassStr != null) { try { return (CompositeConverter) OptionHelper.instantiateByClassName( converterClassStr, CompositeConverter.class, context); } catch (Exception e) { addError("Failed to instantiate converter class [" + converterClassStr + "] as a composite converter for keyword ["+keyword+"]", e); return null; } } else { addError("There is no conversion class registered for composite conversion word [" + keyword + "]"); return null; } }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { inError = false; String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Mandatory \"" + CLASS_ATTRIBUTE + "\" attribute not set for <loggerContextListener> element"); inError = true; return; } try { lcl = (LoggerContextListener) OptionHelper.instantiateByClassName( className, LoggerContextListener.class, context); if(lcl instanceof ContextAware) { ((ContextAware) lcl).setContext(context); } ec.pushObject(lcl); addInfo("Adding LoggerContextListener of type [" + className + "] to the object stack"); } catch (Exception oops) { inError = true; addError("Could not create LoggerContextListener of type " + className + "].", oops); } }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Missing class name for receiver. Near [" + name + "] line " + getLineNumber(ic)); inError = true; return; } try { addInfo("About to instantiate receiver of type [" + className + "]"); receiver = (ReceiverBase) OptionHelper.instantiateByClassName( className, ReceiverBase.class, context); receiver.setContext(context); ic.pushObject(receiver); } catch (Exception ex) { inError = true; addError("Could not create a receiver of type [" + className + "].", ex); throw new ActionException(ex); } }
addInfo("About to instantiate appender of type [" + className + "]"); appender = (Appender<E>) OptionHelper.instantiateByClassName(className, ch.qos.logback.core.Appender.class, context);
addInfo("About to instantiate property definer of type [" + className + "]"); definer = (PropertyDefiner) OptionHelper.instantiateByClassName( className, PropertyDefiner.class, context); definer.setContext(context);
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { inError = false; String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Missing class name for statusListener. Near [" + name + "] line " + getLineNumber(ec)); inError = true; return; } try { statusListener = (StatusListener) OptionHelper.instantiateByClassName( className, StatusListener.class, context); ec.getContext().getStatusManager().add(statusListener); if (statusListener instanceof ContextAware) { ((ContextAware) statusListener).setContext(context); } addInfo("Added status listener of type [" + className + "]"); ec.pushObject(statusListener); } catch (Exception e) { inError = true; addError( "Could not create an StatusListener of type [" + className + "].", e); throw new ActionException(e); } }
evaluator = (EventEvaluator<?>) OptionHelper.instantiateByClassName( className, ch.qos.logback.core.boolex.EventEvaluator.class, context);
(DataSource) OptionHelper.instantiateByClassName(dsClassName, DataSource.class, context);
public static Object instantiateByClassName(String className, Class<?> superClass, Context context) throws IncompatibleClassException, DynamicClassLoadingException { ClassLoader classLoader = Loader.getClassLoaderOfObject(context); return instantiateByClassName(className, superClass, classLoader); }
public void addRule(ElementSelector elementSelector, String actionClassName) { Action action = null; try { action = (Action) OptionHelper.instantiateByClassName(actionClassName, Action.class, context); } catch (Exception e) { addError("Could not instantiate class [" + actionClassName + "]", e); } if (action != null) { addRule(elementSelector, action); } }
public void addRule(Pattern pattern, String actionClassName) { Action action = null; try { action = (Action) OptionHelper.instantiateByClassName(actionClassName, Action.class, context); } catch (Exception e) { addError("Could not instantiate class [" + actionClassName + "]", e); } if (action != null) { addRule(pattern, action); } }
public void addRule(ElementSelector elementSelector, String actionClassName) { Action action = null; try { action = (Action) OptionHelper.instantiateByClassName(actionClassName, Action.class, context); } catch (Exception e) { addError("Could not instantiate class [" + actionClassName + "]", e); } if (action != null) { addRule(elementSelector, action); } }
public void addRule(ElementSelector elementSelector, String actionClassName) { Action action = null; try { action = (Action) OptionHelper.instantiateByClassName(actionClassName, Action.class, context); } catch (Exception e) { addError("Could not instantiate class [" + actionClassName + "]", e); } if (action != null) { addRule(elementSelector, action); } }
public void addRule(Pattern pattern, String actionClassName) { Action action = null; try { action = (Action) OptionHelper.instantiateByClassName(actionClassName, Action.class, context); } catch (Exception e) { addError("Could not instantiate class [" + actionClassName + "]", e); } if (action != null) { addRule(pattern, action); } }