001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.server.hsql;
017:
018: import java.io.PrintWriter;
019:
020: import org.apache.openejb.util.LogCategory;
021: import org.apache.openejb.util.Logger;
022:
023: public class HsqlPrintWriter extends PrintWriter {
024: private Logger logger;
025: private boolean errorWriter;
026: private StringBuffer text = new StringBuffer("");
027:
028: public HsqlPrintWriter(boolean errorWriter) {
029: super (System.err);
030: logger = Logger.getInstance(LogCategory.OPENEJB_HSQL,
031: HsqlPrintWriter.class);
032: this .errorWriter = errorWriter;
033: }
034:
035: public void close() {
036: flush();
037: }
038:
039: private void flushLine() {
040: if (!errorWriter)
041: logger.info(text.toString());
042: else
043: logger.error(text.toString());
044: text.setLength(0);
045: }
046:
047: public void flush() {
048: if (!text.toString().equals("")) {
049: flushLine();
050: }
051: }
052:
053: public void print(boolean b) {
054: text.append(b);
055: }
056:
057: public void print(char c) {
058: text.append(c);
059: }
060:
061: public void print(char[] s) {
062: text.append(s);
063: }
064:
065: public void print(double d) {
066: text.append(d);
067: }
068:
069: public void print(float f) {
070: text.append(f);
071: }
072:
073: public void print(int i) {
074: text.append(i);
075: }
076:
077: public void print(long l) {
078: text.append(l);
079: }
080:
081: public void print(Object obj) {
082: text.append(obj);
083: }
084:
085: public void print(String s) {
086: text.append(s);
087: }
088:
089: public void println() {
090: if (!text.toString().equals("")) {
091: flushLine();
092: }
093: }
094:
095: public void println(boolean x) {
096: text.append(x);
097: flushLine();
098: }
099:
100: public void println(char x) {
101: text.append(x);
102: flushLine();
103: }
104:
105: public void println(char[] x) {
106: text.append(x);
107: flushLine();
108: }
109:
110: public void println(double x) {
111: text.append(x);
112: flushLine();
113: }
114:
115: public void println(float x) {
116: text.append(x);
117: flushLine();
118: }
119:
120: public void println(int x) {
121: text.append(x);
122: flushLine();
123: }
124:
125: public void println(long x) {
126: text.append(x);
127: flushLine();
128: }
129:
130: public void println(Object x) {
131: text.append(x);
132: flushLine();
133: }
134:
135: public void println(String x) {
136: text.append(x);
137: flushLine();
138: }
139:
140: }
|