001 /**
002 * ========================================
003 * JFreeReport : a free Java report library
004 * ========================================
005 *
006 * Project Info: http://reporting.pentaho.org/
007 *
008 * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
009 *
010 * This library is free software; you can redistribute it and/or modify it under the terms
011 * of the GNU Lesser General Public License as published by the Free Software Foundation;
012 * either 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, but WITHOUT ANY WARRANTY;
015 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016 * See the GNU Lesser General Public License for more details.
017 *
018 * You should have received a copy of the GNU Lesser General Public License along with this
019 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020 * Boston, MA 02111-1307, USA.
021 *
022 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023 * in the United States and other countries.]
024 *
025 * ------------
026 * $Id: Node.java,v 1.6 2007/04/01 18:49:33 taqua Exp $
027 * ------------
028 * (C) Copyright 2000-2005, by Object Refinery Limited.
029 * (C) Copyright 2005-2007, by Pentaho Corporation.
030 */
031 package org.jfree.report.structure;
032
033 import java.io.Serializable;
034 import java.util.Locale;
035
036 import org.jfree.report.JFreeReport;
037 import org.jfree.report.expressions.Expression;
038
039 /**
040 * A node is the most basic unit in a report. It acts as general superclass for
041 * all other elements.
042 *
043 * @author Thomas Morgner
044 */
045 public abstract class Node implements Serializable, Cloneable
046 {
047 private Node parent;
048
049 protected Node()
050 {
051 }
052
053 public Node getParent()
054 {
055 return parent;
056 }
057
058 protected void setParent(final Node parent)
059 {
060 this.parent = parent;
061 }
062
063 /**
064 * This is an extra method to allow me to track all *illegal* write-accesses
065 * to the parent.
066 *
067 * @param parent
068 */
069 public void updateParent(final Node parent)
070 {
071 this.parent = parent;
072 }
073
074 public Group getGroup()
075 {
076 Node parent = getParent();
077 while (parent != null)
078 {
079 if (parent instanceof Group)
080 {
081 return (Group) parent;
082 }
083
084 parent = parent.getParent();
085 }
086 return null;
087 }
088
089 public ReportDefinition getReport()
090 {
091 Node parent = getParent();
092 while (parent != null)
093 {
094 if (parent instanceof ReportDefinition)
095 {
096 return (ReportDefinition) parent;
097 }
098
099 parent = parent.getParent();
100 }
101 return null;
102 }
103
104 public JFreeReport getRootReport()
105 {
106 Node parent = getParent();
107 while (parent != null)
108 {
109 if (parent instanceof JFreeReport)
110 {
111 return (JFreeReport) parent;
112 }
113
114 parent = parent.getParent();
115 }
116 return null;
117 }
118
119 public Locale getLocale()
120 {
121 if (parent != null)
122 {
123 return parent.getLocale();
124 }
125 return Locale.getDefault();
126 }
127
128 public Expression getDisplayCondition()
129 {
130 return null;
131 }
132
133 public boolean isEnabled()
134 {
135 return true;
136 }
137
138 public Object clone () throws CloneNotSupportedException
139 {
140 return super.clone();
141 }
142 }