@Override public void end(InterpretationContext ic, String name) throws ActionException { if(!weAreActive(ic)) return; ThenActionState state = stateStack.pop(); if (state.isRegistered) { ic.removeInPlayListener(state); Object o = ic.peekObject(); if (o instanceof IfAction) { IfAction ifAction = (IfAction) o; removeFirstAndLastFromList(state.eventList); registerEventList(ifAction, state.eventList); } else { throw new IllegalStateException("Missing IfAction on top of stack"); } } }
/** * 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); } }
@Override public void end(InterpretationContext ec, String name) throws ActionException { if (inError) { return; } Object o = ec.peekObject(); if (o != context) { addWarn( "The object at the of the stack is not the context named [" + context.getName() + "] pushed earlier."); } else { addInfo( "Popping context named [" + context.getName() + "] from the object stack"); 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"); } }
@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(); } }
@Override public void end(InterpretationContext ec, String name) throws ActionException { if (inError) { return; } Object o = ec.peekObject(); if (o != lcl) { addWarn("The object on the top the of the stack is not the LoggerContextListener pushed earlier."); } else { if (lcl instanceof LifeCycle) { ((LifeCycle) lcl).start(); addInfo("Starting LoggerContextListener"); } ((LoggerContext) context).addListener(lcl); ec.popObject(); } }
@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); }
@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); } }
@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); }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { SaxEventRecorder recorder = new SaxEventRecorder(context); this.attributeInUse = null; this.optional = OptionHelper.toBoolean(attributes.getValue(OPTIONAL_ATTR), false); if (!checkAttributes(attributes)) { return; } InputStream in = getInputStream(ec, attributes); try { if (in != null) { parseAndRecord(in, recorder); // remove the <included> tag from the beginning and </included> from the end trimHeadAndTail(recorder); // offset = 2, because we need to get past this element as well as the end element ec.getJoranInterpreter().getEventPlayer().addEventsDynamically(recorder.saxEventList, 2); } } catch (JoranException e) { addError("Error while parsing " + attributeInUse, e); } finally { close(in); } }
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); } }
/** * 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); } }
@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); }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { inError = false; try { ec.pushObject(context); } catch (Exception oops) { inError = true; addError( "Could not push context", oops); throw new ActionException(oops); } }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { // We are just beginning, reset variables fruitShell = new FruitShell(); inError = false; try { fruitShell.setContext(context); String shellName = attributes.getValue(NAME_ATTRIBUTE); if (OptionHelper.isEmpty(shellName)) { addWarn( "No appender name given for fruitShell]."); } else { fruitShell.setName(shellName); addInfo("FruitShell named as [" + shellName + "]"); } ec.pushObject(fruitShell); } catch (Exception oops) { inError = true; addError( "Could not create an FruitShell", oops); throw new ActionException(oops); } }
@Override public void end(InterpretationContext ec, String name) throws ActionException { ec.removeInPlayListener(this); Object o = ec.peekObject(); if(o instanceof FruitShell) { FruitShell fs = (FruitShell) o; FruitFactory fruitFactory = new FruitFactory(); fruitFactory.setEventList(new ArrayList<SaxEvent>(seList)); fs.setFruitFactory(fruitFactory); } }
/** * Instantiates an layout of the given class and sets its name. * */ public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { //System.out.println("IncAction Begin called"); beginCount++; String val = attributes.getValue("increment"); if(!"1".equals(val)) { errorCount++; throw new ActionException(); } }
public void end(InterpretationContext ec, String name) throws ActionException { switch(type) { case ACTION_EXCEPTION: throw new ActionException(); default: throw new IllegalStateException("bad end"); } }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { String portStr = attributes.getValue(PORT_ATTR); Integer port = null; if (portStr == null) { port = DEFAULT_PORT; } else { try { port = Integer.valueOf(portStr); } catch (NumberFormatException ex) { addError("Port " + portStr + " in ConsolePlugin config is not a correct number"); } } LoggerContext lc = (LoggerContext)ec.getContext(); SocketAppender appender = new SocketAppender(); appender.setContext(lc); appender.setIncludeCallerData(true); appender.setRemoteHost("localhost"); appender.setPort(port.intValue()); appender.start(); Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME); root.addAppender(appender); addInfo("Sending LoggingEvents to the plugin using port " + port); }
@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); } }
@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 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); } }
@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); } }
@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)); if (OptionHelper.isEmpty(name) || OptionHelper.isEmpty(source)) { addError( "The \"name\" and \"source\" attributes of <springProperty> must be set"); } ActionUtil.setProperty(ic, name, getValue(source), scope); }
/** {@inheritDoc} */ @Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { depth++; if (depth != 1) { return; } String profiles = OptionHelper.substVars(attributes.getValue(NAME_ATTRIBUTE), ic, context); String[] normalizedProfiles = StringUtils.commaDelimitedListToStringArray(profiles); normalizedProfiles = StringUtils.trimArrayElements(normalizedProfiles); accepts = normalizedProfiles.length > 0 && environment.acceptsProfiles(normalizedProfiles); ic.addInPlayListener(this); }
/** {@inheritDoc} */ @Override public void end(InterpretationContext ic, String name) throws ActionException { depth--; if (depth != 0) { return; } ic.removeInPlayListener(this); if (accepts) { events.remove(0); events.remove(events.size() - 1); ic.getJoranInterpreter().getEventPlayer().addEventsDynamically(events, 1); } events.clear(); }
/** {@inheritDoc} */ @Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { String key = attributes.getValue(NAME_ATTRIBUTE); Scope scope = ActionUtil.stringToScope(attributes.getValue(SCOPE_ATTRIBUTE)); String source = attributes.getValue("source"); String defaultValue = attributes.getValue("defaultValue"); String value = environment.getProperty(source, defaultValue); ActionUtil.setProperty(ic, key, value, scope); }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { final String loggerName = attributes.getValue(NAME_ATR); // If we don't have a logger name then we can't do anything if(loggerName == null) return; // If that logger doesn't exist yet then we have no reason to configure it if(!containsByName(lc.getLoggerList(), loggerName)) return; final Logger logger = lc.getLogger(loggerName); // Set the logger's level final String levelStr = attributes.getValue(LEVEL_ATR); if(levelStr != null) { logger.setLevel(Level.toLevel(levelStr, null)); } // Attach the appropriate appenders only if those appenders have been created // by Joran from the logback config file final String[] appenderNames = attributes.getValue(APPENDER_ATR).split(" "); if (appenderNames != null) { logger.detachAndStopAllAppenders(); for(int i=0; i<appenderNames.length; i++) { //TODO: This will have to be made to work with a content provider // final Appender<ILoggingEvent> appender = findMatchingAppender( // AppenderStore.getInstance().getAppenders(), appenderNames[i]); // if (appender != null) // logger.addAppender(appender); } } // Set the logger's additivity final String additivityStr = attributes.getValue(ADDITIVITY_ATR); if(additivityStr != null) logger.setAdditive(Boolean.valueOf(additivityStr)); }
@Override public void end(InterpretationContext ic, String name) throws ActionException { }
@Override public void end(InterpretationContext ic, String name) throws ActionException { IfState state = stack.pop(); if(!state.active) { return; } Object o = ic.peekObject(); if (o == null) { throw new IllegalStateException("Unexpected null object on stack"); } if (!(o instanceof IfAction)) { throw new IllegalStateException("Unexpected object of type [" + o.getClass() + "] on stack"); } if (o != this) { throw new IllegalStateException( "IfAction different then current one on stack"); } ic.popObject(); if (state.boolResult == null) { addError("Failed to determine \"if then else\" result"); return; } Interpreter interpreter = ic.getJoranInterpreter(); List<SaxEvent> listToPlay = state.thenSaxEventList; if (!state.boolResult) { listToPlay = state.elseSaxEventList; } // if boolResult==false & missing else, listToPlay may be null if(listToPlay != null) { // insert past this event interpreter.getEventPlayer().addEventsDynamically(listToPlay, 1); } }
public abstract void end(InterpretationContext ic, String name) throws ActionException;