KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 import net.sf.jasperreports.olap.result.JROlapHierarchy;
35 import net.sf.jasperreports.olap.result.JROlapMemberTuple;
36 import net.sf.jasperreports.olap.result.JROlapResultAxis;
37
38
39 /**
40  * @author Lucian Chirita (lucianc@users.sourceforge.net)
41  * @version $Id: JRXmlaResultAxis.java 1446 2006-10-25 09:00:05Z lucianc $
42  */

43 public class JRXmlaResultAxis implements JROlapResultAxis
44 {
45
46     private final String JavaDoc axisName;
47     private final List JavaDoc hierarchyList;
48     private JRXmlaHierarchy[] hierarchies;
49     private final List JavaDoc tuples;
50     
51     public JRXmlaResultAxis(String JavaDoc axisName)
52     {
53         this.axisName = axisName;
54         this.hierarchyList = new ArrayList JavaDoc();
55         this.tuples = new ArrayList JavaDoc();
56     }
57     
58     public String JavaDoc getAxisName()
59     {
60         return axisName;
61     }
62
63     public JROlapHierarchy[] getHierarchiesOnAxis()
64     {
65         return ensureHierarchyArray();
66     }
67
68     public JROlapMemberTuple getTuple(int index)
69     {
70         if (index < 0 || index >= tuples.size())
71         {
72             throw new IndexOutOfBoundsException JavaDoc("Index: " + index + ", Size: " + tuples.size());
73         }
74         
75         return (JROlapMemberTuple) tuples.get(index);
76     }
77
78     public int getTupleCount()
79     {
80         return tuples.size();
81     }
82
83     public void addHierarchy(JRXmlaHierarchy hierarchy)
84     {
85         hierarchyList.add(hierarchy);
86         resetHierarchyArray();
87     }
88     
89     public void addTuple(JRXmlaMemberTuple tuple)
90     {
91         tuples.add(tuple);
92         
93         copyLevelInfo(tuple);
94     }
95
96     protected void copyLevelInfo(JRXmlaMemberTuple tuple)
97     {
98         JRXmlaMember[] members = tuple.getXmlaMembers();
99         int idx = 0;
100         for (Iterator JavaDoc it = hierarchyList.iterator(); it.hasNext() && idx < members.length; ++idx)
101         {
102             JRXmlaHierarchy hierarchy = (JRXmlaHierarchy) it.next();
103             JRXmlaMember member = members[idx];
104             if (hierarchy.getDimensionName().equals(member.getDimensionName()))
105             {
106                 hierarchy.setLevel(member.getLevelName(), member.getDepth());
107             }
108         }
109         
110     }
111
112     protected JRXmlaHierarchy[] ensureHierarchyArray()
113     {
114         if (hierarchies == null)
115         {
116             hierarchies = new JRXmlaHierarchy[hierarchyList.size()];
117             hierarchies = (JRXmlaHierarchy[]) hierarchyList.toArray(hierarchies);
118         }
119         return hierarchies;
120     }
121
122     protected void resetHierarchyArray()
123     {
124         hierarchies = null;
125     }
126
127 }
128
Popular Tags