Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.joran.spi;
 
 import java.util.List;
 import java.util.Map;
 
 
<id>Interpreter</id> is Joran's main driving class. It extends SAX DefaultHandler which invokes various actions according to predefined patterns.

Patterns are kept in a RuleStore which is programmed to store and then later produce the applicable actions for a given pattern.

The pattern corresponding to a top level <a> element is the string <id>"a"</id>.

The pattern corresponding to an element <b> embedded within a top level <a> element is the string <id>"a/b"</id>.

The pattern corresponding to an <b> and any level of nesting is "*/b. Thus, the * character placed at the beginning of a pattern serves as a wildcard for the level of nesting. Conceptually, this is very similar to the API of commons-digester. Joran offers several small advantages. First and foremost, it offers support for implicit actions which result in a significant leap in flexibility. Second, in our opinion better error reporting capability. Third, it is self-reliant. It does not depend on other APIs, in particular commons-logging which is too unreliable. Last but not least, Joran is quite tiny and is expected to remain so.

Author(s):
Ceki Gülcuü
 
 public class Interpreter {
   private static List EMPTY_LIST = new Vector(0);
 
   final private RuleStore ruleStore;
   final private ArrayList<ImplicitActionimplicitActions;
   final private CAI_WithLocatorSupport cai;
   private Pattern pattern;
The <id>actionListStack</id> contains a list of actions that are executing for the given XML element. A list of actions is pushed by the {link #startElement} and popped by endElement(ch.qos.logback.core.joran.event.EndEvent).
 
If the skip nested is set, then we skip all its nested elements until it is set back to null at when the element's end is reached.
 
   Pattern skip = null;
 
   public Interpreter(Context contextRuleStore rsPattern initialPattern) {
     this. = new CAI_WithLocatorSupport(this);
     this..setContext(context);
      = rs;
      = new InterpretationContext(contextthis);
    this. = initialPattern;
     = new Stack<List>();
     = new EventPlayer(this);
  }
  public EventPlayer getEventPlayer() {
    return ;
  }
      Map<StringStringpropertiesMap) {
  }

  

Deprecated:
replaced by getInterpretationContext()
    return getInterpretationContext();
  }
    return ;
  }
  public void startDocument() {
  }
  public void startElement(StartEvent se) {
    startElement(se.namespaceURIse.localNamese.qNamese.attributes);
  }
  private void startElement(String namespaceURIString localName,
      String qNameAttributes atts) {
    String tagName = getTagName(localNameqName);
    .push(tagName);
    if ( != null) {
      // every startElement pushes an action list
      pushEmptyActionList();
      return;
    }
    List applicableActionList = getApplicableActionList(atts);
    if (applicableActionList != null) {
      .add(applicableActionList);
      callBeginAction(applicableActionListtagNameatts);
    } else {
      // every startElement pushes an action list
      pushEmptyActionList();
      String errMsg = "no applicable action for [" + tagName
          + "], current pattern is [" +  + "]";
      .addError(errMsg);
    }
  }

  
This method is used to
  private void pushEmptyActionList() {
  }
  public void characters(BodyEvent be) {
    setDocumentLocator(be.locator);
    String body = be.getText();
    List applicableActionList = .peek();
    if (body != null) {
      body = body.trim();
      if (body.length() > 0) {
        // System.out.println("calling body method with ["+body+ "]");
        callBodyAction(applicableActionListbody);
      }
    }
  }
  public void endElement(EndEvent endEvent) {
    setDocumentLocator(endEvent.locator);
    endElement(endEvent.namespaceURIendEvent.localNameendEvent.qName);
  }
  private void endElement(String namespaceURIString localNameString qName) {
    // given that an action list is always pushed for every startElement, we
    // need
    // to always pop for every endElement
    List applicableActionList = (List.pop();
    if ( != null) {
      if (.equals()) {
         = null;
      }
    } else if (applicableActionList != ) {
      callEndAction(applicableActionListgetTagName(localNameqName));
    }
    // given that we always push, we must also pop the pattern
    .pop();
  }
  public Locator getLocator() {
    return ;
  }
  public void setDocumentLocator(Locator l) {
     = l;
  }
  String getTagName(String localNameString qName) {
    String tagName = localName;
    if ((tagName == null) || (tagName.length() < 1)) {
      tagName = qName;
    }
    return tagName;
  }
  public void addImplicitAction(ImplicitAction ia) {
    .add(ia);
  }

  
Check if any implicit actions are applicable. As soon as an applicable action is found, it is returned. Thus, the returned list will have at most one element.
  List lookupImplicitAction(Pattern patternAttributes attributes,
      InterpretationContext ec) {
    int len = .size();
    for (int i = 0; i < leni++) {
      if (ia.isApplicable(patternattributesec)) {
        List<ActionactionList = new ArrayList<Action>(1);
        actionList.add(ia);
        return actionList;
      }
    }
    return null;
  }

  
Return the list of applicable patterns for this
  List getApplicableActionList(Pattern patternAttributes attributes) {
    List applicableActionList = .matchActions(pattern);
    // logger.debug("set of applicable patterns: " + applicableActionList);
    if (applicableActionList == null) {
      applicableActionList = lookupImplicitAction(patternattributes,
          );
    }
    return applicableActionList;
  }
  void callBeginAction(List applicableActionListString tagName,
      Attributes atts) {
    if (applicableActionList == null) {
      return;
    }
    Iterator i = applicableActionList.iterator();
    while (i.hasNext()) {
      Action action = (Actioni.next();
      // now let us invoke the action. We catch and report any eventual
      // exceptions
      try {
        action.begin(tagNameatts);
      } catch (ActionException e) {
         = (Pattern.clone();
        .addError("ActionException in Action for tag [" + tagName + "]"e);
      } catch (RuntimeException e) {
         = (Pattern.clone();
        .addError("RuntimeException in Action for tag [" + tagName + "]"e);
      }
    }
  }
  private void callBodyAction(List applicableActionListString body) {
    if (applicableActionList == null) {
      return;
    }
    Iterator i = applicableActionList.iterator();
    while (i.hasNext()) {
      Action action = (Actioni.next();
      try {
        action.body(body);
      } catch (ActionException ae) {
        
            .addError("Exception in end() methd for action [" + action + "]",
                ae);
      }
    }
  }
  private void callEndAction(List applicableActionListString tagName) {
    if (applicableActionList == null) {
      return;
    }
    // logger.debug("About to call end actions on node: [" + localName + "]");
    Iterator i = applicableActionList.iterator();
    while (i.hasNext()) {
      Action action = (Actioni.next();
      // now let us invoke the end method of the action. We catch and report
      // any eventual exceptions
      try {
        action.end(tagName);
      } catch (ActionException ae) {
        // at this point endAction, there is no point in skipping children as
        // they have been already processed
        .addError("ActionException in Action for tag [" + tagName + "]"ae);
      } catch (RuntimeException e) {
        // no point in setting skip
        .addError("RuntimeException in Action for tag [" + tagName + "]"e);
      }
    }
  }
  public RuleStore getRuleStore() {
    return ;
  }
When Interpreter class is used as the origin of an ch.qos.logback.core.spi.ContextAwareImpl instance, then XML locator information is lost. This class preserves locator information (as a string).

Author(s):
ceki
    super(interpreter);
  }
  protected Object getOrigin() {
    Interpreter i = (Interpretersuper.getOrigin();
    Locator locator = i.locator;
    if (locator != null) {
      return Interpreter.class.getName() + "@" + locator.getLineNumber() + ":"
          + locator.getColumnNumber();
    } else {
      return Interpreter.class.getName() + "@NA:NA";
    }
  }
New to GrepCode? Check out our FAQ X