KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
24  * Description of the configuration of a set of categories.
25  *
26  * @see CategoryDirective
27  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
28  * @version $Revision: 1.2 $ $Date: 2004/02/24 21:55:37 $
29  */

30 public class CategoriesDirective extends CategoryDirective implements Serializable JavaDoc
31 {
32     /**
33      * The root category hierachy.
34      */

35     private CategoryDirective[] m_categories;
36
37     /**
38      * Create a CategoriesDirective instance.
39      */

40     public CategoriesDirective()
41     {
42         this( "" );
43     }
44
45     /**
46      * Create a CategoriesDirective instance.
47      *
48      * @param name the base category name
49      */

50     public CategoriesDirective( final String JavaDoc name )
51     {
52         this( name, null, null, new CategoryDirective[0] );
53     }
54
55     /**
56      * Create a CategoriesDirective instance.
57      *
58      * @param categories the categories to include in the directive
59      */

60     public CategoriesDirective( CategoryDirective[] categories )
61     {
62         this( "", null, null, categories );
63     }
64
65
66     /**
67      * Create a CategoriesDirective instance.
68      *
69      * @param name the base category name
70      * @param priority the default logging priority
71      * @param target the default logging target
72      * @param categories the logging category descriptors
73      */

74     public CategoriesDirective( final String JavaDoc name,
75                                  final String JavaDoc priority,
76                                  final String JavaDoc target,
77                                  final CategoryDirective[] categories )
78     {
79         super( name, priority, target );
80         if( categories == null )
81         {
82             m_categories = new CategoryDirective[ 0 ];
83         }
84         else
85         {
86             m_categories = categories;
87         }
88     }
89
90     /**
91      * Return the set of logging categories.
92      *
93      * @return the set of category declarations
94      */

95     public CategoryDirective[] getCategories()
96     {
97         return m_categories;
98     }
99
100     /**
101      * Return a named category.
102      *
103      * @param name the category name
104      * @return the category declaration
105      */

106     public CategoryDirective getCategoryDirective( String JavaDoc name )
107     {
108         for( int i = 0; i < m_categories.length; i++ )
109         {
110             final CategoryDirective category = m_categories[ i ];
111             if( category.getName().equalsIgnoreCase( name ) )
112             {
113                 return category;
114             }
115         }
116         return null;
117     }
118
119    /**
120     * Test this object for equality with the suppplied object.
121     *
122     * @return TRUE if this object equals the supplied object
123     * else FALSE
124     */

125     public boolean equals( Object JavaDoc other )
126     {
127         boolean isEqual = other instanceof CategoriesDirective;
128         if ( isEqual ) isEqual = super.equals( other );
129
130         if ( isEqual )
131         {
132             CategoriesDirective cat = (CategoriesDirective) other;
133             if ( isEqual ) isEqual = m_categories.length == cat.m_categories.length;
134             if ( isEqual )
135             {
136                 for ( int i = 0; i < m_categories.length && isEqual; i++ )
137                 {
138                     isEqual = m_categories[i].equals( cat.m_categories[i] );
139                 }
140             }
141         }
142         return isEqual;
143     }
144
145    /**
146     * Return the hashcode for the object.
147     * @return the cashcode
148     */

149     public int hashCode()
150     {
151         int hash = super.hashCode();
152         for ( int i = 0; i < m_categories.length; i++ )
153         {
154             hash >>>= 1;
155             hash ^= m_categories[i].hashCode();
156         }
157         return hash;
158     }
159
160
161 }
162
Popular Tags