Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/urechm/logback into urechm-…
Browse files Browse the repository at this point in the history
…master
  • Loading branch information
ceki committed Mar 27, 2016
2 parents 6e1a80e + 54883ac commit 57ba5ae
Show file tree
Hide file tree
Showing 16 changed files with 413 additions and 138 deletions.
Expand Up @@ -14,7 +14,7 @@
package ch.qos.logback.classic.gaffer

import java.lang.reflect.Method
import java.beans.Introspector
import ch.qos.logback.core.joran.util.beans.BeanUtil

/**
* @author Ceki Gücü
Expand All @@ -27,7 +27,7 @@ class PropertyUtil {
}

static NestingType nestingType(Object obj, String name) {
def decapitalizedName = Introspector.decapitalize(name)
def decapitalizedName = BeanUtil.INSTANCE.toLowerCamelCase(name);
if (obj.hasProperty(decapitalizedName)) {
return NestingType.SINGLE;
}
Expand All @@ -40,7 +40,7 @@ class PropertyUtil {
static void attach(NestingType nestingType, Object component, Object subComponent, String name) {
switch (nestingType) {
case NestingType.SINGLE:
name = Introspector.decapitalize(name)
name = BeanUtil.INSTANCE.toLowerCamelCase(name);
component."${name}" = subComponent;
break;
case NestingType.AS_COLLECTION:
Expand Down
Expand Up @@ -22,10 +22,11 @@
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.joran.util.PropertySetter;
import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;
import ch.qos.logback.core.util.OptionHelper;

/**
*
*
* @author Ceki Gulcu
*
*/
Expand All @@ -35,8 +36,13 @@ public class BindDataSourceToJNDIAction extends Action {
static final String URL = "url";
static final String USER = "user";
static final String PASSWORD = "password";
private final BeanDescriptionCache beanDescriptionCache;

public BindDataSourceToJNDIAction(BeanDescriptionCache beanDescriptionCache) {
this.beanDescriptionCache = beanDescriptionCache;
}

/**
/**
* Instantiates an a data source and bind it to JNDI
* Most of the required parameters are placed in the ec.substitutionProperties
*/
Expand All @@ -57,7 +63,7 @@ public void begin(InterpretationContext ec, String localName, Attributes attribu
try {
DataSource ds = (DataSource) OptionHelper.instantiateByClassName(dsClassName, DataSource.class, context);

PropertySetter setter = new PropertySetter(ds);
PropertySetter setter = new PropertySetter(beanDescriptionCache,ds);
setter.setContext(context);

if (!OptionHelper.isEmpty(urlStr)) {
Expand Down
Expand Up @@ -18,6 +18,7 @@
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.spi.ContextAwareBase;
import ch.qos.logback.core.status.StatusUtil;

Expand All @@ -35,6 +36,8 @@

public abstract class GenericConfigurator extends ContextAwareBase {

private final BeanDescriptionCache beanDescriptionCache=new BeanDescriptionCache();

protected Interpreter interpreter;

public final void doConfigure(URL url) throws JoranException {
Expand Down Expand Up @@ -100,7 +103,12 @@ public final void doConfigure(InputStream inputStream) throws JoranException {
doConfigure(new InputSource(inputStream));
}

protected abstract void addInstanceRules(RuleStore rs);

protected BeanDescriptionCache getBeanDescriptionCache() {
return beanDescriptionCache;
}

protected abstract void addInstanceRules(RuleStore rs);

protected abstract void addImplicitRules(Interpreter interpreter);

Expand Down
Expand Up @@ -47,7 +47,7 @@
* <p>
* A JoranConfiguratorBase instance should not be used more than once to
* configure a Context.
*
*
* @author Ceki G&uuml;lc&uuml;
*/
abstract public class JoranConfiguratorBase extends GenericConfigurator {
Expand Down Expand Up @@ -80,17 +80,17 @@ protected void addInstanceRules(RuleStore rs) {
rs.addRule(new ElementSelector("configuration/appender"), new AppenderAction());
rs.addRule(new ElementSelector("configuration/appender/appender-ref"), new AppenderRefAction());
rs.addRule(new ElementSelector("configuration/newRule"), new NewRuleAction());
rs.addRule(new ElementSelector("*/param"), new ParamAction());
rs.addRule(new ElementSelector("*/param"), new ParamAction(getBeanDescriptionCache()));
}

@Override
protected void addImplicitRules(Interpreter interpreter) {
// The following line adds the capability to parse nested components
NestedComplexPropertyIA nestedComplexPropertyIA = new NestedComplexPropertyIA();
NestedComplexPropertyIA nestedComplexPropertyIA = new NestedComplexPropertyIA(getBeanDescriptionCache());
nestedComplexPropertyIA.setContext(context);
interpreter.addImplicitAction(nestedComplexPropertyIA);

NestedBasicPropertyIA nestedBasicIA = new NestedBasicPropertyIA();
NestedBasicPropertyIA nestedBasicIA = new NestedBasicPropertyIA(getBeanDescriptionCache());
nestedBasicIA.setContext(context);
interpreter.addImplicitAction(nestedBasicIA);
}
Expand Down
Expand Up @@ -16,21 +16,24 @@
import java.util.Stack;

import ch.qos.logback.core.joran.spi.ElementPath;

import org.xml.sax.Attributes;

import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.joran.util.PropertySetter;
import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;
import ch.qos.logback.core.util.AggregationType;

/**
* This action is responsible for tying together a parent object with one of its
* <em>simple</em> properties specified as an element but for which there is
* no explicit rule.
*
*
* @author Ceki G&uuml;lc&uuml;
*/
public class NestedBasicPropertyIA extends ImplicitAction {


// We use a stack of IADataForBasicProperty objects in order to
// support nested elements which are handled by the same NestedBasicPropertyIA instance.
// We push a IADataForBasicProperty instance in the isApplicable method (if the
Expand All @@ -39,6 +42,11 @@ public class NestedBasicPropertyIA extends ImplicitAction {
// be followed by the corresponding pop.
Stack<IADataForBasicProperty> actionDataStack = new Stack<IADataForBasicProperty>();

private final BeanDescriptionCache beanDescriptionCache;
public NestedBasicPropertyIA(BeanDescriptionCache beanDescriptionCache) {
this.beanDescriptionCache=beanDescriptionCache;
}

public boolean isApplicable(ElementPath elementPath, Attributes attributes, InterpretationContext ec) {
// System.out.println("in NestedSimplePropertyIA.isApplicable [" + pattern +
// "]");
Expand All @@ -50,7 +58,7 @@ public boolean isApplicable(ElementPath elementPath, Attributes attributes, Inte
}

Object o = ec.peekObject();
PropertySetter parentBean = new PropertySetter(o);
PropertySetter parentBean = new PropertySetter(beanDescriptionCache,o);
parentBean.setContext(context);

AggregationType aggregationType = parentBean.computeAggregationType(nestedElementTagName);
Expand Down
Expand Up @@ -16,11 +16,13 @@
import java.util.Stack;

import ch.qos.logback.core.joran.spi.ElementPath;

import org.xml.sax.Attributes;

import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.joran.spi.NoAutoStartUtil;
import ch.qos.logback.core.joran.util.PropertySetter;
import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;
import ch.qos.logback.core.spi.ContextAware;
import ch.qos.logback.core.spi.LifeCycle;
import ch.qos.logback.core.util.AggregationType;
Expand All @@ -30,7 +32,7 @@
/**
* This action is responsible for tying together a parent object with a child
* element for which there is no explicit rule.
*
*
* @author Ceki G&uuml;lc&uuml;
*/
public class NestedComplexPropertyIA extends ImplicitAction {
Expand All @@ -44,6 +46,11 @@ public class NestedComplexPropertyIA extends ImplicitAction {
// be followed by a corresponding pop.
Stack<IADataForComplexProperty> actionDataStack = new Stack<IADataForComplexProperty>();

private final BeanDescriptionCache beanDescriptionCache;
public NestedComplexPropertyIA(BeanDescriptionCache beanDescriptionCache) {
this.beanDescriptionCache=beanDescriptionCache;
}

public boolean isApplicable(ElementPath elementPath, Attributes attributes, InterpretationContext ic) {

String nestedElementTagName = elementPath.peekLast();
Expand All @@ -54,7 +61,7 @@ public boolean isApplicable(ElementPath elementPath, Attributes attributes, Inte
}

Object o = ic.peekObject();
PropertySetter parentBean = new PropertySetter(o);
PropertySetter parentBean = new PropertySetter(beanDescriptionCache,o);
parentBean.setContext(context);

AggregationType aggregationType = parentBean.computeAggregationType(nestedElementTagName);
Expand Down Expand Up @@ -138,7 +145,7 @@ public void end(InterpretationContext ec, String tagName) {
return;
}

PropertySetter nestedBean = new PropertySetter(actionData.getNestedComplexProperty());
PropertySetter nestedBean = new PropertySetter(beanDescriptionCache,actionData.getNestedComplexProperty());
nestedBean.setContext(context);

// have the nested element point to its parent if possible
Expand Down
Expand Up @@ -17,12 +17,18 @@

import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.joran.util.PropertySetter;
import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;

public class ParamAction extends Action {
static String NO_NAME = "No name attribute in <param> element";
static String NO_VALUE = "No name attribute in <param> element";
boolean inError = false;

private final BeanDescriptionCache beanDescriptionCache;
public ParamAction(BeanDescriptionCache beanDescriptionCache) {
this.beanDescriptionCache=beanDescriptionCache;
}

public void begin(InterpretationContext ec, String localName, Attributes attributes) {
String name = attributes.getValue(NAME_ATTRIBUTE);
String value = attributes.getValue(VALUE_ATTRIBUTE);
Expand All @@ -43,7 +49,7 @@ public void begin(InterpretationContext ec, String localName, Attributes attribu
value = value.trim();

Object o = ec.peekObject();
PropertySetter propSetter = new PropertySetter(o);
PropertySetter propSetter = new PropertySetter(beanDescriptionCache,o);
propSetter.setContext(context);
value = ec.subst(value);

Expand Down

0 comments on commit 57ba5ae

Please sign in to comment.