KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > crosstabs > base > JRBaseCrosstabMeasure


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.crosstabs.base;
29
30 import java.io.Serializable JavaDoc;
31
32 import net.sf.jasperreports.crosstabs.JRCrosstabMeasure;
33 import net.sf.jasperreports.engine.JRConstants;
34 import net.sf.jasperreports.engine.JRExpression;
35 import net.sf.jasperreports.engine.JRRuntimeException;
36 import net.sf.jasperreports.engine.JRVariable;
37 import net.sf.jasperreports.engine.base.JRBaseObjectFactory;
38 import net.sf.jasperreports.engine.util.JRClassLoader;
39
40 /**
41  * Base read-only crosstab measure implementation.
42  *
43  * @author Lucian Chirita (lucianc@users.sourceforge.net)
44  * @version $Id: JRBaseCrosstabMeasure.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
45  */

46 public class JRBaseCrosstabMeasure implements JRCrosstabMeasure, Serializable JavaDoc
47 {
48     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
49
50     protected String JavaDoc name;
51     protected String JavaDoc valueClassName;
52     protected Class JavaDoc valueClass;
53     protected JRExpression expression;
54     protected byte calculation = JRVariable.CALCULATION_COUNT;
55     protected String JavaDoc incrementerFactoryClassName;
56     protected Class JavaDoc incrementerFactoryClass;
57     protected byte percentageOfType = JRCrosstabMeasure.PERCENTAGE_TYPE_NONE;
58     protected String JavaDoc percentageCalculatorClassName;
59     protected Class JavaDoc percentageCalculatorClass;
60     protected JRVariable variable;
61
62     protected JRBaseCrosstabMeasure()
63     {
64     }
65     
66     public JRBaseCrosstabMeasure(JRCrosstabMeasure measure, JRBaseObjectFactory factory)
67     {
68         factory.put(measure, this);
69         
70         this.name = measure.getName();
71         this.valueClassName = measure.getValueClassName();
72         this.expression = factory.getExpression(measure.getValueExpression());
73         this.calculation = measure.getCalculation();
74         this.incrementerFactoryClassName = measure.getIncrementerFactoryClassName();
75         this.percentageOfType = measure.getPercentageOfType();
76         this.percentageCalculatorClassName = measure.getPercentageCalculatorClassName();
77         this.variable = factory.getVariable(measure.getVariable());
78     }
79     
80     public String JavaDoc getName()
81     {
82         return name;
83     }
84
85     public String JavaDoc getValueClassName()
86     {
87         return valueClassName;
88     }
89
90     public JRExpression getValueExpression()
91     {
92         return expression;
93     }
94
95     public byte getCalculation()
96     {
97         return calculation;
98     }
99
100     public String JavaDoc getIncrementerFactoryClassName()
101     {
102         return incrementerFactoryClassName;
103     }
104
105     public byte getPercentageOfType()
106     {
107         return percentageOfType;
108     }
109
110     public Class JavaDoc getIncrementerFactoryClass()
111     {
112         if (incrementerFactoryClass == null && incrementerFactoryClassName != null)
113         {
114             try
115             {
116                 incrementerFactoryClass = JRClassLoader.loadClassForName(incrementerFactoryClassName);
117             }
118             catch (ClassNotFoundException JavaDoc e)
119             {
120                 throw new JRRuntimeException("Could not load measure incrementer class", e);
121             }
122         }
123         
124         return incrementerFactoryClass;
125     }
126
127     public Class JavaDoc getValueClass()
128     {
129         if (valueClass == null && valueClassName != null)
130         {
131             try
132             {
133                 valueClass = JRClassLoader.loadClassForName(valueClassName);
134             }
135             catch (ClassNotFoundException JavaDoc e)
136             {
137                 throw new JRRuntimeException("Could not load bucket value class", e);
138             }
139         }
140         
141         return valueClass;
142     }
143
144     public JRVariable getVariable()
145     {
146         return variable;
147     }
148
149     public String JavaDoc getPercentageCalculatorClassName()
150     {
151         return percentageCalculatorClassName;
152     }
153
154     public Class JavaDoc getPercentageCalculatorClass()
155     {
156         if (percentageCalculatorClass == null && percentageCalculatorClassName != null)
157         {
158             try
159             {
160                 percentageCalculatorClass = JRClassLoader.loadClassForName(percentageCalculatorClassName);
161             }
162             catch (ClassNotFoundException JavaDoc e)
163             {
164                 throw new JRRuntimeException("Could not load measure percentage calculator class", e);
165             }
166         }
167         
168         return percentageCalculatorClass;
169     }
170 }
171
Popular Tags