KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > logging > data > CategoryDirective


1 /*
2  * Copyright 2004 Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.logging.data;
19
20 import java.io.Serializable JavaDoc;
21
22 /**
23  * A logging category descriptor hierachy. The descriptor contains a category name, a
24  * optional priority value, and an optional target. If the priority or target values
25  * null, the resulting value will be derived from the parent category desciptor. A
26  * category descriptor may 0-n subsidiary categories. CategoryDirective names are relative.
27  * For example, the category "orb" will appear as "my-app.orb" if the parent category
28  * name is "my-app".
29  *
30  * <p><b>XML</b></p>
31  * <pre>
32  * &lt;categories priority="<font color="darkred">INFO</font>"&gt;
33  * &lt;category priority="<font color="darkred">DEBUG</font>" name="<font color="darkred">loader</font>" /&gt;
34  * &lt;category priority="<font color="darkred">WARN</font>" name="<font color="darkred">types</font>" /&gt;
35  * &lt;category priority="<font color="darkred">ERROR</font>" name="<font color="darkred">types.builder</font>" target="<font color="darkred">default</font>"/&gt;
36  * &lt;category name="<font color="darkred">profiles</font>" /&gt;
37  * &lt;category name="<font color="darkred">lifecycle</font>" /&gt;
38  * &lt;category name="<font color="darkred">verifier</font>" /&gt;
39  * &lt;/categories&gt;
40  * </pre>
41  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
42  * @version $Revision: 1.2 $ $Date: 2004/02/24 21:55:37 $
43  */

44 public class CategoryDirective implements Serializable JavaDoc
45 {
46
47     /**
48      * Constant category priority value for debug mode.
49      */

50     public static final String JavaDoc DEBUG = "DEBUG";
51
52     /**
53      * Constant category priority value for info mode.
54      */

55     public static final String JavaDoc INFO = "INFO";
56
57     /**
58      * Constant category priority value for warning mode.
59      */

60     public static final String JavaDoc WARN = "WARN";
61
62     /**
63      * Constant category priority value for error mode.
64      */

65     public static final String JavaDoc ERROR = "ERROR";
66
67     /**
68      * The logging category name.
69      */

70     private String JavaDoc m_name;
71
72     /**
73      * The default logging priority.
74      */

75     private final String JavaDoc m_priority;
76
77     /**
78      * The default logging target.
79      */

80     private final String JavaDoc m_target;
81
82     /**
83      * Creation of a new CategoryDirective using a supplied name.
84      *
85      * @param name the category name
86      */

87     public CategoryDirective( final String JavaDoc name )
88     {
89         this( name, null, null );
90     }
91
92     /**
93      * Creation of a new CategoryDirective using a supplied name and priority.
94      *
95      * @param name the category name
96      * @param priority the category priority - DEBUG, INFO, WARN, or ERROR
97      */

98     public CategoryDirective( final String JavaDoc name, String JavaDoc priority )
99     {
100         this( name, priority, null );
101     }
102
103     /**
104      * Creation of a new CategoryDirective using a supplied name, priority, target and
105      * collection of subsidiary categories.
106      *
107      * @param name the category name
108      * @param priority the category priority - DEBUG, INFO, WARN, or ERROR
109      * @param target the name of a logging category target
110      *
111      */

112     public CategoryDirective(
113         final String JavaDoc name, final String JavaDoc priority, final String JavaDoc target )
114     {
115         m_name = name;
116         m_target = target;
117         if( priority != null )
118         {
119             m_priority = priority.trim().toUpperCase();
120         }
121         else
122         {
123             m_priority = null;
124         }
125     }
126
127     /**
128      * Return the category name.
129      *
130      * @return the category name
131      */

132     public String JavaDoc getName()
133     {
134         return m_name;
135     }
136
137     /**
138      * Return the logging priority for the category.
139      *
140      * @return the logging priority for the category
141      */

142     public String JavaDoc getPriority()
143     {
144         return m_priority;
145     }
146
147     /**
148      * Return the default log target for the category.
149      *
150      * @return the default target name
151      */

152     public String JavaDoc getTarget()
153     {
154         return m_target;
155     }
156
157     public boolean equals(Object JavaDoc other)
158     {
159         if( null == other )
160         {
161             return false;
162         }
163
164         if( ! ( other instanceof CategoryDirective ) )
165         {
166             return false;
167         }
168
169         CategoryDirective test = (CategoryDirective) other;
170         return ( equalName( test.getName() )
171               && equalPriority( test.getPriority() )
172               && equalTarget( test.getTarget() ) );
173     }
174
175     private boolean equalName( String JavaDoc other )
176     {
177         if( m_name == null )
178         {
179             return other == null;
180         }
181         else
182         {
183             return m_name.equals( other );
184         }
185     }
186
187     private boolean equalPriority( String JavaDoc other )
188     {
189         if( m_priority == null )
190         {
191             return other == null;
192         }
193         else
194         {
195             return m_priority.equals( other );
196         }
197     }
198
199     private boolean equalTarget( String JavaDoc other )
200     {
201         if( m_target == null )
202         {
203             return other == null;
204         }
205         else
206         {
207             return m_target.equals( other );
208         }
209     }
210
211     public int hashCode()
212     {
213         int hash = m_name.hashCode();
214         hash >>>= 13;
215         if( m_priority != null )
216         {
217             hash ^= m_priority.hashCode();
218         }
219         hash >>>= 5;
220         if( m_target != null )
221         {
222             hash ^= m_target.hashCode();
223         }
224         return hash;
225     }
226 }
227
Popular Tags