ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/FormatName.java
Revision: 1.12
Committed: Tue May 29 17:02:35 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Changes since 1.11: +4 -4 lines
Log Message:
Major change in the java package naming. This has been held off for some time
now, but it really needed doing. The future packaging of all i-scream products
will be;

uk.org.iscream.<product>.<subpart>.*

In the case of the central monitoring system server this will be;

uk.org.iscream.cms.server.*

The whole server has been changed to follow this structure, and tested to a
smallish extent. Further changes in other parts of the CMS will follow.

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2 tdb 1.12 package uk.org.iscream.cms.server.util;
3 ajm 1.1
4     //---IMPORTS---
5 tdb 1.5 import java.util.Date;
6     import java.text.DateFormat;
7     import java.util.Locale;
8 ajm 1.1
9     /**
10     * This class provides static methods to format the
11     * name of a calling object. It's main use is by
12     * the various objects within the system to create
13     * a toString String to send to the logger.
14     *
15 tdb 1.6 * @author $Author: tdb1 $
16 tdb 1.12 * @version $Id: FormatName.java,v 1.11 2001/03/26 15:33:59 tdb1 Exp $
17 ajm 1.1 */
18 ajm 1.2 public class FormatName {
19 ajm 1.1
20     //---FINAL ATTRIBUTES---
21    
22 tdb 1.5 /**
23     * An array of names of verbosity levels.
24 tdb 1.6 * Thus logging messages are now "classed" by the level
25 tdb 1.5 */
26     private final static String[] VERBOSITY_NAMES = {"FATAL ", "ERROR ", "WARNING", "SYSMSG ", "SYSINIT", "DEBUG "};
27    
28 ajm 1.1 //---STATIC METHODS---
29    
30     /**
31     * This method takes a set of information about the calling
32     * class and constructs a tidy String name to be returned.
33     * This is of use to the override of the toString() as
34     * implemented by most of the iscream objects.
35     *
36 ajm 1.2 * @param friendlyName the configured name of the instance of the calling component the class is in (eg "filter1")
37 ajm 1.1 * @param className the class name of the calling class, as obtained by getClass().getName()
38     * @param revision the CVS Revision number for the calling class
39     *
40     * @return an iscream standard name to be used as a toString()
41     */
42 ajm 1.2 public static String getName(String friendlyName, String className, String revision) {
43 tdb 1.5 if (friendlyName == null && className == null) {
44     return "{static(v" + revision.substring(11, revision.length() - 2) + ")}";
45     } else if (friendlyName == null) {
46 ajm 1.4 return "{"+ tidyClassName(className) + "(v" + revision.substring(11, revision.length() - 2) + ")}";
47 ajm 1.3 } else if (className == null) {
48     return friendlyName + "{static(v" + revision.substring(11, revision.length() - 2) + ")}";
49     } else {
50 ajm 1.4 return friendlyName + "{"+ tidyClassName(className) + "(v" + revision.substring(11, revision.length() - 2) + ")}";
51 ajm 1.1 }
52 ajm 1.4 }
53 tdb 1.5
54     /**
55     * This method generates a nicely formatted line for the log,
56     * including the date/time and the source of the message. The date
57     * and time are formatted using the DateFormat class, and the source
58     * class is formatted using the toString() method found in every
59     * source file. This is then prepended to the message and returned.
60     *
61     * @param source A string representation of the calling object.
62     * @param verbosity The verbosity of the message.
63     * @param message The message to be logged.
64     * @return The string to be written to the log.
65     */
66     public static String formatLogLine(String source, int verbosity, String message){
67 tdb 1.11 String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date());
68 tdb 1.5 return "[" + date + "] [" + VERBOSITY_NAMES[verbosity] + "] " + source + ": " + message;
69     }
70    
71 ajm 1.4 /**
72 tdb 1.12 * If the class name begins with uk.org.iscream.cms.server
73 ajm 1.4 * this method will trim it off, otherwise it
74     * leaves the string unchanged.
75     *
76     * @param className the name of a class
77     *
78     * @return the tidy version of it
79     */
80     private static String tidyClassName(String className) {
81 tdb 1.12 String prefix = "uk.org.iscream.cms.server";
82 tdb 1.9 if (className.startsWith(prefix)) {
83 tdb 1.10 return className.substring(prefix.length()+1);
84 ajm 1.4 }
85     return className;
86 ajm 1.1 }
87    
88     //---CONSTRUCTORS---
89    
90     /**
91     * A private constructor ensures an instance of this
92     * class CANNOT be created.
93     */
94 ajm 1.2 private FormatName() {
95 ajm 1.1 // do nothing on purpose!
96     }
97    
98     //---PUBLIC METHODS---
99    
100     //---PRIVATE METHODS---
101    
102     //---ACCESSOR/MUTATOR METHODS---
103    
104     //---ATTRIBUTES---
105    
106     //---STATIC ATTRIBUTES---
107    
108     }