KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > base > CategoryData


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.base;
13
14 import java.util.*;
15
16 import org.openbravo.data.FieldProvider;
17 import org.apache.log4j.Logger;
18 import org.apache.log4j.LogManager;
19
20 public class CategoryData implements FieldProvider {
21
22   static Logger log4j = Logger.getLogger(CategoryData.class);
23   public String JavaDoc category;
24   public String JavaDoc priority;
25
26   public String JavaDoc getField(String JavaDoc fieldName) {
27     if (fieldName.equals("category"))
28       return category;
29     else if (fieldName.equals("priority"))
30       return priority;
31     else {
32       if (log4j.isDebugEnabled()) log4j.debug("Field does not exist: " + fieldName);
33       return null;
34     }
35   }
36
37   public static CategoryData[] getCategories() {
38     Vector<CategoryData> vector = new Vector<CategoryData>(0);
39
40     for (Enumeration e = LogManager.getCurrentLoggers(); e.hasMoreElements() ;) {
41       Logger categoryItem = (Logger)e.nextElement();
42       CategoryData categoryData = new CategoryData();
43       categoryData.category = categoryItem.getName();
44       if (categoryItem.getLevel() != null) {
45         categoryData.priority = categoryItem.getLevel().toString();
46       }
47       if (vector.isEmpty()) vector.addElement(categoryData);
48       else{
49         int index = 0;
50         while (index<vector.size()) {
51           CategoryData cd = vector.get(index);
52           if (categoryData.category.compareTo(cd.category)<0) {
53             vector.add(index, categoryData);
54             break;
55           }
56           index++;
57         }
58         if (index==vector.size()) vector.addElement(categoryData);
59       }
60       
61     }
62
63     CategoryData categoryData[] = new CategoryData[vector.size()];
64     vector.copyInto(categoryData);
65     return(categoryData);
66   }
67 }
68
Popular Tags