KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > data > olap > WalkableWrapper


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * WalkableWrapper.java
28  *
29  * Created on June 20, 2006, 5:14 PM
30  *
31  */

32
33 package it.businesslogic.ireport.data.olap;
34
35 import it.businesslogic.ireport.util.Misc;
36 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
37 import mondrian.olap.*;
38 /**
39  *
40  * @author gtoffoli
41  */

42 public class WalkableWrapper {
43     
44     Object JavaDoc walkable = null;
45     String JavaDoc name = "";
46     private DefaultMutableTreeNode JavaDoc parentNode = null;
47     
48     
49     /** Creates a new instance of WalkableWrapper */
50     public WalkableWrapper(Object JavaDoc obj, DefaultMutableTreeNode JavaDoc parentNode) {
51         this.walkable = obj;
52         
53         this.parentNode = parentNode;
54         if (walkable instanceof QueryAxis)
55         {
56             name = ((QueryAxis)walkable).getAxisName();
57         }
58         else if (walkable instanceof FunCall)
59         {
60             name = ((FunCall)walkable).getFunName();
61         }
62         else if (walkable instanceof Level)
63         {
64             name = ((Level)walkable).getName();
65         }
66         else if (walkable instanceof Hierarchy)
67         {
68             name = ((Hierarchy)walkable).getName();
69         }
70         else if (walkable instanceof Member)
71         {
72             name = ((Member)walkable).getName();
73         }
74         else
75         {
76             name = getWalkable() + " (" + walkable.getClass().getName();
77         }
78     }
79     
80     public boolean isMeasure()
81     {
82         return (walkable instanceof Member) && ((Member)walkable).isMeasure();
83     }
84     
85     public String JavaDoc getExpression()
86     {
87         if (isMeasure())
88         {
89            int qmarks = parentNode.getChildCount();
90            String JavaDoc s = "Data(" + walkable + "";
91            for (int i=0; i<qmarks-1; ++i)
92            {
93                s +=",?";
94            }
95            s +=")";
96            return s;
97         }
98         else if (walkable instanceof Level)
99         {
100             // Find the ancestor dimension...
101
DefaultMutableTreeNode JavaDoc node = getParentNode();
102             DefaultMutableTreeNode JavaDoc nodeParent = (DefaultMutableTreeNode JavaDoc)getParentNode().getParent();
103             while (nodeParent.getParent() != null)
104             {
105                 node = nodeParent;
106                 nodeParent = (DefaultMutableTreeNode JavaDoc)nodeParent.getParent();
107             }
108             int axisIndex = nodeParent.getIndex( node );
109             
110             String JavaDoc s = "";
111             switch (axisIndex)
112             {
113                 case 0:
114                     s = "Columns";
115                     break;
116                 case 1:
117                     s = "Rows";
118                     break;
119                 case 2:
120                     s = "Pages";
121                     break;
122                 case 3:
123                     s = "Chapters";
124                     break;
125                 case 4:
126                     s = "Sections";
127                     break;
128                 default:
129                     s = "Axis(" + axisIndex +")";
130             }
131             
132             s = s + Misc.string_replace("][","].[", ""+ walkable) + "";
133             
134             return s;
135         }
136         else
137         {
138             return null;
139         }
140         
141         //return walkable+"";
142
}
143     
144     public Object JavaDoc getWalkable()
145     {
146         return walkable;
147     }
148     
149     public void setWalkable(Object JavaDoc w)
150     {
151         walkable = w;
152     }
153     
154     public String JavaDoc toString()
155     {
156         return name;
157         
158     }
159
160     public DefaultMutableTreeNode JavaDoc getParentNode() {
161         return parentNode;
162     }
163
164     public void setParentNode(DefaultMutableTreeNode JavaDoc parentNode) {
165         this.parentNode = parentNode;
166     }
167     
168 }
169
Popular Tags