Skip to content

Commit

Permalink
ongoign 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 330af63 commit f90e00f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ public class StatusListenerAction extends BaseModelAction {
Boolean effectivelyAdded = null;
StatusListener statusListener = null;


@Override
protected Model buildCurrentModel(InterpretationContext interpretationContext, String name, Attributes attributes) {
StatusListenerModel statusListenerModel = new StatusListenerModel();
statusListenerModel.setClassName(attributes.getValue(CLASS_ATTRIBUTE));
return statusListenerModel;
}

@Override
protected boolean validPreconditions(InterpretationContext interpretationContext, String name, Attributes attributes) {
String className = attributes.getValue(CLASS_ATTRIBUTE);
Expand All @@ -44,4 +36,13 @@ protected boolean validPreconditions(InterpretationContext interpretationContext
}
return true;
}

@Override
protected Model buildCurrentModel(InterpretationContext interpretationContext, String name, Attributes attributes) {
StatusListenerModel statusListenerModel = new StatusListenerModel();
statusListenerModel.setClassName(attributes.getValue(CLASS_ATTRIBUTE));
return statusListenerModel;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import ch.qos.logback.core.joran.SimpleConfigurator;
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.action.NOPAction;
import ch.qos.logback.core.joran.action.TopElementAction;
import ch.qos.logback.core.util.StatusPrinter;

/**
Expand All @@ -46,6 +47,7 @@ public List<FruitShell> doFirstPart(String filename) throws Exception {

try {
HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>();
rulesMap.put(new ElementSelector("group"), new TopElementAction());
rulesMap.put(new ElementSelector("group/fruitShell"), new FruitShellModelAction());
rulesMap.put(new ElementSelector("group/fruitShell/fruit"), new FruitFactoryAction());
rulesMap.put(new ElementSelector("group/fruitShell/fruit/*"), new NOPAction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

import org.xml.sax.Attributes;

import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.spi.ActionException;
import ch.qos.logback.core.joran.action.BaseModelAction;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.model.FruitShellModel;
import ch.qos.logback.core.model.Model;
Expand All @@ -25,55 +24,30 @@
/**
* The Fruit* code is intended to test Joran's replay capability
* */
public class FruitShellModelAction extends Action {
public class FruitShellModelAction extends BaseModelAction {

FruitShellModel fruitShellModel;
private boolean inError = false;

@Override
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {

// We are just beginning, reset variables
fruitShellModel = new FruitShellModel();
inError = false;

try {

// fruitShell.setContext(context);

String shellName = attributes.getValue(NAME_ATTRIBUTE);

if (OptionHelper.isEmpty(shellName)) {
addWarn("No appender name given for fruitShell].");
} else {
fruitShellModel.setName(shellName);
addInfo("FruitShell named as [" + shellName + "]");
}

ec.pushModel(fruitShellModel);
} catch (Exception oops) {
inError = true;
addError("Could not create an FruitShellModel", oops);
throw new ActionException(oops);
@Override
protected boolean validPreconditions(InterpretationContext interpretationContext, String name, Attributes attributes) {
String shellName = attributes.getValue(NAME_ATTRIBUTE);
if (OptionHelper.isEmpty(shellName)) {
addError("Missing name for fruitShell. Near [" + name + "] line " + getLineNumber(interpretationContext));
return false;
}
return true;
}

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

Model m = ec.peekModel();

if (m != fruitShellModel) {
addWarn("The object at the of the stack is not the fruitShell named [" + fruitShellModel.getName() + "] pushed earlier.");
} else {
addInfo("Popping fruitSHell named [" + fruitShellModel.getName() + "] from the object stack");
ec.popModel();
// FruitContext fruitContext = (FruitContext) ec.getContext();
// fruitContext.addFruitShell(fruitShellModel);
}
protected Model buildCurrentModel(InterpretationContext interpretationContext, String name, Attributes attributes) {
fruitShellModel = new FruitShellModel();
String shellName = attributes.getValue(NAME_ATTRIBUTE);
fruitShellModel.setName(shellName);
addInfo("FruitShell named as [" + shellName + "]");
return fruitShellModel;
}



}

0 comments on commit f90e00f

Please sign in to comment.