You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/06/28 21:34:40 UTC
svn commit: r417856 [9/22] - in /incubator/openjpa/trunk/openjpa-lib: java/
main/ main/java/ main/java/org/apache/openjpa/lib/ant/
main/java/org/apache/openjpa/lib/conf/ main/java/org/apache/openjpa/lib/jdbc/
main/java/org/apache/openjpa/lib/log/ main/...
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java Wed Jun 28 12:34:33 2006
@@ -15,95 +15,70 @@
*/
package org.apache.openjpa.lib.jdbc;
-
import java.sql.*;
-/**
+/**
* <p>A {@link SQLException} that contains information about
* the {@link Statement} SQL that caused the exception.</p>
- *
- * @author Marc Prud'hommeaux
- * @nojavadoc
- */
-public class ReportingSQLException
- extends SQLException
-{
- private final transient Statement _stmnt;
- private final SQLException _sqle;
-
- public ReportingSQLException (SQLException sqle,
- Statement stmnt, String sql)
- {
- super (getExceptionMessage (sqle, stmnt, sql));
- this._sqle = sqle;
- this._stmnt = stmnt;
- setNextException (sqle);
- }
-
-
- public ReportingSQLException (SQLException sqle, String sql)
- {
- this (sqle, null, sql);
- }
-
-
- public ReportingSQLException (SQLException sqle, Statement stmnt)
- {
- this (sqle, stmnt, null);
- }
-
-
- /**
- * Returns the SQL state of the underlying {@link SQLException}.
- */
- public String getSQLState ()
- {
- return _sqle.getSQLState ();
- }
-
-
- /**
- * Returns the error code of the underlying {@link SQLException}.
- */
- public int getErrorCode ()
- {
- return _sqle.getErrorCode ();
- }
-
-
- /**
- * Returns the {@link Statement} that caused the exception.
- */
- public Statement getStatement ()
- {
- return _stmnt;
- }
-
-
- private static String getExceptionMessage (SQLException sqle,
- Statement stmnt, String sql)
- {
- try
- {
- if (stmnt != null)
- return sqle.getMessage () + " {" + stmnt + "} "
- + "[code=" + sqle.getErrorCode () + ", state="
- + sqle.getSQLState () + "]";
- else if (sql != null)
- return sqle.getMessage () + " {" + sql + "} "
- + "[code=" + sqle.getErrorCode () + ", state="
- + sqle.getSQLState () + "]";
- else
- return sqle.getMessage () + " "
- + "[code=" + sqle.getErrorCode () + ", state="
- + sqle.getSQLState () + "]";
- }
- catch (Throwable t)
- {
- return sqle.getMessage ();
- }
- }
+ *
+ * @author Marc Prud'hommeaux
+ * @nojavadoc */
+public class ReportingSQLException extends SQLException {
+ private final transient Statement _stmnt;
+ private final SQLException _sqle;
+
+ public ReportingSQLException(SQLException sqle, Statement stmnt, String sql) {
+ super(getExceptionMessage(sqle, stmnt, sql));
+ this._sqle = sqle;
+ this._stmnt = stmnt;
+ setNextException(sqle);
+ }
+
+ public ReportingSQLException(SQLException sqle, String sql) {
+ this(sqle, null, sql);
+ }
+
+ public ReportingSQLException(SQLException sqle, Statement stmnt) {
+ this(sqle, stmnt, null);
+ }
+
+ /**
+ * Returns the SQL state of the underlying {@link SQLException}.
+ */
+ public String getSQLState() {
+ return _sqle.getSQLState();
+ }
+
+ /**
+ * Returns the error code of the underlying {@link SQLException}.
+ */
+ public int getErrorCode() {
+ return _sqle.getErrorCode();
+ }
+
+ /**
+ * Returns the {@link Statement} that caused the exception.
+ */
+ public Statement getStatement() {
+ return _stmnt;
+ }
+
+ private static String getExceptionMessage(SQLException sqle,
+ Statement stmnt, String sql) {
+ try {
+ if (stmnt != null) {
+ return sqle.getMessage() + " {" + stmnt + "} " + "[code=" +
+ sqle.getErrorCode() + ", state=" + sqle.getSQLState() + "]";
+ } else if (sql != null) {
+ return sqle.getMessage() + " {" + sql + "} " + "[code=" +
+ sqle.getErrorCode() + ", state=" + sqle.getSQLState() + "]";
+ } else {
+ return sqle.getMessage() + " " + "[code=" +
+ sqle.getErrorCode() + ", state=" + sqle.getSQLState() + "]";
+ }
+ } catch (Throwable t) {
+ return sqle.getMessage();
+ }
+ }
}
-
-
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java Wed Jun 28 12:34:33 2006
@@ -15,317 +15,269 @@
*/
package org.apache.openjpa.lib.jdbc;
-
import java.util.*;
/*
- * Lots of this could be abstracted out into a word-wrapping class.
+ * Lots of this could be abstracted out into a word-wrapping class.
*/
/**
- * <p>Converts single-line SQL strings into nicely-formatted
- * multi-line, indented statements.</p>
+ * <p>Converts single-line SQL strings into nicely-formatted
+ * multi-line, indented statements.</p>
*
- <p>Example:
- <code>SELECT * from PERSON t0, COMPANY t1 WHERE t0.ID = 10 AND \
+ <p>Example:
+ <code>SELECT * from PERSON t0, COMPANY t1 WHERE t0.ID = 10 AND \
t0.COMPANY_ID = t1.ID AND t1.NAME = 'OpenJPA'</code>
- becomes
- <code>SELECT *
- FROM PERSON t0, COMPANY t1
+ becomes
+ <code>SELECT *
+ FROM PERSON t0, COMPANY t1
WHERE t0.ID = 10 AND t0.COMPANY_ID = t1.ID AND t1.NAME = 'OpenJPA'\
</code>
- and
- <code>INSERT INTO PERSON VALUES ('Patrick', 'Linskey', 'OpenJPA', \
+ and
+ <code>INSERT INTO PERSON VALUES ('Patrick', 'Linskey', 'OpenJPA', \
'202 595 2064 x1111')</code>
- becomes
- <code>INSERT INTO PERSON VALUES ('Patrick', 'Linskey', 'OpenJPA', '202
+ becomes
+ <code>INSERT INTO PERSON VALUES ('Patrick', 'Linskey', 'OpenJPA', '202
595 2064 x1111')</code>
- etc.</p>
+ etc.</p>
*
- * @author Patrick Linskey
+ * @author Patrick Linskey
*/
-public class SQLFormatter
-{
- private boolean multiLine = false;
- private boolean doubleSpace = true;
- private String newline = System.getProperty ("line.separator");
- private int lineLength = 72;
- private String wrapIndent = " ";
- private String clauseIndent = " ";
-
-
- private static final String[] selectSeparators = new String[] {
- "FROM ",
- "WHERE ",
- "ORDER BY ", // ### is this order correct?
- "GROUP BY ",
- "HAVING ",
- };
-
- private static final String[] insertSeparators = new String[] {
- "VALUES ",
- };
-
- private static final String[] updateSeparators = new String[] {
- "SET ",
- "WHERE ",
- };
-
- private static final String[] deleteSeparators = new String[] {
- "WHERE ",
- };
-
- private static final String[] createTableSeparators = new String[] {
- "( ",
- };
-
- private static final String[] createIndexSeparators = new String[] {
- "ON ",
- "( ",
- };
-
-
- public void setNewline (String val)
- {
- newline = val;
- }
-
-
- public String getNewline ()
- {
- return newline;
- }
-
-
- public void setLineLength (int val)
- {
- lineLength = val;
- }
-
-
- public int getLineLength ()
- {
- return lineLength;
- }
-
-
- public void setWrapIndent (String val)
- {
- wrapIndent = val;
- }
-
-
- public String getWrapIndent ()
- {
- return wrapIndent;
- }
-
-
- public void setClauseIndent (String val)
- {
- clauseIndent = val;
- }
-
-
- public String getClauseIndent ()
- {
- return clauseIndent;
- }
-
-
- /**
- * If true, then try to parse multi-line SQL statements.
- */
- public void setMultiLine (boolean multiLine)
- {
- this.multiLine = multiLine;
- }
-
-
- /**
- * If true, then try to parse multi-line SQL statements.
- */
- public boolean getMultiLine ()
- {
- return this.multiLine;
- }
-
-
-
- /**
- * If true, then output two lines after multi-line statements.
- */
- public void setDoubleSpace (boolean doubleSpace)
- {
- this.doubleSpace = doubleSpace;
- }
-
-
- /**
- * If true, then output two lines after multi-line statements.
- */
- public boolean getDoubleSpace ()
- {
- return this.doubleSpace;
- }
-
-
-
- public Object prettyPrint (Object sqlObject)
- {
- if (!multiLine)
- {
- return prettyPrintLine (sqlObject);
- }
- else
- {
- StringBuffer sql = new StringBuffer (sqlObject.toString ());
- StringBuffer buf = new StringBuffer (sql.length ());
-
- while (sql.length () > 0)
- {
- String line = null;
-
- int index = Math.max (sql.toString ().indexOf (";\n"),
- sql.toString ().indexOf (";\r"));
- if (index == -1)
- line = sql.toString ();
- else
- line = sql.substring (0, index + 2);
-
- // remove the current line from the sql buffer
- sql.delete (0, line.length ());
-
- buf.append (prettyPrintLine (line));
- for (int i = 0; i < 1 + (getDoubleSpace () ? 1 : 0); i++)
- buf.append (System.getProperty ("line.separator"));
- }
-
- return buf.toString ();
- }
- }
-
-
- private Object prettyPrintLine (Object sqlObject)
- {
- String sql = sqlObject.toString ().trim ();
- String lowerCaseSql = sql.toLowerCase ();
-
- String[] separators;
- if (lowerCaseSql.startsWith ("select"))
- separators = selectSeparators;
- else if (lowerCaseSql.startsWith ("insert"))
- separators = insertSeparators;
- else if (lowerCaseSql.startsWith ("update"))
- separators = updateSeparators;
- else if (lowerCaseSql.startsWith ("delete"))
- separators = deleteSeparators;
- else if (lowerCaseSql.startsWith ("create table"))
- separators = createTableSeparators;
- else if (lowerCaseSql.startsWith ("create index"))
- separators = createIndexSeparators;
- else
- separators = new String[0];
-
- int start = 0;
- int end = -1;
- StringBuffer clause;
- List clauses = new ArrayList ();
- clauses.add (new StringBuffer ());
- for (int i = 0; i < separators.length; i++)
- {
- end = lowerCaseSql.indexOf (" " + separators[i].toLowerCase (),
- start);
- if (end == -1)
- break;
-
- clause = (StringBuffer) clauses.get (clauses.size () - 1);
- clause.append (sql.substring (start, end));
-
- clause = new StringBuffer ();
- clauses.add (clause);
- clause.append (clauseIndent);
- clause.append (separators[i]);
-
- start = end + 1 + separators[i].length ();
- }
-
- clause = (StringBuffer) clauses.get (clauses.size () - 1);
- clause.append (sql.substring (start));
-
-
- StringBuffer pp = new StringBuffer (sql.length ());
- for (Iterator iter = clauses.iterator (); iter.hasNext (); )
- {
- pp.append (wrapLine (((StringBuffer) iter.next ()).toString ()));
- if (iter.hasNext ())
- pp.append (newline);
- }
-
- return pp.toString ();
- }
-
-
- private String wrapLine (String line)
- {
- StringBuffer lines = new StringBuffer (line.length ());
-
- // ensure that any leading whitespace is preserved.
- for (int i = 0; i < line.length () &&
- (line.charAt (i) == ' ' || line.charAt (i) == '\t'); i++)
- {
- lines.append (line.charAt (i));
- }
-
- StringTokenizer tok = new StringTokenizer (line);
- int length = 0;
- String elem;
- while (tok.hasMoreTokens ())
- {
- elem = tok.nextToken ();
- length += elem.length ();
-
- // if we would have exceeded the max, write out a newline
- // before writing the elem.
- if (length >= lineLength)
- {
- lines.append (newline);
- lines.append (wrapIndent);
- lines.append (elem);
- lines.append (' ');
- length = wrapIndent.length () + elem.length () + 1;
- continue;
- }
-
- // if the current length is greater than the max, then the
- // last word alone was too long, so just write out a
- // newline and move on.
- if (elem.length () >= lineLength)
- {
- lines.append (elem);
- if (tok.hasMoreTokens ())
- lines.append (newline);
- lines.append (wrapIndent);
- length = wrapIndent.length ();
- continue;
- }
-
- lines.append (elem);
- lines.append (' ');
- length++;
- }
-
- return lines.toString ();
- }
-
-
- public static void main (String [] args)
- {
- SQLFormatter formatter = new SQLFormatter ();
- for (int i = 0; i < args.length; i++)
- {
- System.out.println (formatter.prettyPrint (args[i]));
- }
- }
+public class SQLFormatter {
+ private static final String[] selectSeparators = new String[] {
+ "FROM ", "WHERE ", "ORDER BY ", // ### is this order correct?
+ "GROUP BY ", "HAVING ",
+ };
+ private static final String[] insertSeparators = new String[] { "VALUES ", };
+ private static final String[] updateSeparators = new String[] {
+ "SET ", "WHERE ",
+ };
+ private static final String[] deleteSeparators = new String[] { "WHERE ", };
+ private static final String[] createTableSeparators = new String[] { "( ", };
+ private static final String[] createIndexSeparators = new String[] {
+ "ON ", "( ",
+ };
+ private boolean multiLine = false;
+ private boolean doubleSpace = true;
+ private String newline = System.getProperty("line.separator");
+ private int lineLength = 72;
+ private String wrapIndent = " ";
+ private String clauseIndent = " ";
+
+ public void setNewline(String val) {
+ newline = val;
+ }
+
+ public String getNewline() {
+ return newline;
+ }
+
+ public void setLineLength(int val) {
+ lineLength = val;
+ }
+
+ public int getLineLength() {
+ return lineLength;
+ }
+
+ public void setWrapIndent(String val) {
+ wrapIndent = val;
+ }
+
+ public String getWrapIndent() {
+ return wrapIndent;
+ }
+
+ public void setClauseIndent(String val) {
+ clauseIndent = val;
+ }
+
+ public String getClauseIndent() {
+ return clauseIndent;
+ }
+
+ /**
+ * If true, then try to parse multi-line SQL statements.
+ */
+ public void setMultiLine(boolean multiLine) {
+ this.multiLine = multiLine;
+ }
+
+ /**
+ * If true, then try to parse multi-line SQL statements.
+ */
+ public boolean getMultiLine() {
+ return this.multiLine;
+ }
+
+ /**
+ * If true, then output two lines after multi-line statements.
+ */
+ public void setDoubleSpace(boolean doubleSpace) {
+ this.doubleSpace = doubleSpace;
+ }
+
+ /**
+ * If true, then output two lines after multi-line statements.
+ */
+ public boolean getDoubleSpace() {
+ return this.doubleSpace;
+ }
+
+ public Object prettyPrint(Object sqlObject) {
+ if (!multiLine) {
+ return prettyPrintLine(sqlObject);
+ } else {
+ StringBuffer sql = new StringBuffer(sqlObject.toString());
+ StringBuffer buf = new StringBuffer(sql.length());
+
+ while (sql.length() > 0) {
+ String line = null;
+
+ int index = Math.max(sql.toString().indexOf(";\n"),
+ sql.toString().indexOf(";\r"));
+
+ if (index == -1) {
+ line = sql.toString();
+ } else {
+ line = sql.substring(0, index + 2);
+ }
+
+ // remove the current line from the sql buffer
+ sql.delete(0, line.length());
+
+ buf.append(prettyPrintLine(line));
+
+ for (int i = 0; i < (1 + (getDoubleSpace() ? 1 : 0)); i++)
+ buf.append(System.getProperty("line.separator"));
+ }
+
+ return buf.toString();
+ }
+ }
+
+ private Object prettyPrintLine(Object sqlObject) {
+ String sql = sqlObject.toString().trim();
+ String lowerCaseSql = sql.toLowerCase();
+
+ String[] separators;
+
+ if (lowerCaseSql.startsWith("select")) {
+ separators = selectSeparators;
+ } else if (lowerCaseSql.startsWith("insert")) {
+ separators = insertSeparators;
+ } else if (lowerCaseSql.startsWith("update")) {
+ separators = updateSeparators;
+ } else if (lowerCaseSql.startsWith("delete")) {
+ separators = deleteSeparators;
+ } else if (lowerCaseSql.startsWith("create table")) {
+ separators = createTableSeparators;
+ } else if (lowerCaseSql.startsWith("create index")) {
+ separators = createIndexSeparators;
+ } else {
+ separators = new String[0];
+ }
+
+ int start = 0;
+ int end = -1;
+ StringBuffer clause;
+ List clauses = new ArrayList();
+ clauses.add(new StringBuffer());
+
+ for (int i = 0; i < separators.length; i++) {
+ end = lowerCaseSql.indexOf(" " + separators[i].toLowerCase(), start);
+
+ if (end == -1) {
+ break;
+ }
+
+ clause = (StringBuffer) clauses.get(clauses.size() - 1);
+ clause.append(sql.substring(start, end));
+
+ clause = new StringBuffer();
+ clauses.add(clause);
+ clause.append(clauseIndent);
+ clause.append(separators[i]);
+
+ start = end + 1 + separators[i].length();
+ }
+
+ clause = (StringBuffer) clauses.get(clauses.size() - 1);
+ clause.append(sql.substring(start));
+
+ StringBuffer pp = new StringBuffer(sql.length());
+
+ for (Iterator iter = clauses.iterator(); iter.hasNext();) {
+ pp.append(wrapLine(((StringBuffer) iter.next()).toString()));
+
+ if (iter.hasNext()) {
+ pp.append(newline);
+ }
+ }
+
+ return pp.toString();
+ }
+
+ private String wrapLine(String line) {
+ StringBuffer lines = new StringBuffer(line.length());
+
+ // ensure that any leading whitespace is preserved.
+ for (int i = 0;
+ (i < line.length()) &&
+ ((line.charAt(i) == ' ') || (line.charAt(i) == '\t')); i++) {
+ lines.append(line.charAt(i));
+ }
+
+ StringTokenizer tok = new StringTokenizer(line);
+ int length = 0;
+ String elem;
+
+ while (tok.hasMoreTokens()) {
+ elem = tok.nextToken();
+ length += elem.length();
+
+ // if we would have exceeded the max, write out a newline
+ // before writing the elem.
+ if (length >= lineLength) {
+ lines.append(newline);
+ lines.append(wrapIndent);
+ lines.append(elem);
+ lines.append(' ');
+ length = wrapIndent.length() + elem.length() + 1;
+
+ continue;
+ }
+
+ // if the current length is greater than the max, then the
+ // last word alone was too long, so just write out a
+ // newline and move on.
+ if (elem.length() >= lineLength) {
+ lines.append(elem);
+
+ if (tok.hasMoreTokens()) {
+ lines.append(newline);
+ }
+
+ lines.append(wrapIndent);
+ length = wrapIndent.length();
+
+ continue;
+ }
+
+ lines.append(elem);
+ lines.append(' ');
+ length++;
+ }
+
+ return lines.toString();
+ }
+
+ public static void main(String[] args) {
+ SQLFormatter formatter = new SQLFormatter();
+
+ for (int i = 0; i < args.length; i++) {
+ System.out.println(formatter.prettyPrint(args[i]));
+ }
+ }
}
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/package.html
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/package.html?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/package.html (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/jdbc/package.html Wed Jun 28 12:34:33 2006
@@ -1,18 +1,3 @@
-<!--
- Copyright 2006 The Apache Software Foundation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
<html>
<body>
<p><strong>Database Connectivity</strong></p>
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/AbstractLog.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/AbstractLog.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/AbstractLog.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/AbstractLog.java Wed Jun 28 12:34:33 2006
@@ -15,181 +15,145 @@
*/
package org.apache.openjpa.lib.log;
-
import java.io.*;
-/**
+/**
* A simple implementation of the {@link Log} interface. Writes
* output to stdout.
*
- * @author Patrick Linskey
+ * @author Patrick Linskey
*/
-public abstract class AbstractLog
- implements Log
-{
- /**
- * Check to see if the specified logging level is enabled.
- */
- protected abstract boolean isEnabled (short level);
-
-
- /**
- * Send the specified log message to the handler.
- *
- * @param level the level of the log message
- * @param message the message to send
- * @param t the Throwable, or null if this is not an error
- */
- protected abstract void log (short level, String message, Throwable t);
-
-
- public boolean isTraceEnabled ()
- {
- return isEnabled (TRACE);
- }
-
-
- public boolean isDebugEnabled ()
- {
- return isEnabled (DEBUG);
- }
-
-
- public boolean isInfoEnabled ()
- {
- return isEnabled (INFO);
- }
-
-
- public boolean isWarnEnabled ()
- {
- return isEnabled (WARN);
- }
-
-
- public boolean isErrorEnabled ()
- {
- return isEnabled (ERROR);
- }
-
-
- public boolean isFatalEnabled ()
- {
- return isEnabled (FATAL);
- }
-
-
- public void trace (Object message)
- {
- trace (message, throwableParam (message, null));
- }
-
-
- public void trace (Object message, Throwable t)
- {
- if (isTraceEnabled ())
- log (TRACE, toString (message), throwableParam (message, t));
- }
-
-
- public void debug (Object message)
- {
- debug (message, throwableParam (message, null));
- }
-
-
- public void debug (Object message, Throwable t)
- {
- if (isDebugEnabled ())
- log (DEBUG, toString (message), throwableParam (message, t));
- }
-
-
- public void info (Object message)
- {
- info (message, throwableParam (message, null));
- }
-
-
- public void info (Object message, Throwable t)
- {
- if (isInfoEnabled ())
- log (INFO, toString (message), throwableParam (message, t));
- }
-
-
- public void warn (Object message)
- {
- warn (message, throwableParam (message, null));
- }
-
-
- public void warn (Object message, Throwable t)
- {
- if (isWarnEnabled ())
- log (WARN, toString (message), throwableParam (message, t));
- }
-
-
- public void error (Object message)
- {
- error (message, throwableParam (message, null));
- }
-
-
- public void error (Object message, Throwable t)
- {
- if (isErrorEnabled ())
- log (ERROR, toString (message), throwableParam (message, t));
- }
-
-
- public void fatal (Object message)
- {
- fatal (message, throwableParam (message, null));
- }
-
-
- public void fatal (Object message, Throwable t)
- {
- if (isFatalEnabled ())
- log (FATAL, toString (message), throwableParam (message, t));
- }
-
-
- /**
- * Utility method to obtain a stack trace as a String.
- */
- protected static String getStackTrace (Throwable t)
- {
- StringWriter sw = new StringWriter ();
- PrintWriter pw = new PrintWriter (sw, true);
- t.printStackTrace (pw);
- pw.close ();
- return sw.toString ();
- }
-
-
- /**
- * If either given instance is a throwable, return it.
- */
- private static Throwable throwableParam (Object message, Throwable t)
- {
- if (t != null)
- return t;
- if (message instanceof Throwable)
- return (Throwable)message;
-
- return null;
- }
-
-
- /**
- * Efficiently turn the given object into a string.
- */
- private static String toString (Object o)
- {
- return (o == null) ? "null" : o.toString ();
- }
+public abstract class AbstractLog implements Log {
+ /**
+ * Check to see if the specified logging level is enabled.
+ */
+ protected abstract boolean isEnabled(short level);
+
+ /**
+ * Send the specified log message to the handler.
+ *
+ * @param level the level of the log message
+ * @param message the message to send
+ * @param t the Throwable, or null if this is not an error
+ */
+ protected abstract void log(short level, String message, Throwable t);
+
+ public boolean isTraceEnabled() {
+ return isEnabled(TRACE);
+ }
+
+ public boolean isDebugEnabled() {
+ return isEnabled(DEBUG);
+ }
+
+ public boolean isInfoEnabled() {
+ return isEnabled(INFO);
+ }
+
+ public boolean isWarnEnabled() {
+ return isEnabled(WARN);
+ }
+
+ public boolean isErrorEnabled() {
+ return isEnabled(ERROR);
+ }
+
+ public boolean isFatalEnabled() {
+ return isEnabled(FATAL);
+ }
+
+ public void trace(Object message) {
+ trace(message, throwableParam(message, null));
+ }
+
+ public void trace(Object message, Throwable t) {
+ if (isTraceEnabled()) {
+ log(TRACE, toString(message), throwableParam(message, t));
+ }
+ }
+
+ public void debug(Object message) {
+ debug(message, throwableParam(message, null));
+ }
+
+ public void debug(Object message, Throwable t) {
+ if (isDebugEnabled()) {
+ log(DEBUG, toString(message), throwableParam(message, t));
+ }
+ }
+
+ public void info(Object message) {
+ info(message, throwableParam(message, null));
+ }
+
+ public void info(Object message, Throwable t) {
+ if (isInfoEnabled()) {
+ log(INFO, toString(message), throwableParam(message, t));
+ }
+ }
+
+ public void warn(Object message) {
+ warn(message, throwableParam(message, null));
+ }
+
+ public void warn(Object message, Throwable t) {
+ if (isWarnEnabled()) {
+ log(WARN, toString(message), throwableParam(message, t));
+ }
+ }
+
+ public void error(Object message) {
+ error(message, throwableParam(message, null));
+ }
+
+ public void error(Object message, Throwable t) {
+ if (isErrorEnabled()) {
+ log(ERROR, toString(message), throwableParam(message, t));
+ }
+ }
+
+ public void fatal(Object message) {
+ fatal(message, throwableParam(message, null));
+ }
+
+ public void fatal(Object message, Throwable t) {
+ if (isFatalEnabled()) {
+ log(FATAL, toString(message), throwableParam(message, t));
+ }
+ }
+
+ /**
+ * Utility method to obtain a stack trace as a String.
+ */
+ protected static String getStackTrace(Throwable t) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw, true);
+ t.printStackTrace(pw);
+ pw.close();
+
+ return sw.toString();
+ }
+
+ /**
+ * If either given instance is a throwable, return it.
+ */
+ private static Throwable throwableParam(Object message, Throwable t) {
+ if (t != null) {
+ return t;
+ }
+
+ if (message instanceof Throwable) {
+ return (Throwable) message;
+ }
+
+ return null;
+ }
+
+ /**
+ * Efficiently turn the given object into a string.
+ */
+ private static String toString(Object o) {
+ return (o == null) ? "null" : o.toString();
+ }
}
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/CommonsLogFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/CommonsLogFactory.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/CommonsLogFactory.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/CommonsLogFactory.java Wed Jun 28 12:34:33 2006
@@ -15,158 +15,111 @@
*/
package org.apache.openjpa.lib.log;
+import java.util.*;
+
/**
- * {@link LogFactory} implementation that delegates to the commons logging
- * framework.
+ * {@link LogFactory} implementation that delegates to the commons logging
+ * framework.
*
- * @author Patrick Linskey
+ * @author Patrick Linskey
*/
-public class CommonsLogFactory
- extends LogFactoryAdapter
-{
- private org.apache.commons.logging.LogFactory _factory;
-
-
- public CommonsLogFactory ()
- {
- _factory = org.apache.commons.logging.LogFactory.getFactory ();
- }
-
-
- protected org.apache.openjpa.lib.log.Log newLogAdapter (String channel)
- {
- return new LogAdapter (_factory.getInstance (channel));
- }
-
-
- /**
- * Adapts a commons logging log to the {@link org.apache.openjpa.lib.log.Log}
- * interface.
- */
- public static class LogAdapter
- implements org.apache.openjpa.lib.log.Log
- {
- private org.apache.commons.logging.Log _log;
-
-
- private LogAdapter (org.apache.commons.logging.Log wrapee)
- {
- _log = wrapee;
- }
-
-
- public org.apache.commons.logging.Log getDelegate ()
- {
- return _log;
- }
-
-
- public boolean isDebugEnabled ()
- {
- return _log.isDebugEnabled ();
- }
-
-
- public boolean isErrorEnabled ()
- {
- return _log.isErrorEnabled ();
- }
-
-
- public boolean isFatalEnabled ()
- {
- return _log.isFatalEnabled ();
- }
-
-
- public boolean isInfoEnabled ()
- {
- return _log.isInfoEnabled ();
- }
-
-
- public boolean isTraceEnabled ()
- {
- return _log.isTraceEnabled ();
- }
-
-
- public boolean isWarnEnabled ()
- {
- return _log.isWarnEnabled ();
- }
-
-
- public void trace (Object o)
- {
- _log.trace (o);
- }
-
-
- public void trace (Object o, Throwable t)
- {
- _log.trace (o, t);
- }
-
-
- public void debug (Object o)
- {
- _log.debug (o);
- }
-
-
- public void debug (Object o, Throwable t)
- {
- _log.debug (o, t);
- }
-
-
- public void info (Object o)
- {
- _log.info (o);
- }
-
-
- public void info (Object o, Throwable t)
- {
- _log.info (o, t);
- }
-
-
- public void warn (Object o)
- {
- _log.warn (o);
- }
-
-
- public void warn (Object o, Throwable t)
- {
- _log.warn (o, t);
- }
-
-
- public void error (Object o)
- {
- _log.error (o);
- }
-
-
- public void error (Object o, Throwable t)
- {
- _log.error (o, t);
- }
-
-
- public void fatal (Object o)
- {
- _log.fatal (o);
- }
-
+public class CommonsLogFactory extends LogFactoryAdapter {
+ private org.apache.commons.logging.LogFactory _factory;
- public void fatal (Object o, Throwable t)
- {
- _log.fatal (o, t);
- }
- }
+ public CommonsLogFactory() {
+ _factory = org.apache.commons.logging.LogFactory.getFactory();
+ }
+
+ protected org.apache.openjpa.lib.log.Log newLogAdapter(String channel) {
+ return new LogAdapter(_factory.getInstance(channel));
+ }
+
+ /**
+ * Adapts a commons logging log to the {@link org.apache.openjpa.lib.log.Log}
+ * interface.
+ */
+ public static class LogAdapter implements org.apache.openjpa.lib.log.Log {
+ private org.apache.commons.logging.Log _log;
+
+ private LogAdapter(org.apache.commons.logging.Log wrapee) {
+ _log = wrapee;
+ }
+
+ public org.apache.commons.logging.Log getDelegate() {
+ return _log;
+ }
+
+ public boolean isDebugEnabled() {
+ return _log.isDebugEnabled();
+ }
+
+ public boolean isErrorEnabled() {
+ return _log.isErrorEnabled();
+ }
+
+ public boolean isFatalEnabled() {
+ return _log.isFatalEnabled();
+ }
+
+ public boolean isInfoEnabled() {
+ return _log.isInfoEnabled();
+ }
+
+ public boolean isTraceEnabled() {
+ return _log.isTraceEnabled();
+ }
+
+ public boolean isWarnEnabled() {
+ return _log.isWarnEnabled();
+ }
+
+ public void trace(Object o) {
+ _log.trace(o);
+ }
+
+ public void trace(Object o, Throwable t) {
+ _log.trace(o, t);
+ }
+
+ public void debug(Object o) {
+ _log.debug(o);
+ }
+
+ public void debug(Object o, Throwable t) {
+ _log.debug(o, t);
+ }
+
+ public void info(Object o) {
+ _log.info(o);
+ }
+
+ public void info(Object o, Throwable t) {
+ _log.info(o, t);
+ }
+
+ public void warn(Object o) {
+ _log.warn(o);
+ }
+
+ public void warn(Object o, Throwable t) {
+ _log.warn(o, t);
+ }
+
+ public void error(Object o) {
+ _log.error(o);
+ }
+
+ public void error(Object o, Throwable t) {
+ _log.error(o, t);
+ }
+
+ public void fatal(Object o) {
+ _log.fatal(o);
+ }
+
+ public void fatal(Object o, Throwable t) {
+ _log.fatal(o, t);
+ }
+ }
}
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/Log.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/Log.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/Log.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/Log.java Wed Jun 28 12:34:33 2006
@@ -17,149 +17,130 @@
/**
- * Logging interface that is independent of other logging frameworks.
+ * Logging interface that is independent of other logging frameworks.
*
- * @author Patrick Linskey
- * @author Abe White
+ * @author Patrick Linskey
+ * @author Abe White
*/
-public interface Log
-{
- public static final short TRACE = 1;
- public static final short DEBUG = 2;
- public static final short INFO = 3;
- public static final short WARN = 4;
- public static final short ERROR = 5;
- public static final short FATAL = 6;
-
-
- /**
- * Returns if the {@link #TRACE} log level is enabled.
- */
- public boolean isTraceEnabled ();
-
-
- /**
- * Returns if the {@link #DEBUG} log level is enabled.
- */
- public boolean isDebugEnabled ();
-
-
- /**
- * Returns if the {@link #INFO} log level is enabled.
- */
- public boolean isInfoEnabled ();
-
-
- /**
- * Returns if the {@link #WARN} log level is enabled.
- */
- public boolean isWarnEnabled ();
-
-
- /**
- * Returns if the {@link #ERROR} log level is enabled.
- */
- public boolean isErrorEnabled ();
-
-
- /**
- * Returns if the {@link #FATAL} log level is enabled.
- */
- public boolean isFatalEnabled ();
-
-
- /**
- * Write out a log message at the {@link #TRACE}
- * level with the stringification of <code>o</code> as the body
- * of the message.
- */
- public void trace (Object o);
-
-
- /**
- * Write out a log message at the {@link #TRACE}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void trace (Object o, Throwable t);
-
-
- /**
- * Write out a log message at the {@link #DEBUG}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void debug (Object o);
-
-
- /**
- * Write out a log message at the {@link #DEBUG}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void debug (Object o, Throwable t);
-
-
- /**
- * Write out a log message at the {@link #INFO}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void info (Object o);
-
-
- /**
- * Write out a log message at the {@link #INFO}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void info (Object o, Throwable t);
-
-
- /**
- * Write out a log message at the {@link #WARN}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void warn (Object o);
-
-
- /**
- * Write out a log message at the {@link #WARN}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void warn (Object o, Throwable t);
-
-
- /**
- * Write out a log message at the {@link #ERROR}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void error (Object o);
-
-
- /**
- * Write out a log message at the {@link #ERROR}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void error (Object o, Throwable t);
-
-
- /**
- * Write out a log message at the {@link #FATAL}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void fatal (Object o);
-
-
- /**
- * Write out a log message at the {@link #FATAL}
- * level with the stringification of <code>o</code> as the body
- * of the message, also outputting <code>t</code> to the log.
- */
- public void fatal (Object o, Throwable t);
+public interface Log {
+ public static final short TRACE = 1;
+ public static final short DEBUG = 2;
+ public static final short INFO = 3;
+ public static final short WARN = 4;
+ public static final short ERROR = 5;
+ public static final short FATAL = 6;
+
+ /**
+ * Returns if the {@link #TRACE} log level is enabled.
+ */
+ public boolean isTraceEnabled();
+
+ /**
+ * Returns if the {@link #DEBUG} log level is enabled.
+ */
+ public boolean isDebugEnabled();
+
+ /**
+ * Returns if the {@link #INFO} log level is enabled.
+ */
+ public boolean isInfoEnabled();
+
+ /**
+ * Returns if the {@link #WARN} log level is enabled.
+ */
+ public boolean isWarnEnabled();
+
+ /**
+ * Returns if the {@link #ERROR} log level is enabled.
+ */
+ public boolean isErrorEnabled();
+
+ /**
+ * Returns if the {@link #FATAL} log level is enabled.
+ */
+ public boolean isFatalEnabled();
+
+ /**
+ * Write out a log message at the {@link #TRACE}
+ * level with the stringification of <code>o</code> as the body
+ * of the message.
+ */
+ public void trace(Object o);
+
+ /**
+ * Write out a log message at the {@link #TRACE}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void trace(Object o, Throwable t);
+
+ /**
+ * Write out a log message at the {@link #DEBUG}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void debug(Object o);
+
+ /**
+ * Write out a log message at the {@link #DEBUG}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void debug(Object o, Throwable t);
+
+ /**
+ * Write out a log message at the {@link #INFO}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void info(Object o);
+
+ /**
+ * Write out a log message at the {@link #INFO}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void info(Object o, Throwable t);
+
+ /**
+ * Write out a log message at the {@link #WARN}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void warn(Object o);
+
+ /**
+ * Write out a log message at the {@link #WARN}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void warn(Object o, Throwable t);
+
+ /**
+ * Write out a log message at the {@link #ERROR}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void error(Object o);
+
+ /**
+ * Write out a log message at the {@link #ERROR}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void error(Object o, Throwable t);
+
+ /**
+ * Write out a log message at the {@link #FATAL}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void fatal(Object o);
+
+ /**
+ * Write out a log message at the {@link #FATAL}
+ * level with the stringification of <code>o</code> as the body
+ * of the message, also outputting <code>t</code> to the log.
+ */
+ public void fatal(Object o, Throwable t);
}
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java Wed Jun 28 12:34:33 2006
@@ -15,150 +15,105 @@
*/
package org.apache.openjpa.lib.log;
-
import org.apache.log4j.*;
+import java.util.*;
+
/**
- * {@link LogFactory} implementation that delegates to the Log4J framework.
+ * {@link LogFactory} implementation that delegates to the Log4J framework.
*
- * @author Patrick Linskey
+ * @author Patrick Linskey
*/
-public class Log4JLogFactory
- extends LogFactoryAdapter
-{
- protected Log newLogAdapter (String channel)
- {
- return new LogAdapter ((Logger) LogManager.getLogger (channel));
- }
-
-
- /**
- * Adapts a Log4J logger to the {@link org.apache.openjpa.lib.log.Log} interface.
- */
- public static class LogAdapter
- implements Log
- {
- private Logger _log;
-
-
- private LogAdapter (Logger wrapee)
- {
- _log = wrapee;
- }
-
-
- public Logger getDelegate ()
- {
- return _log;
- }
-
-
- public boolean isTraceEnabled ()
- {
- return isDebugEnabled ();
- }
-
-
- public boolean isDebugEnabled ()
- {
- return _log.getEffectiveLevel ().toInt () >= Level.DEBUG_INT;
- }
-
-
- public boolean isInfoEnabled ()
- {
- return _log.getEffectiveLevel ().toInt () >= Level.INFO_INT;
- }
-
-
- public boolean isWarnEnabled ()
- {
- return _log.getEffectiveLevel ().toInt () >= Level.WARN_INT;
- }
-
-
- public boolean isErrorEnabled ()
- {
- return _log.getEffectiveLevel ().toInt () >= Level.ERROR_INT;
- }
-
-
- public boolean isFatalEnabled ()
- {
- return _log.getEffectiveLevel ().toInt () >= Level.FATAL_INT;
- }
-
-
- public void trace (Object o)
- {
- _log.debug (o);
- }
-
-
- public void trace (Object o, Throwable t)
- {
- _log.debug (o, t);
- }
-
-
- public void debug (Object o)
- {
- _log.debug (o);
- }
-
-
- public void debug (Object o, Throwable t)
- {
- _log.debug (o, t);
- }
-
-
- public void info (Object o)
- {
- _log.info (o);
- }
-
-
- public void info (Object o, Throwable t)
- {
- _log.info (o, t);
- }
-
-
- public void warn (Object o)
- {
- _log.warn (o);
- }
-
-
- public void warn (Object o, Throwable t)
- {
- _log.warn (o, t);
- }
-
-
- public void error (Object o)
- {
- _log.error (o);
- }
-
-
- public void error (Object o, Throwable t)
- {
- _log.error (o, t);
- }
-
-
- public void fatal (Object o)
- {
- _log.fatal (o);
- }
-
-
- public void fatal (Object o, Throwable t)
- {
- _log.fatal (o, t);
- }
- }
+public class Log4JLogFactory extends LogFactoryAdapter {
+ protected Log newLogAdapter(String channel) {
+ return new LogAdapter((Logger) LogManager.getLogger(channel));
+ }
+
+ /**
+ * Adapts a Log4J logger to the {@link org.apache.openjpa.lib.log.Log} interface.
+ */
+ public static class LogAdapter implements Log {
+ private Logger _log;
+
+ private LogAdapter(Logger wrapee) {
+ _log = wrapee;
+ }
+
+ public Logger getDelegate() {
+ return _log;
+ }
+
+ public boolean isTraceEnabled() {
+ return isDebugEnabled();
+ }
+
+ public boolean isDebugEnabled() {
+ return _log.getEffectiveLevel().toInt() >= Level.DEBUG_INT;
+ }
+
+ public boolean isInfoEnabled() {
+ return _log.getEffectiveLevel().toInt() >= Level.INFO_INT;
+ }
+
+ public boolean isWarnEnabled() {
+ return _log.getEffectiveLevel().toInt() >= Level.WARN_INT;
+ }
+
+ public boolean isErrorEnabled() {
+ return _log.getEffectiveLevel().toInt() >= Level.ERROR_INT;
+ }
+
+ public boolean isFatalEnabled() {
+ return _log.getEffectiveLevel().toInt() >= Level.FATAL_INT;
+ }
+
+ public void trace(Object o) {
+ _log.debug(o);
+ }
+
+ public void trace(Object o, Throwable t) {
+ _log.debug(o, t);
+ }
+
+ public void debug(Object o) {
+ _log.debug(o);
+ }
+
+ public void debug(Object o, Throwable t) {
+ _log.debug(o, t);
+ }
+
+ public void info(Object o) {
+ _log.info(o);
+ }
+
+ public void info(Object o, Throwable t) {
+ _log.info(o, t);
+ }
+
+ public void warn(Object o) {
+ _log.warn(o);
+ }
+
+ public void warn(Object o, Throwable t) {
+ _log.warn(o, t);
+ }
+
+ public void error(Object o) {
+ _log.error(o);
+ }
+
+ public void error(Object o, Throwable t) {
+ _log.error(o, t);
+ }
+
+ public void fatal(Object o) {
+ _log.fatal(o);
+ }
+
+ public void fatal(Object o, Throwable t) {
+ _log.fatal(o, t);
+ }
+ }
}
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactory.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactory.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactory.java Wed Jun 28 12:34:33 2006
@@ -17,14 +17,13 @@
/**
- * <p>Factory for log instances.</p>
+ * <p>Factory for log instances.</p>
*
- * @author Abe White
+ * @author Abe White
*/
-public interface LogFactory
-{
- /**
- * Return a log for the given channel name.
- */
- public Log getLog (String channel);
+public interface LogFactory {
+ /**
+ * Return a log for the given channel name.
+ */
+ public Log getLog(String channel);
}
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactoryAdapter.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactoryAdapter.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactoryAdapter.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactoryAdapter.java Wed Jun 28 12:34:33 2006
@@ -15,37 +15,36 @@
*/
package org.apache.openjpa.lib.log;
+import org.apache.openjpa.lib.util.concurrent.*;
import java.util.*;
/**
- * <p>Base type that aids in adapting an external log framework to the
- * {@link LogFactory}.</p>
+ * <p>Base type that aids in adapting an external log framework to the
+ * {@link LogFactory}.</p>
*
- * @author Abe White
- */
-public abstract class LogFactoryAdapter
- implements LogFactory
-{
- // cache category to log adapters
- private Map _logs = new HashMap ();
-
-
- public synchronized Log getLog (String channel)
- {
- Log log = (Log) _logs.get (channel);
- if (log == null)
- {
- log = newLogAdapter (channel);
- _logs.put (channel, log);
- }
- return log;
- }
-
-
- /**
- * Return a log adapter for the given channel.
- */
- protected abstract Log newLogAdapter (String channel);
+ * @author Abe White
+ */
+public abstract class LogFactoryAdapter implements LogFactory {
+ // cache category to log adapters
+ private Map _logs = new ConcurrentHashMap();
+
+ public Log getLog(String channel) {
+ // no locking; OK if same adapter created multiple times
+ Log log = (Log) _logs.get(channel);
+
+ if (log == null) {
+ log = newLogAdapter(channel);
+ _logs.put(channel, log);
+ }
+
+ return log;
+ }
+
+ /**
+ * Return a log adapter for the given channel. This method may be called
+ * multiple times for the same channel in concurrent situations.
+ */
+ protected abstract Log newLogAdapter(String channel);
}
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java Wed Jun 28 12:34:33 2006
@@ -15,368 +15,321 @@
*/
package org.apache.openjpa.lib.log;
+import org.apache.openjpa.lib.conf.*;
+import org.apache.openjpa.lib.util.*;
+import org.apache.openjpa.lib.util.concurrent.*;
import java.io.*;
-import java.util.*;
-import org.apache.openjpa.lib.conf.*;
-import org.apache.openjpa.lib.util.*;
+import java.util.*;
/**
- * Default {@link LogFactory} implementation. For ease of automatic
- * configuration, this implementation keys on only the last dot-separated
- * token of the log channel name.
+ * Default {@link LogFactory} implementation. For ease of automatic
+ * configuration, this implementation keys on only the last dot-separated
+ * token of the log channel name.
*
- * @author Patrick Linskey
+ * @author Patrick Linskey
*/
-public class LogFactoryImpl
- implements LogFactory, GenericConfigurable
-{
- private static Localizer _loc = Localizer.forPackage (LogFactoryImpl.class);
-
- public static final String TRACE_STR = _loc.get ("log-trace");
- public static final String DEBUG_STR = _loc.get ("log-debug");
- public static final String INFO_STR = _loc.get ("log-info");
- public static final String WARN_STR = _loc.get ("log-warn");
- public static final String ERROR_STR = _loc.get ("log-error");
- public static final String FATAL_STR = _loc.get ("log-fatal");
-
- public static final String STDOUT = "stdout";
- public static final String STDERR = "stderr";
-
- private static final String NEWLINE = System.getProperty ("line.separator");
-
-
- /**
- * The time at which this factory was initialized.
- */
- protected final long initializationMillis;
-
-
- /**
- * The {@link Log}s that this factory manages, keyed by log
- * channel name.
- */
- private Map _logs = new HashMap (); // HashMap<String,Log>
-
-
- /**
- * The default logging level.
- */
- private short _defaultLogLevel = Log.INFO;
-
-
- private String _diagContext = null;
-
-
- /**
- * Storage for logging level configuration specified at
- * configuration time.
- */
- private Map _configuredLevels = new HashMap (); // HashMap<String,Integer>
-
-
- /**
- * The stream to write to. Defaults to System.err.
- */
- private PrintStream _out = System.err;
-
-
- public LogFactoryImpl ()
- {
- initializationMillis = System.currentTimeMillis ();
- }
-
-
- public synchronized Log getLog (String channel)
- {
- LogImpl l = (LogImpl) _logs.get (channel);
- if (l == null)
- {
- l = newLogImpl ();
- l.setChannel (channel);
- Short lvl = (Short) _configuredLevels.get (shorten (channel));
- l.setLevel (lvl == null ? _defaultLogLevel : lvl.shortValue ());
- _logs.put (channel, l);
- }
- return l;
- }
-
-
- /**
- * Create a new log. The log will be cached.
- */
- protected LogImpl newLogImpl ()
- {
- return new LogImpl ();
- }
-
-
- /**
- * The string name of the default level for unconfigured log channels;
- * used for automatic configuration.
- */
- public void setDefaultLevel (String level)
- {
- _defaultLogLevel = getLevel (level);
- }
-
-
- /**
- * The default level for unconfigured log channels.
- */
- public short getDefaultLevel ()
- {
- return _defaultLogLevel;
- }
-
-
- /**
- * The default level for unconfigured log channels.
- */
- public void setDefaultLevel (short level)
- {
- _defaultLogLevel = level;
- }
-
-
- /**
- * A string to prefix all log messages with. Set to
- * <code>null</code> for no prefix.
- */
- public void setDiagnosticContext (String val)
- {
- _diagContext = val;
- }
-
-
- /**
- * A string to prefix all log messages with. Set to
- * <code>null</code> for no prefix.
- */
- public String getDiagnosticContext ()
- {
- return _diagContext;
- }
-
-
- /**
- * The stream to write to. Recognized values are: <code>stdout</code>
- * and <code>stderr</code>. Any other value will be considered a
- * file name.
- */
- public void setFile (String file)
- {
- if (STDOUT.equals (file))
- _out = System.out;
- else if (STDERR.equals (file))
- _out = System.err;
- else
- {
- File f = Files.getFile (file, null);
- try
- {
- _out = new PrintStream (new FileOutputStream
- (f.getCanonicalPath (), true));
- }
- catch (IOException ioe)
- {
- throw new IllegalArgumentException (_loc.get ("log-bad-file",
- file) + " " + ioe.toString ());
- }
- }
- }
-
-
- /**
- * The stream to write to.
- */
- public PrintStream getStream ()
- {
- return _out;
- }
-
-
- /**
- * The stream to write to.
- */
- public void setStream (PrintStream stream)
- {
- if (stream == null)
- throw new NullPointerException ("stream == null");
- _out = stream;
- }
-
-
- /**
- * Returns a string representation of the specified log level constant.
- */
- public static String getLevelName (short level)
- {
- switch (level)
- {
- case Log.TRACE:
- return TRACE_STR;
- case Log.DEBUG:
- return DEBUG_STR;
- case Log.INFO:
- return INFO_STR;
- case Log.WARN:
- return WARN_STR;
- case Log.ERROR:
- return ERROR_STR;
- case Log.FATAL:
- return FATAL_STR;
- default:
- return _loc.get ("log-unknown");
- }
- }
-
-
- /**
- * Returns a symbolic constant for the specified string level.
- */
- public static short getLevel (String str)
- {
- str = str.toUpperCase ().trim ();
- short val =
- TRACE_STR.equals (str) ? Log.TRACE :
- DEBUG_STR.equals (str) ? Log.DEBUG :
- INFO_STR.equals (str) ? Log.INFO :
- WARN_STR.equals (str) ? Log.WARN :
- ERROR_STR.equals (str) ? Log.ERROR :
- FATAL_STR.equals (str) ? Log.FATAL : -1;
-
- if (val == -1)
- throw new IllegalArgumentException
- (_loc.get ("log-bad-constant", str));
-
- return val;
- }
-
-
- // ---------- GenericConfigurable implementation ----------
-
- public void setInto (Map m)
- {
- if (!m.isEmpty ())
- {
- Map.Entry e;
- for (Iterator iter = m.entrySet ().iterator (); iter.hasNext (); )
- {
- e = (Map.Entry) iter.next ();
- _configuredLevels.put (shorten ((String) e.getKey ()),
- new Short (getLevel ((String) e.getValue ())));
- }
- m.clear ();
- }
- }
-
-
- private static String shorten (String channel)
- {
- return channel.substring (channel.lastIndexOf ('.') + 1);
- }
-
-
- /**
- * A simple implementation of the {@link Log} interface. Writes
- * output to stderr.
- */
- public class LogImpl
- extends AbstractLog
- {
- private short _level = INFO;
- private String _channel;
-
-
- protected boolean isEnabled (short level)
- {
- return level >= _level;
- }
-
-
- protected void log (short level, String message, Throwable t)
- {
- String msg = formatMessage (level, message, t);
- synchronized (_out)
- {
- _out.print (msg);
- }
- }
-
-
- /**
- * Convert <code>message</code> into a string ready to be written to
- * the log. The string should include the terminating newline.
- *
- * @param t may be null
- */
- protected String formatMessage (short level, String message,
- Throwable t)
- {
- // we write to a StringBuffer and then flush it all at
- // once as a single line, since some environments (e.g., JBoss)
- // override the System output stream to flush any calls
- // to write without regard to line breaks, making the
- // output incomprehensibe.
- StringBuffer buf = new StringBuffer ();
-
- buf.append (getOffset ());
- buf.append (" ");
- if (_diagContext != null)
- buf.append (_diagContext).append (" ");
- buf.append (getLevelName (level));
- if (level == INFO || level == WARN)
- buf.append (" ");
- buf.append (" [");
- buf.append (Thread.currentThread ().getName ());
- buf.append ("] ");
- buf.append (_channel);
- buf.append (" - ");
- buf.append (message);
- buf.append (NEWLINE);
-
- if (t != null)
- {
- StringWriter swriter = new StringWriter ();
- PrintWriter pwriter = new PrintWriter (swriter);
- t.printStackTrace (pwriter);
- pwriter.flush ();
- buf.append (swriter.toString ());
- }
- return buf.toString ();
- }
-
-
- private long getOffset ()
- {
- return System.currentTimeMillis () - initializationMillis;
- }
-
-
- public void setChannel (String val)
- {
- _channel = val;
- }
-
-
- public String getChannel ()
- {
- return _channel;
- }
-
-
- public void setLevel (short val)
- {
- _level = val;
- }
-
-
- public short getLevel ()
- {
- return _level;
- }
- }
+public class LogFactoryImpl implements LogFactory, GenericConfigurable {
+ private static Localizer _loc = Localizer.forPackage(LogFactoryImpl.class);
+ public static final String TRACE_STR = _loc.get("log-trace");
+ public static final String DEBUG_STR = _loc.get("log-debug");
+ public static final String INFO_STR = _loc.get("log-info");
+ public static final String WARN_STR = _loc.get("log-warn");
+ public static final String ERROR_STR = _loc.get("log-error");
+ public static final String FATAL_STR = _loc.get("log-fatal");
+ public static final String STDOUT = "stdout";
+ public static final String STDERR = "stderr";
+ private static final String NEWLINE = System.getProperty("line.separator");
+
+ /**
+ * The time at which this factory was initialized.
+ */
+ protected final long initializationMillis;
+
+ /**
+ * The {@link Log}s that this factory manages, keyed by log
+ * channel name.
+ */
+ private Map _logs = new ConcurrentHashMap(); // <String,Log>
+
+ /**
+ * The default logging level.
+ */
+ private short _defaultLogLevel = Log.INFO;
+
+ /**
+ * Storage for logging level configuration specified at
+ * configuration time.
+ */
+ private Map _configuredLevels = new HashMap(); // <String,Integer>
+
+ /**
+ * The stream to write to. Defaults to System.err.
+ */
+ private PrintStream _out = System.err;
+ private String _diagContext = null;
+
+ public LogFactoryImpl() {
+ initializationMillis = System.currentTimeMillis();
+ }
+
+ public Log getLog(String channel) {
+ // no locking; ok if same log created multiple times
+ LogImpl l = (LogImpl) _logs.get(channel);
+
+ if (l == null) {
+ l = newLogImpl();
+ l.setChannel(channel);
+
+ Short lvl = (Short) _configuredLevels.get(shorten(channel));
+ l.setLevel((lvl == null) ? _defaultLogLevel : lvl.shortValue());
+ _logs.put(channel, l);
+ }
+
+ return l;
+ }
+
+ /**
+ * Create a new log. The log will be cached.
+ */
+ protected LogImpl newLogImpl() {
+ return new LogImpl();
+ }
+
+ /**
+ * The string name of the default level for unconfigured log channels;
+ * used for automatic configuration.
+ */
+ public void setDefaultLevel(String level) {
+ _defaultLogLevel = getLevel(level);
+ }
+
+ /**
+ * The default level for unconfigured log channels.
+ */
+ public short getDefaultLevel() {
+ return _defaultLogLevel;
+ }
+
+ /**
+ * The default level for unconfigured log channels.
+ */
+ public void setDefaultLevel(short level) {
+ _defaultLogLevel = level;
+ }
+
+ /**
+ * A string to prefix all log messages with. Set to
+ * <code>null</code> for no prefix.
+ */
+ public void setDiagnosticContext(String val) {
+ _diagContext = val;
+ }
+
+ /**
+ * A string to prefix all log messages with. Set to
+ * <code>null</code> for no prefix.
+ */
+ public String getDiagnosticContext() {
+ return _diagContext;
+ }
+
+ /**
+ * The stream to write to. Recognized values are: <code>stdout</code>
+ * and <code>stderr</code>. Any other value will be considered a
+ * file name.
+ */
+ public void setFile(String file) {
+ if (STDOUT.equals(file)) {
+ _out = System.out;
+ } else if (STDERR.equals(file)) {
+ _out = System.err;
+ } else {
+ File f = Files.getFile(file, null);
+
+ try {
+ _out = new PrintStream(new FileOutputStream(
+ f.getCanonicalPath(), true));
+ } catch (IOException ioe) {
+ throw new IllegalArgumentException(_loc.get("log-bad-file", file) +
+ " " + ioe.toString());
+ }
+ }
+ }
+
+ /**
+ * The stream to write to.
+ */
+ public PrintStream getStream() {
+ return _out;
+ }
+
+ /**
+ * The stream to write to.
+ */
+ public void setStream(PrintStream stream) {
+ if (stream == null) {
+ throw new NullPointerException("stream == null");
+ }
+
+ _out = stream;
+ }
+
+ /**
+ * Returns a string representation of the specified log level constant.
+ */
+ public static String getLevelName(short level) {
+ switch (level) {
+ case Log.TRACE:
+ return TRACE_STR;
+
+ case Log.DEBUG:
+ return DEBUG_STR;
+
+ case Log.INFO:
+ return INFO_STR;
+
+ case Log.WARN:
+ return WARN_STR;
+
+ case Log.ERROR:
+ return ERROR_STR;
+
+ case Log.FATAL:
+ return FATAL_STR;
+
+ default:
+ return _loc.get("log-unknown");
+ }
+ }
+
+ /**
+ * Returns a symbolic constant for the specified string level.
+ */
+ public static short getLevel(String str) {
+ str = str.toUpperCase().trim();
+
+ short val = TRACE_STR.equals(str) ? Log.TRACE
+ : (DEBUG_STR.equals(str) ? Log.DEBUG
+ : (INFO_STR.equals(str)
+ ? Log.INFO
+ : (WARN_STR.equals(str) ? Log.WARN
+ : (ERROR_STR.equals(str) ? Log.ERROR
+ : (FATAL_STR.equals(str)
+ ? Log.FATAL : (-1))))));
+
+ if (val == -1) {
+ throw new IllegalArgumentException(_loc.get("log-bad-constant", str));
+ }
+
+ return val;
+ }
+
+ // ---------- GenericConfigurable implementation ----------
+ public void setInto(Map m) {
+ if (!m.isEmpty()) {
+ Map.Entry e;
+
+ for (Iterator iter = m.entrySet().iterator(); iter.hasNext();) {
+ e = (Map.Entry) iter.next();
+ _configuredLevels.put(shorten((String) e.getKey()),
+ new Short(getLevel((String) e.getValue())));
+ }
+
+ m.clear();
+ }
+ }
+
+ private static String shorten(String channel) {
+ return channel.substring(channel.lastIndexOf('.') + 1);
+ }
+
+ /**
+ * A simple implementation of the {@link Log} interface. Writes
+ * output to stderr.
+ */
+ public class LogImpl extends AbstractLog {
+ private short _level = INFO;
+ private String _channel;
+
+ protected boolean isEnabled(short level) {
+ return level >= _level;
+ }
+
+ protected void log(short level, String message, Throwable t) {
+ String msg = formatMessage(level, message, t);
+
+ synchronized (_out) {
+ _out.print(msg);
+ }
+ }
+
+ /**
+ * Convert <code>message</code> into a string ready to be written to
+ * the log. The string should include the terminating newline.
+ *
+ * @param t may be null
+ */
+ protected String formatMessage(short level, String message, Throwable t) {
+ // we write to a StringBuffer and then flush it all at
+ // once as a single line, since some environments (e.g., JBoss)
+ // override the System output stream to flush any calls
+ // to write without regard to line breaks, making the
+ // output incomprehensibe.
+ StringBuffer buf = new StringBuffer();
+
+ buf.append(getOffset());
+ buf.append(" ");
+
+ if (_diagContext != null) {
+ buf.append(_diagContext).append(" ");
+ }
+
+ buf.append(getLevelName(level));
+
+ if ((level == INFO) || (level == WARN)) {
+ buf.append(" ");
+ }
+
+ buf.append(" [");
+ buf.append(Thread.currentThread().getName());
+ buf.append("] ");
+ buf.append(_channel);
+ buf.append(" - ");
+ buf.append(message);
+ buf.append(NEWLINE);
+
+ if (t != null) {
+ StringWriter swriter = new StringWriter();
+ PrintWriter pwriter = new PrintWriter(swriter);
+ t.printStackTrace(pwriter);
+ pwriter.flush();
+ buf.append(swriter.toString());
+ }
+
+ return buf.toString();
+ }
+
+ private long getOffset() {
+ return System.currentTimeMillis() - initializationMillis;
+ }
+
+ public void setChannel(String val) {
+ _channel = val;
+ }
+
+ public String getChannel() {
+ return _channel;
+ }
+
+ public void setLevel(short val) {
+ _level = val;
+ }
+
+ public short getLevel() {
+ return _level;
+ }
+ }
}
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogOutputStream.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogOutputStream.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/LogOutputStream.java Wed Jun 28 12:34:33 2006
@@ -15,88 +15,88 @@
*/
package org.apache.openjpa.lib.log;
+import org.apache.openjpa.lib.log.*;
import java.io.*;
+
import java.util.*;
/**
- * <p>Many standard components log to {@link OutputStream}s.
- * This wrapper class extends the {@link ByteArrayOutputStream}
- * class and writes all given data to an underlying {@link Log} instance
- * whenever it is flushed and the internally held byte array contains a
- * newline.</p>
+ * <p>Many standard components log to {@link OutputStream}s.
+ * This wrapper class extends the {@link ByteArrayOutputStream}
+ * class and writes all given data to an underlying {@link Log} instance
+ * whenever it is flushed and the internally held byte array contains a
+ * newline.</p>
*
- * @author Abe White, Marc Prud'hommeaux
+ * @author Abe White, Marc Prud'hommeaux
*/
-public class LogOutputStream
- extends ByteArrayOutputStream
-{
- private static final String _sep = System.getProperty ("line.separator");
-
- private final int _level;
- private final Log _log;
-
-
- /**
- * Constructor.
- *
- * @param log the log to log to
- * @param level the level to log at
- */
- public LogOutputStream (Log log, int level)
- {
- _log = log;
- _level = level;
- }
-
-
- public void flush ()
- throws IOException
- {
- super.flush ();
-
- String msg = new String (toByteArray ());
- if (msg != null && msg.length () > 0 && msg.indexOf (_sep) != -1)
- {
- // break up the message based on the line separator; this
- // may be because the flushed buffer contains mutliple lines
- for (StringTokenizer tok = new StringTokenizer (msg, _sep);
- tok.hasMoreTokens (); )
- {
- String next = tok.nextToken ();
- log (next);
- }
-
- // clear the internally held byte array
- reset ();
- }
- }
-
-
- private void log (String msg)
- {
- switch (_level)
- {
- case Log.TRACE:
- _log.trace (msg);
- break;
- case Log.DEBUG:
- _log.debug (msg);
- break;
- case Log.INFO:
- _log.info (msg);
- break;
- case Log.WARN:
- _log.warn (msg);
- break;
- case Log.ERROR:
- _log.error (msg);
- break;
- case Log.FATAL:
- _log.fatal (msg);
- break;
- }
- }
+public class LogOutputStream extends ByteArrayOutputStream {
+ private static final String _sep = System.getProperty("line.separator");
+ private final int _level;
+ private final Log _log;
+
+ /**
+ * Constructor.
+ *
+ * @param log the log to log to
+ * @param level the level to log at
+ */
+ public LogOutputStream(Log log, int level) {
+ _log = log;
+ _level = level;
+ }
+
+ public void flush() throws IOException {
+ super.flush();
+
+ String msg = new String(toByteArray());
+
+ if ((msg != null) && (msg.length() > 0) && (msg.indexOf(_sep) != -1)) {
+ // break up the message based on the line separator; this
+ // may be because the flushed buffer contains mutliple lines
+ for (StringTokenizer tok = new StringTokenizer(msg, _sep);
+ tok.hasMoreTokens();) {
+ String next = tok.nextToken();
+ log(next);
+ }
+
+ // clear the internally held byte array
+ reset();
+ }
+ }
+
+ private void log(String msg) {
+ switch (_level) {
+ case Log.TRACE:
+ _log.trace(msg);
+
+ break;
+
+ case Log.DEBUG:
+ _log.debug(msg);
+
+ break;
+
+ case Log.INFO:
+ _log.info(msg);
+
+ break;
+
+ case Log.WARN:
+ _log.warn(msg);
+
+ break;
+
+ case Log.ERROR:
+ _log.error(msg);
+
+ break;
+
+ case Log.FATAL:
+ _log.fatal(msg);
+
+ break;
+ }
+ }
}
-
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java Wed Jun 28 12:34:33 2006
@@ -19,248 +19,199 @@
/**
- * A LogFactory implementation to pass events through multiple
- * LogFactory implementations (such as log4j and LogPanelFactory).
- *
- * @author Steve Kim
+* A LogFactory implementation to pass events through multiple
+* LogFactory implementations (such as log4j and LogPanelFactory).
+ *
+* @author Steve Kim
*/
-public class MultiLogFactory
- implements LogFactory
-{
- private List _delegates;
-
-
- /**
- * create an instance with two delegates
- */
- public MultiLogFactory (LogFactory d1, LogFactory d2)
- {
- this (new LogFactory [] { d1, d2 });
- }
-
-
- public MultiLogFactory (LogFactory d1, LogFactory d2, LogFactory d3)
- {
- this (new LogFactory [] { d1, d2, d3 });
- }
-
-
- /**
- * create an instance with the given delegates
- */
- public MultiLogFactory (LogFactory [] delegates)
- {
- _delegates = new LinkedList (Arrays.asList (delegates));;
- }
-
-
- public synchronized void addLogFactory (LogFactory factory)
- {
- _delegates.add (factory);
- }
-
-
- public synchronized void removeLogFactory (LogFactory factory)
- {
- _delegates.remove (factory);
- }
-
-
- /**
- * Returns the delegates that this MultiLogFactory delegates
- * messages to.
- */
- public synchronized LogFactory[] getDelegates ()
- {
- return (LogFactory[])_delegates.toArray (new LogFactory[0]);
- }
-
-
- /**
- * returns a Log impl that combines all logs.
- */
- public synchronized Log getLog (String channel)
- {
- List logs = new ArrayList (_delegates.size ());
- for (Iterator i = _delegates.iterator (); i.hasNext (); )
- {
- LogFactory f = (LogFactory)i.next ();
- if (f != null)
- {
- Log l = f.getLog (channel);
- if (l != null)
- logs.add (l);
- }
- }
-
- return new MultiLog ((Log[])logs.toArray (new Log[logs.size ()]));
- }
-
-
- /**
- * Combinatory Log impl.
- */
- private static class MultiLog implements Log
- {
- private Log[] _logs;
-
- public MultiLog (Log[] logs)
- {
- _logs = logs;
- }
-
-
- /**
- * Return the logs that this log delegates to.
- */
- public Log[] getDelegates ()
- {
- return _logs;
- }
-
-
- public void trace (Object msg)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].trace (msg);
- }
-
-
- public void trace (Object msg, Throwable t)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].trace (msg, t);
- }
-
-
- public void info (Object msg)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].info (msg);
- }
-
-
- public void info (Object msg, Throwable t)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].info (msg, t);
- }
-
-
- public void debug (Object msg)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].debug (msg);
- }
-
-
- public void debug (Object msg, Throwable t)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].debug (msg, t);
- }
-
-
- public void warn (Object msg)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].warn (msg);
- }
-
-
- public void warn (Object msg, Throwable t)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].warn (msg, t);
- }
-
-
- public void error (Object msg)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].error (msg);
- }
-
-
- public void error (Object msg, Throwable t)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].error (msg, t);
- }
-
-
- public void fatal (Object msg)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].fatal (msg);
- }
-
-
- public void fatal (Object msg, Throwable t)
- {
- for (int i = 0; i < _logs.length; i++)
- _logs[i].fatal (msg, t);
- }
-
-
- public boolean isTraceEnabled ()
- {
- for (int i = 0; i < _logs.length; i++)
- if (_logs[i].isTraceEnabled ())
- return true;
-
- return false;
- }
-
-
- public boolean isInfoEnabled ()
- {
- for (int i = 0; i < _logs.length; i++)
- if (_logs[i].isInfoEnabled ())
- return true;
-
- return false;
- }
-
-
- public boolean isWarnEnabled ()
- {
- for (int i = 0; i < _logs.length; i++)
- if (_logs[i].isWarnEnabled ())
- return true;
-
- return false;
- }
-
-
- public boolean isDebugEnabled ()
- {
- for (int i = 0; i < _logs.length; i++)
- if (_logs[i].isDebugEnabled ())
- return true;
-
- return false;
- }
-
-
-
- public boolean isErrorEnabled ()
- {
- for (int i = 0; i < _logs.length; i++)
- if (_logs[i].isErrorEnabled ())
- return true;
-
- return false;
- }
-
-
- public boolean isFatalEnabled ()
- {
- for (int i = 0; i < _logs.length; i++)
- if (_logs[i].isFatalEnabled ())
- return true;
-
- return false;
- }
- }
+public class MultiLogFactory implements LogFactory {
+ private List _delegates;
+
+ /**
+ * create an instance with two delegates
+ */
+ public MultiLogFactory(LogFactory d1, LogFactory d2) {
+ this(new LogFactory[] { d1, d2 });
+ }
+
+ public MultiLogFactory(LogFactory d1, LogFactory d2, LogFactory d3) {
+ this(new LogFactory[] { d1, d2, d3 });
+ }
+
+ /**
+ * create an instance with the given delegates
+ */
+ public MultiLogFactory(LogFactory[] delegates) {
+ _delegates = new LinkedList(Arrays.asList(delegates));
+ ;
+ }
+
+ public synchronized void addLogFactory(LogFactory factory) {
+ _delegates.add(factory);
+ }
+
+ public synchronized void removeLogFactory(LogFactory factory) {
+ _delegates.remove(factory);
+ }
+
+ /**
+ * Returns the delegates that this MultiLogFactory delegates
+ * messages to.
+ */
+ public synchronized LogFactory[] getDelegates() {
+ return (LogFactory[]) _delegates.toArray(new LogFactory[0]);
+ }
+
+ /**
+ * returns a Log impl that combines all logs.
+ */
+ public synchronized Log getLog(String channel) {
+ List logs = new ArrayList(_delegates.size());
+
+ for (Iterator i = _delegates.iterator(); i.hasNext();) {
+ LogFactory f = (LogFactory) i.next();
+
+ if (f != null) {
+ Log l = f.getLog(channel);
+
+ if (l != null) {
+ logs.add(l);
+ }
+ }
+ }
+
+ return new MultiLog((Log[]) logs.toArray(new Log[logs.size()]));
+ }
+
+ /**
+ * Combinatory Log impl.
+ */
+ private static class MultiLog implements Log {
+ private Log[] _logs;
+
+ public MultiLog(Log[] logs) {
+ _logs = logs;
+ }
+
+ /**
+ * Return the logs that this log delegates to.
+ */
+ public Log[] getDelegates() {
+ return _logs;
+ }
+
+ public void trace(Object msg) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].trace(msg);
+ }
+
+ public void trace(Object msg, Throwable t) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].trace(msg, t);
+ }
+
+ public void info(Object msg) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].info(msg);
+ }
+
+ public void info(Object msg, Throwable t) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].info(msg, t);
+ }
+
+ public void debug(Object msg) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].debug(msg);
+ }
+
+ public void debug(Object msg, Throwable t) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].debug(msg, t);
+ }
+
+ public void warn(Object msg) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].warn(msg);
+ }
+
+ public void warn(Object msg, Throwable t) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].warn(msg, t);
+ }
+
+ public void error(Object msg) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].error(msg);
+ }
+
+ public void error(Object msg, Throwable t) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].error(msg, t);
+ }
+
+ public void fatal(Object msg) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].fatal(msg);
+ }
+
+ public void fatal(Object msg, Throwable t) {
+ for (int i = 0; i < _logs.length; i++)
+ _logs[i].fatal(msg, t);
+ }
+
+ public boolean isTraceEnabled() {
+ for (int i = 0; i < _logs.length; i++)
+ if (_logs[i].isTraceEnabled()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean isInfoEnabled() {
+ for (int i = 0; i < _logs.length; i++)
+ if (_logs[i].isInfoEnabled()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean isWarnEnabled() {
+ for (int i = 0; i < _logs.length; i++)
+ if (_logs[i].isWarnEnabled()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean isDebugEnabled() {
+ for (int i = 0; i < _logs.length; i++)
+ if (_logs[i].isDebugEnabled()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean isErrorEnabled() {
+ for (int i = 0; i < _logs.length; i++)
+ if (_logs[i].isErrorEnabled()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean isFatalEnabled() {
+ for (int i = 0; i < _logs.length; i++)
+ if (_logs[i].isFatalEnabled()) {
+ return true;
+ }
+
+ return false;
+ }
+ }
}
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/NoneLogFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/NoneLogFactory.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/NoneLogFactory.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/NoneLogFactory.java Wed Jun 28 12:34:33 2006
@@ -17,129 +17,84 @@
/**
- * A log factory implementation that does not do any logging, as
- * quickly as possible.
+ * A log factory implementation that does not do any logging, as
+ * quickly as possible.
*
- * @author Patrick Linskey
+ * @author Patrick Linskey
*/
-public class NoneLogFactory
- implements LogFactory
-{
- public final Log getLog (String channel)
- {
- return NoneLog.getInstance ();
- }
+public class NoneLogFactory implements LogFactory {
+ public final Log getLog(String channel) {
+ return NoneLog.getInstance();
+ }
+ /**
+ * No-op log.
+ */
+ public static class NoneLog implements Log {
+ private static final NoneLog s_log = new NoneLog();
- /**
- * No-op log.
- */
- public static class NoneLog
- implements Log
- {
- private static final NoneLog s_log = new NoneLog ();
+ public static NoneLog getInstance() {
+ return s_log;
+ }
+ public final boolean isDebugEnabled() {
+ return false;
+ }
- public static NoneLog getInstance ()
- {
- return s_log;
- }
+ public final boolean isErrorEnabled() {
+ return false;
+ }
+ public final boolean isFatalEnabled() {
+ return false;
+ }
- public final boolean isDebugEnabled ()
- {
- return false;
- }
+ public final boolean isInfoEnabled() {
+ return false;
+ }
+ public final boolean isTraceEnabled() {
+ return false;
+ }
- public final boolean isErrorEnabled ()
- {
- return false;
- }
+ public final boolean isWarnEnabled() {
+ return false;
+ }
+ public final void trace(Object o) {
+ }
- public final boolean isFatalEnabled ()
- {
- return false;
- }
+ public final void trace(Object o, Throwable t) {
+ }
+ public final void debug(Object o) {
+ }
- public final boolean isInfoEnabled ()
- {
- return false;
- }
+ public final void debug(Object o, Throwable t) {
+ }
+ public final void info(Object o) {
+ }
- public final boolean isTraceEnabled ()
- {
- return false;
- }
+ public final void info(Object o, Throwable t) {
+ }
+ public final void warn(Object o) {
+ }
- public final boolean isWarnEnabled ()
- {
- return false;
- }
+ public final void warn(Object o, Throwable t) {
+ }
+ public final void error(Object o) {
+ }
- public final void trace (Object o)
- {
- }
+ public final void error(Object o, Throwable t) {
+ }
+ public final void fatal(Object o) {
+ }
- public final void trace (Object o, Throwable t)
- {
- }
-
-
- public final void debug (Object o)
- {
- }
-
-
- public final void debug (Object o, Throwable t)
- {
- }
-
-
- public final void info (Object o)
- {
- }
-
-
- public final void info (Object o, Throwable t)
- {
- }
-
-
- public final void warn (Object o)
- {
- }
-
-
- public final void warn (Object o, Throwable t)
- {
- }
-
-
- public final void error (Object o)
- {
- }
-
-
- public final void error (Object o, Throwable t)
- {
- }
-
-
- public final void fatal (Object o)
- {
- }
-
-
- public final void fatal (Object o, Throwable t)
- {
- }
- }
+ public final void fatal(Object o, Throwable t) {
+ }
+ }
}
-
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/package.html
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/package.html?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/package.html (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/log/package.html Wed Jun 28 12:34:33 2006
@@ -1,18 +1,3 @@
-<!--
- Copyright 2006 The Apache Software Foundation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
<html>
<body>
<p><strong>Logging</strong></p>