KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > services > stream > BasicGetLogHeader


1 /*
2
3    Derby - Class org.apache.derby.impl.services.stream.BasicGetLogHeader
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.services.stream;
23
24 import org.apache.derby.iapi.services.stream.PrintWriterGetHeader;
25 import org.apache.derby.iapi.util.CheapDateFormatter;
26
27 /**
28  * Get a header to prepend to a line of output. *
29  * A HeaderPrintWriter requires an object which implements
30  * this interface to construct line headers.
31  *
32  * @see org.apache.derby.iapi.services.stream.HeaderPrintWriter
33  */

34
35 class BasicGetLogHeader implements PrintWriterGetHeader
36 {
37     
38     private boolean doThreadId;
39     private boolean doTimeStamp;
40     private String JavaDoc tag;
41
42     /*
43      * STUB: This should take a header template. Check if
44      * the error message facility provides something.
45      *
46      * This should be localizable. How?
47      */

48     /**
49      * Constructor for a BasicGetLogHeader object.
50      * <p>
51      * @param doThreadId true means include the calling thread's
52      * id in the header.
53      * @param doTimeStamp true means include the current time in
54      * the header.
55      * @param tag A string to prefix the header. null
56      * means don't prefix the header with
57      * a string.
58      */

59     BasicGetLogHeader(boolean doThreadId,
60                 boolean doTimeStamp,
61                 String JavaDoc tag){
62         this.doThreadId = doThreadId;
63         this.doTimeStamp = doTimeStamp;
64         this.tag = tag;
65     }
66     
67     public String JavaDoc getHeader()
68     {
69         StringBuffer JavaDoc header = new StringBuffer JavaDoc(48);
70
71         if (tag != null) {
72             header.append(tag);
73             header.append(' ');
74         }
75
76         if (doTimeStamp) {
77             long currentTime = System.currentTimeMillis();
78
79             header.append(CheapDateFormatter.formatDate(currentTime));
80             header.append(' ');
81
82         }
83         if (doThreadId) {
84             header.append(Thread.currentThread().toString());
85             header.append(' ');
86         }
87
88         return header.toString();
89     }
90 }
91     
92
Popular Tags