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.4
Committed: Tue Dec 12 19:15:30 2000 UTC (23 years, 4 months ago) by ajm
Branch: MAIN
Changes since 1.3: +19 -3 lines
Log Message:
added function to trim uk.ac.ukc.iscream from the class name...declutters things a bit ;-)

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.util;
3    
4     //---IMPORTS---
5    
6     /**
7     * This class provides static methods to format the
8     * name of a calling object. It's main use is by
9     * the various objects within the system to create
10     * a toString String to send to the logger.
11     *
12 ajm 1.2 * @author $Author: ajm4 $
13 ajm 1.4 * @version $Id: FormatName.java,v 1.3 2000/12/12 18:24:00 ajm4 Exp $
14 ajm 1.1 */
15 ajm 1.2 public class FormatName {
16 ajm 1.1
17     //---FINAL ATTRIBUTES---
18    
19     //---STATIC METHODS---
20    
21     /**
22     * This method takes a set of information about the calling
23     * class and constructs a tidy String name to be returned.
24     * This is of use to the override of the toString() as
25     * implemented by most of the iscream objects.
26     *
27 ajm 1.3 * It has support for null friendly name and null class name
28     * bit NOT both at the same time.
29     *
30 ajm 1.2 * @param friendlyName the configured name of the instance of the calling component the class is in (eg "filter1")
31 ajm 1.1 * @param className the class name of the calling class, as obtained by getClass().getName()
32     * @param revision the CVS Revision number for the calling class
33     *
34     * @return an iscream standard name to be used as a toString()
35     */
36 ajm 1.2 public static String getName(String friendlyName, String className, String revision) {
37 ajm 1.1 if (friendlyName == null) {
38 ajm 1.4 return "{"+ tidyClassName(className) + "(v" + revision.substring(11, revision.length() - 2) + ")}";
39 ajm 1.3 } else if (className == null) {
40     return friendlyName + "{static(v" + revision.substring(11, revision.length() - 2) + ")}";
41     } else {
42 ajm 1.4 return friendlyName + "{"+ tidyClassName(className) + "(v" + revision.substring(11, revision.length() - 2) + ")}";
43 ajm 1.1 }
44 ajm 1.4 }
45    
46     /**
47     * If the class name begins with uk.ac.ukc.iscream
48     * this method will trim it off, otherwise it
49     * leaves the string unchanged.
50     *
51     * @param className the name of a class
52     *
53     * @return the tidy version of it
54     */
55     private static String tidyClassName(String className) {
56     if (className.startsWith("uk.ac.ukc.iscream")) {
57     return className.substring(18);
58     }
59     return className;
60 ajm 1.1 }
61    
62     //---CONSTRUCTORS---
63    
64     /**
65     * A private constructor ensures an instance of this
66     * class CANNOT be created.
67     */
68 ajm 1.2 private FormatName() {
69 ajm 1.1 // do nothing on purpose!
70     }
71    
72     //---PUBLIC METHODS---
73    
74     //---PRIVATE METHODS---
75    
76     //---ACCESSOR/MUTATOR METHODS---
77    
78     //---ATTRIBUTES---
79    
80     //---STATIC ATTRIBUTES---
81    
82     }