001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.olap.xmla;
029:
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: import org.apache.commons.logging.Log;
034: import org.apache.commons.logging.LogFactory;
035:
036: import net.sf.jasperreports.olap.result.JROlapHierarchy;
037: import net.sf.jasperreports.olap.result.JROlapHierarchyLevel;
038:
039: /**
040: * @author Lucian Chirita (lucianc@users.sourceforge.net)
041: * @version $Id: JRXmlaHierarchy.java 1446 2006-10-25 09:00:05Z lucianc $
042: */
043: public class JRXmlaHierarchy implements JROlapHierarchy {
044:
045: private final static Log log = LogFactory
046: .getLog(JRXmlaHierarchy.class);
047:
048: private final String dimensionName;
049: private final List levels;
050: private JRXmlaHierarchyLevel[] levelArray;
051:
052: public JRXmlaHierarchy(String dimensionName) {
053: this .dimensionName = dimensionName;
054: this .levels = new ArrayList();
055: }
056:
057: public String getDimensionName() {
058: return dimensionName;
059: }
060:
061: public JROlapHierarchyLevel[] getLevels() {
062: return ensureLevelArray();
063: }
064:
065: public void setLevel(String levelName, int depth) {
066: int levelCount = levels.size();
067: if (depth >= levelCount) {
068: for (int i = levelCount; i <= depth; ++i) {
069: levels.add(null);
070: }
071: }
072:
073: JRXmlaHierarchyLevel level = (JRXmlaHierarchyLevel) levels
074: .get(depth);
075: if (level == null) {
076: level = new JRXmlaHierarchyLevel(levelName, depth);
077: levels.set(depth, level);
078: } else if (!levelName.equals(level.getName())) {
079: if (log.isWarnEnabled()) {
080: log.warn("Different level name \"" + levelName
081: + "\" found for level \"" + level.getName()
082: + "\" at depth " + depth);
083: }
084: }
085:
086: resetLevelArray();
087: }
088:
089: protected JRXmlaHierarchyLevel[] ensureLevelArray() {
090: if (levelArray == null) {
091: levelArray = new JRXmlaHierarchyLevel[levels.size()];
092: levelArray = (JRXmlaHierarchyLevel[]) levels
093: .toArray(levelArray);
094: }
095: return levelArray;
096: }
097:
098: protected void resetLevelArray() {
099: levelArray = null;
100: }
101: }
|