KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > util > log > Priority


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8 package org.jivesoftware.util.log;
9
10 import java.io.ObjectStreamException JavaDoc;
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * Class representing and holding constants for priority.
15  *
16  * @author <a HREF="mailto:peter@apache.org">Peter Donald</a>
17  */

18 public final class Priority implements Serializable JavaDoc {
19
20     /**
21      * Developer orientated messages, usually used during development of product.
22      */

23     public final static Priority DEBUG = new Priority("DEBUG", 5);
24
25     /**
26      * Useful information messages such as state changes, client connection, user login etc.
27      */

28     public final static Priority INFO = new Priority("INFO", 10);
29
30     /**
31      * A problem or conflict has occurred but it may be recoverable, then
32      * again it could be the start of the system failing.
33      */

34     public final static Priority WARN = new Priority("WARN", 15);
35
36     /**
37      * A problem has occurred but it is not fatal. The system will still function.
38      */

39     public final static Priority ERROR = new Priority("ERROR", 20);
40
41     /**
42      * Something caused whole system to fail. This indicates that an administrator
43      * should restart the system and try to fix the problem that caused the failure.
44      */

45     public final static Priority FATAL_ERROR = new Priority("FATAL_ERROR", 25);
46
47     private final String JavaDoc m_name;
48     private final int m_priority;
49
50     /**
51      * Retrieve a Priority object for the name parameter.
52      *
53      * @param priority the priority name
54      * @return the Priority for name
55      */

56     public static Priority getPriorityForName(final String JavaDoc priority) {
57         if (Priority.DEBUG.getName().equals(priority))
58             return Priority.DEBUG;
59         else if (Priority.INFO.getName().equals(priority))
60             return Priority.INFO;
61         else if (Priority.WARN.getName().equals(priority))
62             return Priority.WARN;
63         else if (Priority.ERROR.getName().equals(priority))
64             return Priority.ERROR;
65         else if (Priority.FATAL_ERROR.getName().equals(priority))
66             return Priority.FATAL_ERROR;
67         else
68             return Priority.DEBUG;
69     }
70
71     /**
72      * Private Constructor to block instantiation outside class.
73      *
74      * @param name the string name of priority
75      * @param priority the numerical code of priority
76      */

77     private Priority(final String JavaDoc name, final int priority) {
78         m_name = name;
79         m_priority = priority;
80     }
81
82     /**
83      * Overidden string to display Priority in human readable form.
84      *
85      * @return the string describing priority
86      */

87     public String JavaDoc toString() {
88         return "Priority[" + getName() + "/" + getValue() + "]";
89     }
90
91     /**
92      * Get numerical value associated with priority.
93      *
94      * @return the numerical value
95      */

96     public int getValue() {
97         return m_priority;
98     }
99
100     /**
101      * Get name of priority.
102      *
103      * @return the priorities name
104      */

105     public String JavaDoc getName() {
106         return m_name;
107     }
108
109     /**
110      * Test whether this priority is greater than other priority.
111      *
112      * @param other the other Priority
113      */

114     public boolean isGreater(final Priority other) {
115         return m_priority > other.getValue();
116     }
117
118     /**
119      * Test whether this priority is lower than other priority.
120      *
121      * @param other the other Priority
122      */

123     public boolean isLower(final Priority other) {
124         return m_priority < other.getValue();
125     }
126
127     /**
128      * Test whether this priority is lower or equal to other priority.
129      *
130      * @param other the other Priority
131      */

132     public boolean isLowerOrEqual(final Priority other) {
133         return m_priority <= other.getValue();
134     }
135
136     /**
137      * Helper method that replaces deserialized object with correct singleton.
138      *
139      * @return the singleton version of object
140      * @throws ObjectStreamException if an error occurs
141      */

142     private Object JavaDoc readResolve()
143             throws ObjectStreamException JavaDoc {
144         return getPriorityForName(m_name);
145     }
146 }
147
Popular Tags