@Override public void begin(InterpretationContext ec, String name, Attributes attributes) { // See LBCLASSIC-225 (the system property is looked up first. Thus, it overrides // the equivalent property in the config file. This reversal of scope priority is justified // by the use case: the admin trying to chase rogue config file String debugAttrib = System.getProperty(DEBUG_SYSTEM_PROPERTY_KEY); if (debugAttrib == null) { debugAttrib = attributes.getValue(INTERNAL_DEBUG_ATTR); } if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equals("false") || debugAttrib.equals("null")) { addInfo(INTERNAL_DEBUG_ATTR + " attribute not set"); } else { OnConsoleStatusListener.addNewInstanceToContext(context); } new ContextUtil(context).addHostNameAsProperty(); // the context is appender attachable, so it is pushed on top of the stack ec.pushObject(getContext()); }
URL getInputURL(InterpretationContext ec, Attributes attributes) { String fileAttribute = attributes.getValue(FILE_ATTR); String urlAttribute = attributes.getValue(URL_ATTR); String resourceAttribute = attributes.getValue(RESOURCE_ATTR); if (!OptionHelper.isEmpty(fileAttribute)) { this.attributeInUse = ec.subst(fileAttribute); return filePathAsURL(attributeInUse); } if (!OptionHelper.isEmpty(urlAttribute)) { this.attributeInUse = ec.subst(urlAttribute); return attributeToURL(attributeInUse); } if (!OptionHelper.isEmpty(resourceAttribute)) { this.attributeInUse = ec.subst(resourceAttribute); return resourceAsURL(attributeInUse); } // given previous checkAttributes() check we cannot reach this line throw new IllegalStateException("A URL stream should have been returned"); }
/** * Once the children elements are also parsed, now is the time to activate the * shutdown hook options. */ @Override public void end(InterpretationContext ic, String name) throws ActionException { if (inError) { return; } Object o = ic.peekObject(); if (o != hook) { addWarn("The object at the of the stack is not the hook pushed earlier."); } else { ic.popObject(); Thread hookThread = new Thread(hook, "Logback shutdown hook [" + context.getName() + "]"); context.putObject(CoreConstants.SHUTDOWN_HOOK_THREAD, hookThread); Runtime.getRuntime().addShutdownHook(hookThread); } }
/** * Now property definer is initialized by all properties and we can put * property value to context */ public void end(InterpretationContext ec, String name) { if (inError) { return; } Object o = ec.peekObject(); if (o != definer) { addWarn("The object at the of the stack is not the property definer for property named [" + propertyName + "] pushed earlier."); } else { addInfo("Popping property definer for property named [" + propertyName + "] from the object stack"); ec.popObject(); // let's put defined property and value to context but only if it is // not null String propertyValue = definer.getPropertyValue(); if(propertyValue != null) { ActionUtil.setProperty(ec, propertyName, propertyValue, scope); } } }
/** * Once the children elements are also parsed, now is the time to activate the * appender options. */ public void end(InterpretationContext ec, String name) { if (inError) { return; } if (appender instanceof LifeCycle) { ((LifeCycle) appender).start(); } Object o = ec.peekObject(); if (o != appender) { addWarn("The object at the of the stack is not the appender named [" + appender.getName() + "] pushed earlier."); } else { ec.popObject(); } }
@Override public void end(InterpretationContext ec, String name) throws ActionException { if (inError) { return; } Object o = ec.peekObject(); if (o != fruitShell) { addWarn( "The object at the of the stack is not the fruitShell named [" + fruitShell.getName() + "] pushed earlier."); } else { addInfo( "Popping fruitSHell named [" + fruitShell.getName() + "] from the object stack"); ec.popObject(); FruitContext fruitContext = (FruitContext) ec.getContext(); fruitContext.addFruitShell(fruitShell); } }
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { String exType = attributes.getValue(EXCEPTION_TYPE); type = RUNTIME_EDXCEPTION; if("ActionException".equals(exType)) { type = ACTION_EXCEPTION; } switch(type) { case ACTION_EXCEPTION: throw new ActionException(); default: throw new IllegalStateException("bad begin"); } }
/** * Pop the Integer object at the top of the stack. This code illustrates usage * of Joran's error handling paradigm. */ int fetchInteger(InterpretationContext ic) { int result = 0; try { Object o1 = ic.popObject(); if (o1 instanceof Integer) { result = ((Integer) o1).intValue(); } else { String errMsg = "Object [" + o1 + "] currently at the top of the stack is not an integer."; ic.addError(errMsg); throw new IllegalArgumentException(errMsg); } } catch (EmptyStackException ese) { ic.addError("Expecting an integer on the execution stack."); throw ese; } return result; }
public void begin(InterpretationContext ic, String name, Attributes attributes) { String valueStr = attributes.getValue(VALUE_ATR); if (OptionHelper.isEmpty(valueStr)) { ic.addError("The literal action requires a value attribute"); return; } try { Integer i = Integer.valueOf(valueStr); ic.pushObject(i); } catch (NumberFormatException nfe) { ic.addError("The value [" + valueStr + "] could not be converted to an Integer", nfe); throw nfe; } }
/** * Pop the Integer object at the top of the stack. * This code also illustrates usage of Joran's error handling paradigm. */ int fetchInteger(InterpretationContext ic) { int result = 0; try { // Pop the object at the top of the interpretation context's stack. Object o1 = ic.popObject(); if (o1 instanceof Integer) { result = ((Integer) o1).intValue(); } else { String errMsg = "Object [" + o1 + "] currently at the top of the stack is not an integer."; ic.addError(errMsg); throw new IllegalArgumentException(errMsg); } } catch (EmptyStackException ese) { ic.addError(("Expecting an integer on the execution stack.")); throw ese; } return result; }
public void begin(InterpretationContext ec, String name, Attributes attributes) { Object o = ec.peekObject(); if (!(o instanceof Logger)) { inError = true; addError("For element <level>, could not find a logger at the top of execution stack."); return; } Logger l = (Logger) o; String loggerName = l.getName(); String levelStr = ec.subst(attributes.getValue(ActionConst.VALUE_ATTR)); //addInfo("Encapsulating logger name is [" + loggerName // + "], level value is [" + levelStr + "]."); if (ActionConst.INHERITED.equalsIgnoreCase(levelStr) || ActionConst.NULL.equalsIgnoreCase(levelStr)) { l.setLevel(null); } else { l.setLevel(Level.toLevel(levelStr, Level.DEBUG)); } addInfo(loggerName + " level set to " + l.getLevel()); }
@Override public void end(InterpretationContext ic, String name) throws ActionException { if (inError) return; ic.getContext().register(receiver); receiver.start(); Object o = ic.peekObject(); if (o != receiver) { addWarn("The object at the of the stack is not the remote " + "pushed earlier."); } else { ic.popObject(); } }
void processScanAttrib(InterpretationContext ic, Attributes attributes) { String scanAttrib = ic.subst(attributes.getValue(SCAN_ATTR)); if (!OptionHelper.isEmpty(scanAttrib) && !"false".equalsIgnoreCase(scanAttrib)) { ReconfigureOnChangeFilter rocf = new ReconfigureOnChangeFilter(); rocf.setContext(context); String scanPeriodAttrib = ic.subst(attributes.getValue(SCAN_PERIOD_ATTR)); if (!OptionHelper.isEmpty(scanPeriodAttrib)) { try { Duration duration = Duration.valueOf(scanPeriodAttrib); rocf.setRefreshPeriod(duration.getMilliseconds()); addInfo("Setting ReconfigureOnChangeFilter scanning period to " + duration); } catch (NumberFormatException nfe) { addError("Error while converting [" + scanAttrib + "] to long", nfe); } } rocf.start(); LoggerContext lc = (LoggerContext) context; addInfo("Adding ReconfigureOnChangeFilter as a turbo filter"); lc.addTurboFilter(rocf); } }
@Override public void begin(InterpretationContext ic, String elementName, Attributes attributes) throws ActionException { String name = attributes.getValue(NAME_ATTRIBUTE); String source = attributes.getValue(SOURCE_ATTRIBUTE); Scope scope = ActionUtil.stringToScope(attributes.getValue(SCOPE_ATTRIBUTE)); String defaultValue = attributes.getValue(DEFAULT_VALUE_ATTRIBUTE); if (OptionHelper.isEmpty(name) || OptionHelper.isEmpty(source)) { addError( "The \"name\" and \"source\" attributes of <springProperty> must be set"); } ActionUtil.setProperty(ic, name, getValue(source, defaultValue), scope); }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { this.depth++; if (this.depth != 1) { return; } ic.pushObject(this); this.acceptsProfile = acceptsProfiles(ic, attributes); this.events = new ArrayList<SaxEvent>(); ic.addInPlayListener(this); }
private boolean acceptsProfiles(InterpretationContext ic, Attributes attributes) { String[] profileNames = StringUtils.trimArrayElements(StringUtils .commaDelimitedListToStringArray(attributes.getValue(NAME_ATTRIBUTE))); if (profileNames.length != 0) { for (String profileName : profileNames) { OptionHelper.substVars(profileName, ic, this.context); } return this.environment != null && this.environment.acceptsProfiles(profileNames); } return false; }
@Override public void end(InterpretationContext ic, String name) throws ActionException { this.depth--; if (this.depth != 0) { return; } ic.removeInPlayListener(this); verifyAndPop(ic); if (this.acceptsProfile) { addEventsToPlayer(ic); } }
private void verifyAndPop(InterpretationContext ic) { Object o = ic.peekObject(); Assert.state(o != null, "Unexpected null object on stack"); Assert.isInstanceOf(SpringProfileAction.class, o, "logback stack error"); Assert.state(o == this, "ProfileAction different than current one on stack"); ic.popObject(); }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { IfState state = new IfState(); boolean emptyStack = stack.isEmpty(); stack.push(state); if(!emptyStack) { return; } ic.pushObject(this); if(!EnvUtil.isJaninoAvailable()) { addError(MISSING_JANINO_MSG); addError(MISSING_JANINO_SEE); return; } state.active = true; Condition condition = null; String conditionAttribute = attributes.getValue(CONDITION_ATTR); if (!OptionHelper.isEmpty(conditionAttribute)) { conditionAttribute = OptionHelper.substVars(conditionAttribute, ic, context); PropertyEvalScriptBuilder pesb = new PropertyEvalScriptBuilder(ic); pesb.setContext(context); try { condition = pesb.build(conditionAttribute); } catch (Exception e) { addError("Failed to parse condition ["+conditionAttribute+"]", e); } if(condition!=null) { state.boolResult = condition.evaluate(); } } }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { if(!weAreActive(ic)) return; ThenActionState state = new ThenActionState(); if (ic.isListenerListEmpty()) { ic.addInPlayListener(state); state.isRegistered = true; } stateStack.push(state); }
/** * Once the children elements are also parsed, now is the time to activate the * evaluator options. */ @SuppressWarnings("unchecked") public void end(InterpretationContext ec, String e) { if (inError) { return; } if (evaluator instanceof LifeCycle) { ((LifeCycle) evaluator).start(); addInfo("Starting evaluator named [" + evaluator.getName() + "]"); } Object o = ec.peekObject(); if (o != evaluator) { addWarn("The object on the top the of the stack is not the evaluator pushed earlier."); } else { ec.popObject(); try { Map<String, EventEvaluator<?>> evaluatorMap = (Map<String, EventEvaluator<?>>) context .getObject(CoreConstants.EVALUATOR_MAP); if(evaluatorMap == null) { addError("Could not find EvaluatorMap"); } else { evaluatorMap.put(evaluator.getName(), evaluator); } } catch (Exception ex) { addError("Could not set evaluator named [" + evaluator + "].", ex); } } }
@Override public void end(InterpretationContext ic, String name) throws ActionException { ic.removeInPlayListener(this); Object o = ic.peekObject(); if (o instanceof SiftingAppender) { SiftingAppender siftingAppender = (SiftingAppender) o; Map<String, String> propertyMap = ic.getCopyOfPropertyMap(); AppenderFactoryUsingJoran appenderFactory = new AppenderFactoryUsingJoran(seList, siftingAppender.getDiscriminatorKey(), propertyMap); siftingAppender.setAppenderFactory(appenderFactory); } }
protected int getLineNumber(InterpretationContext ic) { Interpreter ji = ic.getJoranInterpreter(); Locator locator = ji.getLocator(); if (locator != null) { return locator.getLineNumber(); } return -1; }
InputStream getInputStream(InterpretationContext ec, Attributes attributes) { URL inputURL = getInputURL(ec, attributes); if (inputURL == null) return null; ConfigurationWatchListUtil.addToWatchList(context, inputURL); return openURL(inputURL); }
public void begin( InterpretationContext ec, String localName, Attributes attributes) { String name = attributes.getValue(NAME_ATTRIBUTE); String value = attributes.getValue(VALUE_ATTRIBUTE); if (name == null) { inError = true; addError(NO_NAME); return; } if (value == null) { inError = true; addError(NO_VALUE); return; } // remove both leading and trailing spaces value = value.trim(); Object o = ec.peekObject(); PropertySetter propSetter = new PropertySetter(o); propSetter.setContext(context); value = ec.subst(value); // allow for variable substitution for name as well name = ec.subst(name); //getLogger().debug( // "In ParamAction setting parameter [{}] to value [{}].", name, value); propSetter.setProperty(name, value); }
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); } }
public void end(InterpretationContext ec, String e) { if (inError) { return; } if (statusListener instanceof LifeCycle) { ((LifeCycle) statusListener).start(); } Object o = ec.peekObject(); if (o != statusListener) { addWarn("The object at the of the stack is not the statusListener pushed earlier."); } else { ec.popObject(); } }
/** * Instantiates a shutdown hook of the given class and sets its name. * * The hook thus generated is placed in the {@link InterpretationContext}'s * shutdown hook bag. */ @Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { hook = null; inError = false; String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Missing class name for shutdown hook. Near [" + name + "] line " + getLineNumber(ic)); inError = true; return; } try { addInfo("About to instantiate shutdown hook of type [" + className + "]"); hook = (ShutdownHookBase) OptionHelper.instantiateByClassName(className, ShutdownHookBase.class, context); hook.setContext(context); ic.pushObject(hook); }catch (Exception e) { inError = true; addError("Could not create a shutdown hook of type [" + className + "].", e); throw new ActionException(e); } }
void loadAndSetProperties(InterpretationContext ec, InputStream istream, Scope scope) throws IOException { Properties props = new Properties(); props.load(istream); istream.close(); ActionUtil.setProperties(ec, props, scope); }
@Override public void end(InterpretationContext ic, String name) throws ActionException { ic.removeInPlayListener(this); Object o = ic.peekObject(); if (o instanceof SiftingAppender) { SiftingAppender sa = (SiftingAppender) o; Map<String, String> propertyMap = ic.getCopyOfPropertyMap(); AppenderFactoryUsingJoran appenderFactory = new AppenderFactoryUsingJoran(seList, sa .getDiscriminatorKey(), propertyMap); sa.setAppenderFactory(appenderFactory); } }
private boolean acceptsProfiles(InterpretationContext ic, Attributes attributes) { String[] profileNames = StringUtils .commaDelimitedListToStringArray(attributes.getValue(NAME_ATTRIBUTE)); if (profileNames.length != 0) { for (String profileName : profileNames) { OptionHelper.substVars(profileName, ic, this.context); } return this.environment != null && this.environment.acceptsProfiles(profileNames); } return false; }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { String keyStr = attributes.getValue(KEY_ATTRIBUTE); if (OptionHelper.isEmpty(keyStr)) { addError("Attribute named [" + KEY_ATTRIBUTE + "] cannot be empty"); inError = true; } String datePatternStr = attributes.getValue(DATE_PATTERN_ATTRIBUTE); if (OptionHelper.isEmpty(datePatternStr)) { addError("Attribute named [" + DATE_PATTERN_ATTRIBUTE + "] cannot be empty"); inError = true; } String timeReferenceStr = attributes.getValue(TIME_REFERENCE_ATTRIBUTE); long timeReference; if (CONTEXT_BIRTH.equalsIgnoreCase(timeReferenceStr)) { addInfo("Using context birth as time reference."); timeReference = context.getBirthTime(); } else { timeReference = System.currentTimeMillis(); addInfo("Using current interpretation time, i.e. now, as time reference."); } if (inError) return; String scopeStr = attributes.getValue(SCOPE_ATTRIBUTE); Scope scope = ActionUtil.stringToScope(scopeStr); CachingDateFormatter sdf = new CachingDateFormatter(datePatternStr); String val = sdf.format(timeReference); addInfo("Adding property to the context with key=\"" + keyStr + "\" and value=\"" + val + "\" to the " + scope + " scope"); ActionUtil.setProperty(ec, keyStr, val, scope); }
static public void setProperty(InterpretationContext ic, String key, String value, Scope scope) { switch (scope) { case LOCAL: ic.addSubstitutionProperty(key, value); break; case CONTEXT: ic.getContext().putProperty(key, value); break; case SYSTEM: OptionHelper.setSystemProperty(ic, key, value); } }
/** * Add all the properties found in the argument named 'props' to an * InterpretationContext. */ static public void setProperties(InterpretationContext ic, Properties props, Scope scope) { switch (scope) { case LOCAL: ic.addSubstitutionProperties(props); break; case CONTEXT: ContextUtil cu = new ContextUtil(ic.getContext()); cu.addProperties(props); break; case SYSTEM: OptionHelper.setSystemProperties(ic, props); } }
/** * Instantiates an layout of the given class and sets its name. */ public void begin(InterpretationContext ec, String localName, Attributes attributes) { // Let us forget about previous errors (in this object) inError = false; String errorMsg; String pattern = attributes.getValue(Action.PATTERN_ATTRIBUTE); String actionClass = attributes.getValue(Action.ACTION_CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(pattern)) { inError = true; errorMsg = "No 'pattern' attribute in <newRule>"; addError(errorMsg); return; } if (OptionHelper.isEmpty(actionClass)) { inError = true; errorMsg = "No 'actionClass' attribute in <newRule>"; addError(errorMsg); return; } try { addInfo("About to add new Joran parsing rule [" + pattern + "," + actionClass + "]."); ec.getJoranInterpreter().getRuleStore().addRule(new ElementSelector(pattern), actionClass); } catch (Exception oops) { inError = true; errorMsg = "Could not add new Joran parsing rule [" + pattern + "," + actionClass + "]"; addError(errorMsg); } }