KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > olap > xmla > JRXmlaHierarchy


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.olap.xmla;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.List JavaDoc;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 import net.sf.jasperreports.olap.result.JROlapHierarchy;
37 import net.sf.jasperreports.olap.result.JROlapHierarchyLevel;
38
39
40 /**
41  * @author Lucian Chirita (lucianc@users.sourceforge.net)
42  * @version $Id: JRXmlaHierarchy.java 1446 2006-10-25 09:00:05Z lucianc $
43  */

44 public class JRXmlaHierarchy implements JROlapHierarchy
45 {
46     
47     private final static Log log = LogFactory.getLog(JRXmlaHierarchy.class);
48
49     private final String JavaDoc dimensionName;
50     private final List JavaDoc levels;
51     private JRXmlaHierarchyLevel[] levelArray;
52
53     public JRXmlaHierarchy(String JavaDoc dimensionName)
54     {
55         this.dimensionName = dimensionName;
56         this.levels = new ArrayList JavaDoc();
57     }
58
59     public String JavaDoc getDimensionName()
60     {
61         return dimensionName;
62     }
63
64     public JROlapHierarchyLevel[] getLevels()
65     {
66         return ensureLevelArray();
67     }
68
69     public void setLevel(String JavaDoc levelName, int depth)
70     {
71         int levelCount = levels.size();
72         if (depth >= levelCount)
73         {
74             for (int i = levelCount; i <= depth; ++i)
75             {
76                 levels.add(null);
77             }
78         }
79         
80         JRXmlaHierarchyLevel level = (JRXmlaHierarchyLevel) levels.get(depth);
81         if (level == null)
82         {
83             level = new JRXmlaHierarchyLevel(levelName, depth);
84             levels.set(depth, level);
85         }
86         else if (!levelName.equals(level.getName()))
87         {
88             if (log.isWarnEnabled())
89             {
90                 log.warn("Different level name \"" + levelName + "\" found for level \"" + level.getName() + "\" at depth " + depth);
91             }
92         }
93         
94         resetLevelArray();
95     }
96
97     protected JRXmlaHierarchyLevel[] ensureLevelArray()
98     {
99         if (levelArray == null)
100         {
101             levelArray = new JRXmlaHierarchyLevel[levels.size()];
102             levelArray = (JRXmlaHierarchyLevel[]) levels.toArray(levelArray);
103         }
104         return levelArray;
105     }
106
107     protected void resetLevelArray()
108     {
109         levelArray = null;
110     }
111 }
112
Popular Tags