Skip to content

Commit

Permalink
ongoing work on model based configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Mar 5, 2019
1 parent 70357e9 commit eaafcc8
Show file tree
Hide file tree
Showing 39 changed files with 623 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected void addDefaultNestedComponentRegistryRules(DefaultNestedComponentRegi
@Override
protected DefaultProcessor buildDefaultProcessor(Context context, InterpretationContext interpretationContext) {
DefaultProcessor defaultProcessor = super.buildDefaultProcessor(context, interpretationContext);
defaultProcessor.addHandler(ConfigurationModel.class, ConfigurationModelHandler.class);
defaultProcessor.addHandler(ConfigurationModel.class, new ConfigurationModelHandler(context));
return defaultProcessor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void begin(InterpretationContext interpretationContext, String name, Attr
configurationModel.setScanPeriodStr(attributes.getValue(SCAN_PERIOD_ATTR));
configurationModel.setPackagingDataStr(attributes.getValue(PACKAGING_DATA_ATTR));

interpretationContext.pushObject(configurationModel);
interpretationContext.pushModel(configurationModel);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ch.qos.logback.classic.joran.ReconfigureOnChangeTask;
import ch.qos.logback.classic.model.ConfigurationModel;
import ch.qos.logback.classic.util.EnvUtil;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.joran.util.ConfigurationWatchListUtil;
Expand All @@ -25,7 +26,7 @@ public class ConfigurationModelHandler extends ModelHandlerBase {
static final String DEBUG_SYSTEM_PROPERTY_KEY = "logback.debug";
static final Duration SCAN_PERIOD_DEFAULT = Duration.buildByMinutes(1);

ConfigurationModelHandler(LoggerContext context) {
public ConfigurationModelHandler(Context context) {
super(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,7 @@
*/
package ch.qos.logback.core.joran;

import ch.qos.logback.core.Context;
import ch.qos.logback.core.joran.event.SaxEvent;
import ch.qos.logback.core.joran.event.SaxEventRecorder;
import ch.qos.logback.core.joran.spi.*;
import ch.qos.logback.core.joran.util.ConfigurationWatchListUtil;
import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;
import ch.qos.logback.core.model.PropertyModel;
import ch.qos.logback.core.model.ShutdownHookModel;
import ch.qos.logback.core.model.TimestampModel;
import ch.qos.logback.core.model.processor.DefaultProcessor;
import ch.qos.logback.core.model.processor.PropertyModelHandler;
import ch.qos.logback.core.model.processor.ShutdownHookModelHandler;
import ch.qos.logback.core.model.processor.TimestampModelHandler;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.status.StatusUtil;

import org.xml.sax.InputSource;
import static ch.qos.logback.core.CoreConstants.SAFE_JORAN_CONFIGURATION;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -39,7 +23,23 @@
import java.net.URLConnection;
import java.util.List;

import static ch.qos.logback.core.CoreConstants.SAFE_JORAN_CONFIGURATION;
import org.xml.sax.InputSource;

import ch.qos.logback.core.Context;
import ch.qos.logback.core.joran.event.SaxEvent;
import ch.qos.logback.core.joran.event.SaxEventRecorder;
import ch.qos.logback.core.joran.spi.DefaultNestedComponentRegistry;
import ch.qos.logback.core.joran.spi.ElementPath;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.joran.spi.Interpreter;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.joran.spi.RuleStore;
import ch.qos.logback.core.joran.spi.SimpleRuleStore;
import ch.qos.logback.core.joran.util.ConfigurationWatchListUtil;
import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;
import ch.qos.logback.core.model.processor.DefaultProcessor;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.status.StatusUtil;

public abstract class GenericConfigurator extends ContextAwareBase {

Expand Down Expand Up @@ -177,10 +177,6 @@ public void doConfigure(final List<SaxEvent> eventList) throws JoranException {

protected DefaultProcessor buildDefaultProcessor(Context context, InterpretationContext interpretationContext) {
DefaultProcessor defaultProcessor = new DefaultProcessor(context, interpreter.getInterpretationContext());
defaultProcessor.addHandler(ShutdownHookModel.class, ShutdownHookModelHandler.class);
defaultProcessor.addHandler(PropertyModel.class, PropertyModelHandler.class);
defaultProcessor.addHandler(TimestampModel.class, TimestampModelHandler.class);

return defaultProcessor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import ch.qos.logback.core.joran.action.ContextPropertyAction;
import ch.qos.logback.core.joran.action.ConversionRuleAction;
import ch.qos.logback.core.joran.action.DefinePropertyAction;
import ch.qos.logback.core.joran.action.ModelImplicitAction;
import ch.qos.logback.core.joran.action.NestedBasicPropertyIA;
import ch.qos.logback.core.joran.action.NestedComplexPropertyIA;
import ch.qos.logback.core.joran.action.ImplicitModelAction;
import ch.qos.logback.core.joran.action.NewRuleAction;
import ch.qos.logback.core.joran.action.ParamAction;
import ch.qos.logback.core.joran.action.PropertyAction;
Expand All @@ -37,8 +35,17 @@
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.joran.spi.Interpreter;
import ch.qos.logback.core.joran.spi.RuleStore;
import ch.qos.logback.core.model.*;
import ch.qos.logback.core.model.processor.*;
import ch.qos.logback.core.model.ImplicitModel;
import ch.qos.logback.core.model.PropertyModel;
import ch.qos.logback.core.model.ShutdownHookModel;
import ch.qos.logback.core.model.StatusListenerModel;
import ch.qos.logback.core.model.TimestampModel;
import ch.qos.logback.core.model.processor.DefaultProcessor;
import ch.qos.logback.core.model.processor.ImplicitModelHandler;
import ch.qos.logback.core.model.processor.PropertyModelHandler;
import ch.qos.logback.core.model.processor.ShutdownHookModelHandler;
import ch.qos.logback.core.model.processor.StatusListenerModelHandler;
import ch.qos.logback.core.model.processor.TimestampModelHandler;


// Based on 310985 revision 310985 as attested by http://tinyurl.com/8njps
Expand Down Expand Up @@ -86,16 +93,16 @@ protected void addInstanceRules(RuleStore rs) {
@Override
protected void addImplicitRules(Interpreter interpreter) {
// The following line adds the capability to parse nested components
NestedComplexPropertyIA nestedComplexPropertyIA = new NestedComplexPropertyIA(getBeanDescriptionCache());
nestedComplexPropertyIA.setContext(context);
interpreter.addImplicitAction(nestedComplexPropertyIA);

NestedBasicPropertyIA nestedBasicIA = new NestedBasicPropertyIA(getBeanDescriptionCache());
nestedBasicIA.setContext(context);
interpreter.addImplicitAction(nestedBasicIA);
// NestedComplexPropertyIA nestedComplexPropertyIA = new NestedComplexPropertyIA(getBeanDescriptionCache());
// nestedComplexPropertyIA.setContext(context);
// interpreter.addImplicitAction(nestedComplexPropertyIA);
//
// NestedBasicPropertyIA nestedBasicIA = new NestedBasicPropertyIA(getBeanDescriptionCache());
// nestedBasicIA.setContext(context);
// interpreter.addImplicitAction(nestedBasicIA);

ModelImplicitAction modelImplicitAction = new ModelImplicitAction();
interpreter.addImplicitAction(modelImplicitAction);
ImplicitModelAction implicitRuleModelAction = new ImplicitModelAction();
interpreter.addImplicitAction(implicitRuleModelAction);
}

@Override
Expand All @@ -113,9 +120,12 @@ public InterpretationContext getInterpretationContext() {
@Override
protected DefaultProcessor buildDefaultProcessor(Context context, InterpretationContext interpretationContext) {
DefaultProcessor defaultProcessor = super.buildDefaultProcessor(context, interpretationContext);
defaultProcessor.addHandler(ShutdownHookModel.class, ShutdownHookModelHandler.class);
defaultProcessor.addHandler(PropertyModel.class, PropertyModelHandler.class);
defaultProcessor.addHandler(TimestampModel.class, TimestampModelHandler.class);
defaultProcessor.addHandler(ShutdownHookModel.class, new ShutdownHookModelHandler(context));
defaultProcessor.addHandler(PropertyModel.class, new PropertyModelHandler(context));
defaultProcessor.addHandler(TimestampModel.class, new TimestampModelHandler(context));
defaultProcessor.addHandler(StatusListenerModel.class, new StatusListenerModelHandler(context));
defaultProcessor.addHandler(ImplicitModel.class, new ImplicitModelHandler(context, getBeanDescriptionCache()));

return defaultProcessor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ public abstract class BaseModelAction extends Action {
@Override
public void begin(InterpretationContext interpretationContext, String name, Attributes attributes) throws ActionException {
parentModel = null;

inError = false;

if (!validPreconditions(interpretationContext, name, attributes)) {
inError = true;
return;
}
parentModel = interpretationContext.peekModel();
currentModel = buildCurrentModel(interpretationContext, name, attributes);
currentModel.setTag(name);
final int lineNumber = getLineNumber(interpretationContext);
currentModel.setLineNumber(lineNumber);
interpretationContext.pushModel(currentModel);
}

Expand All @@ -32,6 +35,9 @@ public void begin(InterpretationContext interpretationContext, String name, Attr

@Override
public void end(InterpretationContext interpretationContext, String name) throws ActionException {
if(inError)
return;

Model m = interpretationContext.peekModel();

if (m != currentModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ContextPropertyAction extends Action {

@Override
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
addError("The [contextProperty] element has been removed. Please use [substitutionProperty] element instead");
addError("The [contextProperty] element has been removed. Please use [property] element instead");
}

@Override
Expand Down
Loading

0 comments on commit eaafcc8

Please sign in to comment.