logback-core-0.9.9

16:38:57.495 INFO  jd.cli.Main - Decompiling logback-core-0.9.9.jar
package ch.qos.logback.core;

import ch.qos.logback.core.spi.ContextAware;
import ch.qos.logback.core.spi.FilterAttachable;
import ch.qos.logback.core.spi.LifeCycle;

public abstract interface Appender<E>
  extends LifeCycle, ContextAware, FilterAttachable
{
  public abstract String getName();
  
  public abstract void doAppend(E paramE)
    throws LogbackException;
  
  public abstract void setLayout(Layout<E> paramLayout);
  
  public abstract Layout<E> getLayout();
  
  public abstract void setName(String paramString);
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.Appender
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core;

import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.FilterAttachable;
import ch.qos.logback.core.spi.FilterAttachableImpl;
import ch.qos.logback.core.spi.FilterReply;
import ch.qos.logback.core.status.WarnStatus;

public abstract class AppenderBase<E>
  extends ContextAwareBase
  implements Appender<E>, FilterAttachable
{
  protected boolean started = false;
  private boolean guard = false;
  protected String name;
  private FilterAttachableImpl fai = new FilterAttachableImpl();
  
  public String getName()
  {
    return name;
  }
  
  private int statusRepeatCount = 0;
  private int exceptionCount = 0;
  static final int ALLOWED_REPEATS = 5;
  
  public synchronized void doAppend(E eventObject)
  {
    if (guard) {
      return;
    }
    try
    {
      guard = true;
      if (!started)
      {
        if (statusRepeatCount++ < 5) {
          addStatus(new WarnStatus("Attempted to append to non started appender [" + name + "].", this));
        }
      }
      else
      {
        if (getFilterChainDecision(eventObject) == FilterReply.DENY) {
          return;
        }
        append(eventObject);
      }
    }
    catch (Exception e)
    {
      if (exceptionCount++ < 5) {
        addError("Appender [" + name + "] failed to append.", e);
      }
    }
    finally
    {
      guard = false;
    }
  }
  
  protected abstract void append(E paramE);
  
  public void setName(String name)
  {
    this.name = name;
  }
  
  public void start()
  {
    started = true;
  }
  
  public void stop()
  {
    started = false;
  }
  
  public boolean isStarted()
  {
    return started;
  }
  
  public String toString()
  {
    return getClass().getName() + "[" + name + "]";
  }
  
  public void addFilter(Filter newFilter)
  {
    fai.addFilter(newFilter);
  }
  
  public Filter getFirstFilter()
  {
    return fai.getFirstFilter();
  }
  
  public void clearAllFilters()
  {
    fai.clearAllFilters();
  }
  
  public FilterReply getFilterChainDecision(Object event)
  {
    return fai.getFilterChainDecision(event);
  }
  
  public Layout<E> getLayout()
  {
    return null;
  }
  
  public void setLayout(Layout<E> layout) {}
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.AppenderBase
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core;

import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusManager;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class BasicStatusManager
  implements StatusManager
{
  public static final int MAX_COUNT = 200;
  int count = 0;
  List<Status> statusList = new ArrayList();
  int level = 0;
  
  public synchronized void add(Status newStatus)
  {
    if (count > 200) {
      return;
    }
    count += 1;
    if (newStatus.getLevel() > level) {
      level = newStatus.getLevel();
    }
    statusList.add(newStatus);
  }
  
  public Iterator<Status> iterator()
  {
    return statusList.iterator();
  }
  
  public int getLevel()
  {
    return level;
  }
  
  public int getCount()
  {
    return count;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.BasicStatusManager
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.boolex;

public class EvaluationException
  extends Exception
{
  private static final long serialVersionUID = 1L;
  
  public EvaluationException(String msg)
  {
    super(msg);
  }
  
  public EvaluationException(String msg, Throwable cause)
  {
    super(msg, cause);
  }
  
  public EvaluationException(Throwable cause)
  {
    super(cause);
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.boolex.EvaluationException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.boolex;

import ch.qos.logback.core.spi.ContextAware;
import ch.qos.logback.core.spi.LifeCycle;

public abstract interface EventEvaluator
  extends ContextAware, LifeCycle
{
  public abstract boolean evaluate(Object paramObject)
    throws NullPointerException, EvaluationException;
  
  public abstract String getName();
  
  public abstract void setName(String paramString);
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.boolex.EventEvaluator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.boolex;

import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.LifeCycle;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.janino.ExpressionEvaluator;

public abstract class JaninoEventEvaluatorBase
  extends ContextAwareBase
  implements EventEvaluator, LifeCycle
{
  static Class EXPRESSION_TYPE;
  static Class[] THROWN_EXCEPTIONS;
  public static final int ERROR_THRESHOLD = 4;
  
  static
  {
    EXPRESSION_TYPE = Boolean.TYPE;
    THROWN_EXCEPTIONS = new Class[1];
    
    THROWN_EXCEPTIONS[0] = EvaluationException.class;
  }
  
  protected boolean start = false;
  private String name;
  private String expression;
  ExpressionEvaluator ee;
  private int errorCount = 0;
  protected List<Matcher> matcherList = new ArrayList();
  
  public boolean isStarted()
  {
    return start;
  }
  
  public void stop()
  {
    start = false;
  }
  
  public void start()
  {
    try
    {
      assert (context != null);
      ClassLoader cl = context.getClass().getClassLoader();
      ee = new ExpressionEvaluator(getDecoratedExpression(), EXPRESSION_TYPE, getParameterNames(), getParameterTypes(), THROWN_EXCEPTIONS, cl);
      
      start = true;
    }
    catch (Exception e)
    {
      addError("Could not start evaluator with expression [" + expression + "]", e);
    }
  }
  
  public boolean evaluate(Object event)
    throws EvaluationException
  {
    if (!start) {
      throw new IllegalStateException("Evaluator [" + name + "] was called in stopped state");
    }
    try
    {
      Boolean result = (Boolean)ee.evaluate(getParameterValues(event));
      return result.booleanValue();
    }
    catch (Exception ex)
    {
      errorCount += 1;
      if (errorCount >= 4) {
        start = false;
      }
      throw new EvaluationException("Evaluator [" + name + "] caused an exception", ex);
    }
  }
  
  public String getName()
  {
    return name;
  }
  
  public void setName(String name)
  {
    if (this.name != null) {
      throw new IllegalStateException("name has been already set");
    }
    this.name = name;
  }
  
  public String getExpression()
  {
    return expression;
  }
  
  public void setExpression(String expression)
  {
    this.expression = expression;
  }
  
  public void addMatcher(Matcher matcher)
  {
    matcherList.add(matcher);
  }
  
  public List getMatcherList()
  {
    return matcherList;
  }
  
  protected abstract String getDecoratedExpression();
  
  protected abstract String[] getParameterNames();
  
  protected abstract Class[] getParameterTypes();
  
  protected abstract Object[] getParameterValues(Object paramObject);
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.boolex.JaninoEventEvaluatorBase
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.boolex;

import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.LifeCycle;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class Matcher
  extends ContextAwareBase
  implements LifeCycle
{
  private String regex;
  private String name;
  private boolean caseSensitive = true;
  private boolean canonEq = false;
  private boolean unicodeCase = false;
  private boolean start = false;
  private Pattern pattern;
  
  public String getRegex()
  {
    return regex;
  }
  
  public void setRegex(String regex)
  {
    this.regex = regex;
  }
  
  public void start()
  {
    if (name == null)
    {
      addError("All Matcher objects must be named");
      return;
    }
    try
    {
      int code = 0;
      if (!caseSensitive) {
        code |= 0x2;
      }
      if (canonEq) {
        code |= 0x80;
      }
      if (unicodeCase) {
        code |= 0x40;
      }
      pattern = Pattern.compile(regex, code);
      start = true;
    }
    catch (PatternSyntaxException pse)
    {
      addError("Failed to compile regex [" + regex + "]", pse);
    }
  }
  
  public void stop()
  {
    start = false;
  }
  
  public boolean isStarted()
  {
    return start;
  }
  
  public boolean matches(String input)
    throws EvaluationException
  {
    if (start)
    {
      java.util.regex.Matcher matcher = pattern.matcher(input);
      return matcher.find();
    }
    throw new EvaluationException("Matcher [" + regex + "] not started");
  }
  
  public boolean isCanonEq()
  {
    return canonEq;
  }
  
  public void setCanonEq(boolean canonEq)
  {
    this.canonEq = canonEq;
  }
  
  public boolean isCaseSensitive()
  {
    return caseSensitive;
  }
  
  public void setCaseSensitive(boolean caseSensitive)
  {
    this.caseSensitive = caseSensitive;
  }
  
  public boolean isUnicodeCase()
  {
    return unicodeCase;
  }
  
  public void setUnicodeCase(boolean unicodeCase)
  {
    this.unicodeCase = unicodeCase;
  }
  
  public String getName()
  {
    return name;
  }
  
  public void setName(String name)
  {
    this.name = name;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.boolex.Matcher
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core;

import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.WarnStatus;

public class ConsoleAppender<E>
  extends WriterAppender<E>
{
  public static final String SYSTEM_OUT = "System.out";
  public static final String SYSTEM_ERR = "System.err";
  protected String target = "System.out";
  
  public void setTarget(String value)
  {
    String v = value.trim();
    if ("System.out".equalsIgnoreCase(v)) {
      target = "System.out";
    } else if ("System.err".equalsIgnoreCase(v)) {
      target = "System.err";
    } else {
      targetWarn(value);
    }
  }
  
  public String getTarget()
  {
    return target;
  }
  
  void targetWarn(String val)
  {
    Status status = new WarnStatus("[" + val + " should be System.out or System.err.", this);
    status.add(new WarnStatus("Using previously set target, System.out by default.", this));
    addStatus(status);
  }
  
  public void start()
  {
    if (target.equals("System.out")) {
      setWriter(createWriter(System.out));
    } else {
      setWriter(createWriter(System.err));
    }
    super.start();
  }
  
  protected final void closeWriter()
  {
    writeFooter();
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.ConsoleAppender
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core;

import ch.qos.logback.core.status.StatusManager;

public abstract interface Context
{
  public abstract StatusManager getStatusManager();
  
  public abstract Object getObject(String paramString);
  
  public abstract void putObject(String paramString, Object paramObject);
  
  public abstract String getProperty(String paramString);
  
  public abstract void putProperty(String paramString1, String paramString2);
  
  public abstract String getName();
  
  public abstract void setName(String paramString);
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.Context
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core;

import ch.qos.logback.core.status.StatusManager;
import java.util.HashMap;
import java.util.Map;

public class ContextBase
  implements Context
{
  private String name;
  StatusManager sm = new BasicStatusManager();
  Map<String, String> propertyMap = new HashMap();
  Map<String, Object> objectMap = new HashMap();
  
  public StatusManager getStatusManager()
  {
    return sm;
  }
  
  public Map<String, String> getCopyOfPropertyMap()
  {
    return new HashMap(propertyMap);
  }
  
  public void putProperty(String key, String val)
  {
    propertyMap.put(key, val);
  }
  
  public String getProperty(String key)
  {
    return (String)propertyMap.get(key);
  }
  
  public Object getObject(String key)
  {
    return objectMap.get(key);
  }
  
  public void putObject(String key, Object value)
  {
    objectMap.put(key, value);
  }
  
  public String getName()
  {
    return name;
  }
  
  public void setName(String name)
  {
    if (this.name != null) {
      throw new IllegalStateException("Context has been already given a name");
    }
    this.name = name;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.ContextBase
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core;

public class CoreGlobal
{
  public static final String LINE_SEPARATOR = System.getProperty("line.separator");
  public static final int LINE_SEPARATOR_LEN = LINE_SEPARATOR.length();
  public static final String CODES_URL = "http://logback.qos.ch/codes.html";
  public static final String PATTERN_RULE_REGISTRY = "PATTERN_RULE_REGISTRY";
  public static final String ISO8601_STR = "ISO8601";
  public static final String ISO8601_PATTERN = "yyyy-MM-dd HH:mm:ss,SSS";
  public static final String CLF_DATE_PATTERN = "dd/MM/yyyy:HH:mm:ss Z";
  public static final String EVALUATOR_MAP = "EVALUATOR_MAP";
  public static final String EMPTY_STRING = "";
  public static final String[] EMPTY_STRING_ARRAY = new String[0];
  public static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.CoreGlobal
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db;

import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.util.OptionHelper;
import ch.qos.logback.core.util.PropertySetter;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.xml.sax.Attributes;

public class BindDataSourceToJNDIAction
  extends Action
{
  static final String DATA_SOURCE_CLASS = "dataSourceClass";
  static final String URL = "url";
  static final String USER = "user";
  static final String PASSWORD = "password";
  
  public void begin(InterpretationContext ec, String localName, Attributes attributes)
  {
    String dsClassName = ec.getSubstitutionProperty("dataSourceClass");
    if (OptionHelper.isEmpty(dsClassName))
    {
      addWarn("dsClassName is a required parameter");
      ec.addError("dsClassName is a required parameter");
      
      return;
    }
    String urlStr = ec.getSubstitutionProperty("url");
    String userStr = ec.getSubstitutionProperty("user");
    String passwordStr = ec.getSubstitutionProperty("password");
    try
    {
      DataSource ds = (DataSource)OptionHelper.instantiateByClassName(dsClassName, DataSource.class, context);
      
      PropertySetter setter = new PropertySetter(ds);
      setter.setContext(context);
      if (!OptionHelper.isEmpty(urlStr)) {
        setter.setProperty("url", urlStr);
      }
      if (!OptionHelper.isEmpty(userStr)) {
        setter.setProperty("user", userStr);
      }
      if (!OptionHelper.isEmpty(passwordStr)) {
        setter.setProperty("password", passwordStr);
      }
      Context ctx = new InitialContext();
      ctx.rebind("dataSource", ds);
    }
    catch (Exception oops)
    {
      addError("Could not bind  datasource. Reported error follows.", oops);
      
      ec.addError("Could not not bind  datasource of type [" + dsClassName + "].");
    }
  }
  
  public void end(InterpretationContext ec, String name) {}
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.BindDataSourceToJNDIAction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db;

import ch.qos.logback.core.spi.LifeCycle;
import java.sql.Connection;
import java.sql.SQLException;

public abstract interface ConnectionSource
  extends LifeCycle
{
  public static final int UNKNOWN_DIALECT = 0;
  public static final int POSTGRES_DIALECT = 1;
  public static final int MYSQL_DIALECT = 2;
  public static final int ORACLE_DIALECT = 3;
  public static final int MSSQL_DIALECT = 4;
  public static final int HSQL_DIALECT = 5;
  
  public abstract Connection getConnection()
    throws SQLException;
  
  public abstract int getSQLDialectCode();
  
  public abstract boolean supportsGetGeneratedKeys();
  
  public abstract boolean supportsBatchUpdates();
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.ConnectionSource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db;

import ch.qos.logback.core.db.dialect.DBUtil;
import ch.qos.logback.core.spi.ContextAwareBase;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

public abstract class ConnectionSourceBase
  extends ContextAwareBase
  implements ConnectionSource
{
  private boolean started;
  private String user = null;
  private String password = null;
  private int dialectCode = 0;
  private boolean supportsGetGeneratedKeys = false;
  private boolean supportsBatchUpdates = false;
  
  public void discoverConnnectionProperties()
  {
    try
    {
      Connection connection = getConnection();
      if (connection == null)
      {
        addWarn("Could not get a connection");
        return;
      }
      DatabaseMetaData meta = connection.getMetaData();
      DBUtil util = new DBUtil();
      util.setContext(getContext());
      supportsGetGeneratedKeys = util.supportsGetGeneratedKeys(meta);
      supportsBatchUpdates = util.supportsBatchUpdates(meta);
      dialectCode = DBUtil.discoverSQLDialect(meta);
    }
    catch (SQLException se)
    {
      addWarn("Could not discover the dialect to use.", se);
    }
  }
  
  public final boolean supportsGetGeneratedKeys()
  {
    return supportsGetGeneratedKeys;
  }
  
  public final int getSQLDialectCode()
  {
    return dialectCode;
  }
  
  public final String getPassword()
  {
    return password;
  }
  
  public final void setPassword(String password)
  {
    this.password = password;
  }
  
  public final String getUser()
  {
    return user;
  }
  
  public final void setUser(String username)
  {
    user = username;
  }
  
  public final boolean supportsBatchUpdates()
  {
    return supportsBatchUpdates;
  }
  
  public boolean isStarted()
  {
    return started;
  }
  
  public void start()
  {
    started = true;
  }
  
  public void stop()
  {
    started = false;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.ConnectionSourceBase
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db;

import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;

public class DataSourceConnectionSource
  extends ConnectionSourceBase
{
  private DataSource dataSource;
  
  public void start()
  {
    if (dataSource == null)
    {
      addWarn("WARNING: No data source specified");
    }
    else
    {
      Connection connection = null;
      try
      {
        connection = getConnection();
      }
      catch (SQLException se)
      {
        addWarn("Could not get a connection to discover the dialect to use.", se);
      }
      if (connection != null) {
        discoverConnnectionProperties();
      }
      if ((!supportsGetGeneratedKeys()) && (getSQLDialectCode() == 0)) {
        addWarn("Connection does not support GetGeneratedKey method and could not discover the dialect.");
      }
    }
    super.start();
  }
  
  public Connection getConnection()
    throws SQLException
  {
    if (dataSource == null)
    {
      addError("WARNING: No data source specified");
      return null;
    }
    if (getUser() == null) {
      return dataSource.getConnection();
    }
    return dataSource.getConnection(getUser(), getPassword());
  }
  
  public DataSource getDataSource()
  {
    return dataSource;
  }
  
  public void setDataSource(DataSource dataSource)
  {
    this.dataSource = dataSource;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.DataSourceConnectionSource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db;

import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.db.dialect.DBUtil;
import ch.qos.logback.core.db.dialect.SQLDialect;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public abstract class DBAppenderBase<E>
  extends AppenderBase<E>
{
  protected ConnectionSource connectionSource;
  protected boolean cnxSupportsGetGeneratedKeys = false;
  protected boolean cnxSupportsBatchUpdates = false;
  protected SQLDialect sqlDialect;
  
  protected abstract Method getGeneratedKeysMethod();
  
  protected abstract String getInsertSQL();
  
  public void start()
  {
    if (connectionSource == null) {
      throw new IllegalStateException("DBAppender cannot function without a connection source");
    }
    sqlDialect = DBUtil.getDialectFromCode(connectionSource.getSQLDialectCode());
    if (getGeneratedKeysMethod() != null) {
      cnxSupportsGetGeneratedKeys = connectionSource.supportsGetGeneratedKeys();
    } else {
      cnxSupportsGetGeneratedKeys = false;
    }
    cnxSupportsBatchUpdates = connectionSource.supportsBatchUpdates();
    if ((!cnxSupportsGetGeneratedKeys) && (sqlDialect == null)) {
      throw new IllegalStateException("DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect");
    }
    super.start();
  }
  
  public ConnectionSource getConnectionSource()
  {
    return connectionSource;
  }
  
  public void setConnectionSource(ConnectionSource connectionSource)
  {
    this.connectionSource = connectionSource;
  }
  
  public void append(E eventObject)
  {
    Connection connection = null;
    try
    {
      connection = connectionSource.getConnection();
      connection.setAutoCommit(false);
      
      PreparedStatement insertStatement = connection.prepareStatement(getInsertSQL());
      
      subAppend(eventObject, connection, insertStatement);
      if (insertStatement != null)
      {
        insertStatement.close();
        insertStatement = null;
      }
      connection.commit();
    }
    catch (Throwable sqle)
    {
      addError("problem appending event", sqle);
    }
    finally
    {
      DBHelper.closeConnection(connection);
    }
  }
  
  protected abstract void subAppend(Object paramObject, Connection paramConnection, PreparedStatement paramPreparedStatement)
    throws Throwable;
  
  protected int getEventId(PreparedStatement insertStatement, Connection connection)
    throws SQLException, InvocationTargetException
  {
    ResultSet rs = null;
    Statement idStatement = null;
    boolean gotGeneratedKeys = false;
    if (cnxSupportsGetGeneratedKeys) {
      try
      {
        rs = (ResultSet)getGeneratedKeysMethod().invoke(insertStatement, (Object[])null);
        
        gotGeneratedKeys = true;
      }
      catch (InvocationTargetException ex)
      {
        Throwable target = ex.getTargetException();
        if ((target instanceof SQLException)) {
          throw ((SQLException)target);
        }
        throw ex;
      }
      catch (IllegalAccessException ex)
      {
        addWarn("IllegalAccessException invoking PreparedStatement.getGeneratedKeys", ex);
      }
    }
    if (!gotGeneratedKeys)
    {
      insertStatement.close();
      insertStatement = null;
      
      idStatement = connection.createStatement();
      idStatement.setMaxRows(1);
      rs = idStatement.executeQuery(sqlDialect.getSelectInsertId());
    }
    rs.next();
    int eventId = rs.getInt(1);
    
    rs.close();
    if (idStatement != null)
    {
      idStatement.close();
      idStatement = null;
    }
    return eventId;
  }
  
  public void stop()
  {
    super.stop();
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.DBAppenderBase
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class DBHelper
{
  public static void closeConnection(Connection connection)
  {
    if (connection != null) {
      try
      {
        connection.close();
      }
      catch (SQLException sqle) {}
    }
  }
  
  public static void closeStatement(Statement statement)
  {
    if (statement != null) {
      try
      {
        statement.close();
      }
      catch (SQLException sqle) {}
    }
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.DBHelper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db.dialect;

import ch.qos.logback.core.spi.ContextAwareBase;
import java.lang.reflect.Method;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

public class DBUtil
  extends ContextAwareBase
{
  private static final String POSTGRES_PART = "postgresql";
  private static final String MYSQL_PART = "mysql";
  private static final String ORACLE_PART = "oracle";
  private static final String MSSQL_PART = "microsoft";
  private static final String HSQL_PART = "hsql";
  
  public static int discoverSQLDialect(DatabaseMetaData meta)
  {
    int dialectCode = 0;
    try
    {
      String dbName = meta.getDatabaseProductName().toLowerCase();
      if (dbName.indexOf("postgresql") != -1) {
        return 1;
      }
      if (dbName.indexOf("mysql") != -1) {
        return 2;
      }
      if (dbName.indexOf("oracle") != -1) {
        return 3;
      }
      if (dbName.indexOf("microsoft") != -1) {
        return 4;
      }
      if (dbName.indexOf("hsql") != -1) {
        return 5;
      }
      return 0;
    }
    catch (SQLException sqle) {}
    return dialectCode;
  }
  
  public static SQLDialect getDialectFromCode(int dialectCode)
  {
    SQLDialect sqlDialect = null;
    switch (dialectCode)
    {
    case 1: 
      sqlDialect = new PostgreSQLDialect();
      
      break;
    case 2: 
      sqlDialect = new MySQLDialect();
      
      break;
    case 3: 
      sqlDialect = new OracleDialect();
      
      break;
    case 4: 
      sqlDialect = new MsSQLDialect();
      
      break;
    case 5: 
      sqlDialect = new HSQLDBDialect();
    }
    return sqlDialect;
  }
  
  public boolean supportsGetGeneratedKeys(DatabaseMetaData meta)
  {
    try
    {
      return ((Boolean)DatabaseMetaData.class.getMethod("supportsGetGeneratedKeys", (Class[])null).invoke(meta, (Object[])null)).booleanValue();
    }
    catch (Throwable e)
    {
      addInfo("Could not call supportsGetGeneratedKeys method. This may be recoverable");
    }
    return false;
  }
  
  public boolean supportsBatchUpdates(DatabaseMetaData meta)
  {
    try
    {
      return meta.supportsBatchUpdates();
    }
    catch (Throwable e)
    {
      addInfo("Missing DatabaseMetaData.supportsBatchUpdates method.");
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.dialect.DBUtil
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db.dialect;

public class HSQLDBDialect
  implements SQLDialect
{
  public static final String SELECT_CURRVAL = "CALL IDENTITY()";
  
  public String getSelectInsertId()
  {
    return "CALL IDENTITY()";
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.dialect.HSQLDBDialect
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db.dialect;

public class MsSQLDialect
  implements SQLDialect
{
  public static final String SELECT_CURRVAL = "SELECT @@identity id";
  
  public String getSelectInsertId()
  {
    return "SELECT @@identity id";
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.dialect.MsSQLDialect
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db.dialect;

public class MySQLDialect
  implements SQLDialect
{
  public static final String SELECT_LAST_INSERT_ID = "SELECT LAST_INSERT_ID()";
  
  public String getSelectInsertId()
  {
    return "SELECT LAST_INSERT_ID()";
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.dialect.MySQLDialect
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db.dialect;

public class OracleDialect
  implements SQLDialect
{
  public static final String SELECT_CURRVAL = "SELECT logging_event_id_seq.currval from dual";
  
  public String getSelectInsertId()
  {
    return "SELECT logging_event_id_seq.currval from dual";
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.dialect.OracleDialect
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db.dialect;

public class PostgreSQLDialect
  implements SQLDialect
{
  public static final String SELECT_CURRVAL = "SELECT currval('logging_event_id_seq')";
  
  public String getSelectInsertId()
  {
    return "SELECT currval('logging_event_id_seq')";
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.dialect.PostgreSQLDialect
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db.dialect;

public abstract interface SQLDialect
{
  public abstract String getSelectInsertId();
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.dialect.SQLDialect
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DriverManagerConnectionSource
  extends ConnectionSourceBase
{
  private String driverClass = null;
  private String url = null;
  
  public void start()
  {
    try
    {
      if (driverClass != null)
      {
        Class.forName(driverClass);
        discoverConnnectionProperties();
      }
      else
      {
        addError("WARNING: No JDBC driver specified for logback DriverManagerConnectionSource.");
      }
    }
    catch (ClassNotFoundException cnfe)
    {
      addError("Could not load JDBC driver class: " + driverClass, cnfe);
    }
  }
  
  public Connection getConnection()
    throws SQLException
  {
    if (getUser() == null) {
      return DriverManager.getConnection(url);
    }
    return DriverManager.getConnection(url, getUser(), getPassword());
  }
  
  public String getUrl()
  {
    return url;
  }
  
  public void setUrl(String url)
  {
    this.url = url;
  }
  
  public String getDriverClass()
  {
    return driverClass;
  }
  
  public void setDriverClass(String driverClass)
  {
    this.driverClass = driverClass;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.DriverManagerConnectionSource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.db;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class JNDIConnectionSource
  extends ConnectionSourceBase
{
  private String jndiLocation = null;
  private DataSource dataSource = null;
  
  public void start()
  {
    if (jndiLocation == null) {
      addError("No JNDI location specified for JNDIConnectionSource.");
    }
    discoverConnnectionProperties();
  }
  
  public Connection getConnection()
    throws SQLException
  {
    Connection conn = null;
    try
    {
      if (dataSource == null) {
        dataSource = lookupDataSource();
      }
      if (getUser() == null) {
        conn = dataSource.getConnection();
      } else {
        conn = dataSource.getConnection(getUser(), getPassword());
      }
    }
    catch (NamingException ne)
    {
      addError("Error while getting data source", ne);
      throw new SQLException("NamingException while looking up DataSource: " + ne.getMessage());
    }
    catch (ClassCastException cce)
    {
      addError("ClassCastException while looking up DataSource.", cce);
      throw new SQLException("ClassCastException while looking up DataSource: " + cce.getMessage());
    }
    return conn;
  }
  
  public String getJndiLocation()
  {
    return jndiLocation;
  }
  
  public void setJndiLocation(String jndiLocation)
  {
    this.jndiLocation = jndiLocation;
  }
  
  private DataSource lookupDataSource()
    throws NamingException, SQLException
  {
    Context ctx = new InitialContext();
    Object obj = ctx.lookup(jndiLocation);
    
    DataSource ds = (DataSource)obj;
    if (ds == null) {
      throw new SQLException("Failed to obtain data source from JNDI location " + jndiLocation);
    }
    return ds;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.db.JNDIConnectionSource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core;

import ch.qos.logback.core.status.ErrorStatus;
import ch.qos.logback.core.status.InfoStatus;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileAppender<E>
  extends WriterAppender<E>
{
  protected boolean append = true;
  protected String fileName = null;
  protected boolean bufferedIO = false;
  protected int bufferSize = 8192;
  
  public void setFile(String file)
  {
    String val = file.trim();
    fileName = val;
  }
  
  public boolean getAppend()
  {
    return append;
  }
  
  public String getFile()
  {
    return fileName;
  }
  
  public void start()
  {
    int errors = 0;
    if (fileName != null)
    {
      if (bufferedIO)
      {
        immediateFlush = false;
        addStatus(new InfoStatus("Setting immediateFlush to false on account of bufferedIO option", this));
      }
      try
      {
        setFile();
      }
      catch (IOException e)
      {
        errors++;
        
        addStatus(new ErrorStatus("setFile(" + fileName + "," + append + ") call failed.", this, e));
      }
    }
    else
    {
      errors++;
      addStatus(new ErrorStatus("File option not set for appender [" + name + "].", this));
    }
    if (errors == 0) {
      super.start();
    }
  }
  
  public synchronized void setFile()
    throws IOException
  {
    closeWriter();
    
    writer = createWriter(new FileOutputStream(fileName, append));
    if (bufferedIO) {
      writer = new BufferedWriter(writer, bufferSize);
    }
    writeHeader();
  }
  
  public boolean isBufferedIO()
  {
    return bufferedIO;
  }
  
  public void setBufferedIO(boolean bufferedIO)
  {
    this.bufferedIO = bufferedIO;
  }
  
  public int getBufferSize()
  {
    return bufferSize;
  }
  
  public void setBufferSize(int bufferSize)
  {
    this.bufferSize = bufferSize;
  }
  
  public void setAppend(boolean append)
  {
    this.append = append;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.FileAppender
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.filter;

import ch.qos.logback.core.spi.FilterReply;

public abstract class AbstractMatcherFilter
  extends Filter
{
  protected FilterReply onMatch = FilterReply.NEUTRAL;
  protected FilterReply onMismatch = FilterReply.NEUTRAL;
  
  public final void setOnMatch(FilterReply reply)
  {
    onMatch = reply;
  }
  
  public final void setOnMismatch(FilterReply reply)
  {
    onMismatch = reply;
  }
  
  public final FilterReply getOnMatch()
  {
    return onMatch;
  }
  
  public final FilterReply getOnMismatch()
  {
    return onMismatch;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.filter.AbstractMatcherFilter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.filter;

import ch.qos.logback.core.boolex.EvaluationException;
import ch.qos.logback.core.boolex.EventEvaluator;
import ch.qos.logback.core.spi.FilterReply;

public class EvaluatorFilter
  extends AbstractMatcherFilter
{
  EventEvaluator evaluator;
  
  public void start()
  {
    if (evaluator != null) {
      super.start();
    } else {
      addError("No evaluator set for filter " + getName());
    }
  }
  
  public EventEvaluator getEvaluator()
  {
    return evaluator;
  }
  
  public void setEvaluator(EventEvaluator evaluator)
  {
    this.evaluator = evaluator;
  }
  
  public FilterReply decide(Object event)
  {
    if ((!isStarted()) || (!evaluator.isStarted())) {
      return FilterReply.NEUTRAL;
    }
    try
    {
      if (evaluator.evaluate(event)) {
        return onMatch;
      }
      return onMismatch;
    }
    catch (EvaluationException e)
    {
      addError("Evaluator " + evaluator.getName() + " threw an exception", e);
    }
    return FilterReply.NEUTRAL;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.filter.EvaluatorFilter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.filter;

import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.FilterReply;
import ch.qos.logback.core.spi.LifeCycle;

public abstract class Filter
  extends ContextAwareBase
  implements LifeCycle
{
  private Filter next;
  private String name;
  boolean start = false;
  
  public void start()
  {
    start = true;
  }
  
  public boolean isStarted()
  {
    return start;
  }
  
  public void stop()
  {
    start = false;
  }
  
  public abstract FilterReply decide(Object paramObject);
  
  public void setNext(Filter next)
  {
    this.next = next;
  }
  
  public Filter getNext()
  {
    return next;
  }
  
  public String getName()
  {
    return name;
  }
  
  public void setName(String name)
  {
    this.name = name;
  }
}

/* Location:
 * Qualified Name:     ch.qos.logback.core.filter.Filter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package ch.qos.logback.core.helpers;

public class CyclicBuffer<E>
{
  E[] ea;
  int first;
  int last;
  int numElems;
  int maxSize;
  
  public CyclicBuffer(int maxSize)
    throws IllegalArgumentException
  {
    if (maxSize < 1) {
      throw new IllegalArgumentException("The maxSize argument (" + maxSize + ") is not a positive integer.");
    }
    init(maxSize);
  }
  
  private void init(int maxSize)
  {
    this.maxSize = maxSize;
    ea = ((Object[])new Object[maxSize]);
    first = 0;
    last = 0;
    numElems = 0;
  }
  
  public void clear()
  {
    init(maxSize);
  }
  
  public void add(E event)
  {
    ea[last] = event;
    if (++last == maxSize) {
      last = 0;
    }
    if (numElems < maxSize) {
      numElems += 1;
    } else if (++first == maxSize) {
      first = 0;
    }
  }
  
  public E get(int i)
  {
    if ((i < 0) || (i >= numElems)) {
      return null;
    }
    return (E)ea[((first + i) % maxSize)];
  }
  
  public int getMaxSize()
  {
    return maxSize;
  }
  
  public E get()
  {
    E r = null;
    if (numElems > 0)
    {
      numElems -= 1;
      r = ea[first];
      ea[first] = null;
      if (++first == maxSize) {
        first = 0;
      }
    }
    return r;
1 2 3 4 5 6 7

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd