Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jbreport/core/DefaultReportVisitor.java


1   /*
2    * $Id: DefaultReportVisitor.java,v 1.1 2000/08/31 13:53:17 grantfin Exp $
3    *
4    * jbReport - A reporting library for Java
5    * Copyright (C) 2000 Grant Finnemore <grantfin@users.sourceforge.net>
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 2 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   */
21  package jbreport.core;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import jbreport.ReportElement;
27  import jbreport.ReportException;
28  
29  /**
30   * This is an implementation of the ReportVisitor interface which does nothing.
31   * It is provided as a convenience to aid writing concrete implementations of 
32   * the ReportVisitor class.
33   *
34   * <p> For more advanced uses, this class implements the Composite pattern, 
35   * and enables more than one ReportVisitor to be used for every traversal.
36   *
37   * @author Grant Finnemore
38   * @version $Revision: 1.1 $
39   */
40  public 
41  class DefaultReportVisitor implements ReportVisitor {
42  
43     /** The children of this Visitor. */
44     private List children;
45  
46     //
47     // Public interface
48     //
49  
50     /**
51      * This method will add the given ReportVisitor instance to an internal
52      * collection, and on every visit method, all the child visitors will
53      * be invoked.
54      */
55     public void addChild(ReportVisitor child) {
56        if(child == null) {
57           throw new IllegalArgumentException("child cannot be null");
58        }
59        if(children == null) {
60           children = new ArrayList();
61        }
62        children.add(child);
63     }
64  
65     //
66     // Implementation of the ReportVisitor interface
67     //
68  
69     public void visitReportComposite(ReportElement elem, 
70                                      ReportVisitorState state) 
71        throws ReportException {
72        // Try to traverse any children - if they exist
73        if(children != null) {
74           for(int i = 0; i < children.size(); i++) {
75              ((ReportVisitor)children.get(i)).visitReportComposite(elem, state);
76           }
77        }
78     }
79  
80     public void visitGroup(ReportElement elem, ReportVisitorState state)
81        throws ReportException {
82        // Try to traverse any children - if they exist
83        if(children != null) {
84           for(int i = 0; i < children.size(); i++) {
85              ((ReportVisitor)children.get(i)).visitGroup(elem, state);
86           }
87        }
88     }
89  
90     public void visitReportSection(ReportElement elem, ReportVisitorState state)
91        throws ReportException {
92        // Try to traverse any children - if they exist
93        if(children != null) {
94           for(int i = 0; i < children.size(); i++) {
95              ((ReportVisitor)children.get(i)).visitReportSection(elem, state);
96           }
97        }
98     }
99  
100    public void visitQuery(ReportElement elem, ReportVisitorState state) 
101       throws ReportException {
102       // Try to traverse any children - if they exist
103       if(children != null) {
104          for(int i = 0; i < children.size(); i++) {
105             ((ReportVisitor)children.get(i)).visitQuery(elem, state);
106          }
107       }
108    }
109 
110    public void visitDatasource(ReportElement elem, ReportVisitorState state)
111       throws ReportException {
112       // Try to traverse any children - if they exist
113       if(children != null) {
114          for(int i = 0; i < children.size(); i++) {
115             ((ReportVisitor)children.get(i)).visitDatasource(elem, state);
116          }
117       }
118    }
119 
120    public void visitRepository(ReportElement elem, ReportVisitorState state) 
121       throws ReportException {
122       // Try to traverse any children - if they exist
123       if(children != null) {
124          for(int i = 0; i < children.size(); i++) {
125             ((ReportVisitor)children.get(i)).visitRepository(elem, state);
126          }
127       }
128    }
129 
130    public void visitDocument(ReportElement elem, ReportVisitorState state) 
131       throws ReportException {
132       // Try to traverse any children - if they exist
133       if(children != null) {
134          for(int i = 0; i < children.size(); i++) {
135             ((ReportVisitor)children.get(i)).visitDocument(elem, state);
136          }
137       }
138    }
139 
140    public void visitFragment(ReportElement elem, ReportVisitorState state) 
141       throws ReportException {
142       // Try to traverse any children - if they exist
143       if(children != null) {
144          for(int i = 0; i < children.size(); i++) {
145             ((ReportVisitor)children.get(i)).visitFragment(elem, state);
146          }
147       }
148    }
149 
150    public void visitInclude(ReportElement elem, ReportVisitorState state) 
151       throws ReportException {
152       // Try to traverse any children - if they exist
153       if(children != null) {
154          for(int i = 0; i < children.size(); i++) {
155             ((ReportVisitor)children.get(i)).visitInclude(elem, state);
156          }
157       }
158    }
159 
160    public void visitQueryBoundResult(ReportElement elem, 
161                                      ReportVisitorState state) 
162       throws ReportException {
163       // Try to traverse any children - if they exist
164       if(children != null) {
165          for(int i = 0; i < children.size(); i++) {
166             ((ReportVisitor)children.get(i))
167                .visitQueryBoundResult(elem, state);
168          }
169       }
170    }
171    
172    public void visitSectionBreak(ReportElement elem, ReportVisitorState state)
173       throws ReportException {
174       // Try to traverse any children - if they exist
175       if(children != null) {
176          for(int i = 0; i < children.size(); i++) {
177             ((ReportVisitor)children.get(i)).visitSectionBreak(elem, state);
178          }
179       }
180    }
181 
182    public void visitTLine(ReportElement elem, ReportVisitorState state) 
183       throws ReportException {
184       // Try to traverse any children - if they exist
185       if(children != null) {
186          for(int i = 0; i < children.size(); i++) {
187             ((ReportVisitor)children.get(i)).visitTLine(elem, state);
188          }
189       }
190    }
191 
192    public void visitTable(ReportElement elem, ReportVisitorState state) 
193       throws ReportException {
194       // Try to traverse any children - if they exist
195       if(children != null) {
196          for(int i = 0; i < children.size(); i++) {
197             ((ReportVisitor)children.get(i)).visitTable(elem, state);
198          }
199       }
200    }
201 
202    public void visitTableHeaderRow(ReportElement elem, 
203                                    ReportVisitorState state) 
204       throws ReportException {
205       // Try to traverse any children - if they exist
206       if(children != null) {
207          for(int i = 0; i < children.size(); i++) {
208             ((ReportVisitor)children.get(i)).visitTableHeaderRow(elem, state);
209          }
210       }
211    }
212 
213    public void visitTableHeaderItem(ReportElement elem, 
214                                     ReportVisitorState state)
215       throws ReportException {
216       // Try to traverse any children - if they exist
217       if(children != null) {
218          for(int i = 0; i < children.size(); i++) {
219             ((ReportVisitor)children.get(i)).visitTableHeaderItem(elem, state);
220          }
221       }
222    }
223 
224    public void visitTableRow(ReportElement elem, ReportVisitorState state)
225       throws ReportException {
226       // Try to traverse any children - if they exist
227       if(children != null) {
228          for(int i = 0; i < children.size(); i++) {
229             ((ReportVisitor)children.get(i)).visitTableRow(elem, state);
230          }
231       }
232    }
233 
234    public void visitStylesheet(ReportElement elem, ReportVisitorState state)
235       throws ReportException {
236       // Try to traverse any children - if they exist
237       if(children != null) {
238          for(int i = 0; i < children.size(); i++) {
239             ((ReportVisitor)children.get(i)).visitStylesheet(elem, state);
240          }
241       }
242    }
243 
244    public void visitStyle(ReportElement elem, ReportVisitorState state)
245       throws ReportException {
246       // Try to traverse any children - if they exist
247       if(children != null) {
248          for(int i = 0; i < children.size(); i++) {
249             ((ReportVisitor)children.get(i)).visitStyle(elem, state);
250          }
251       }
252    }
253 
254    public void visitAggregate(ReportElement elem, ReportVisitorState state)
255       throws ReportException {
256       // Try to traverse any children - if they exist
257       if(children != null) {
258          for(int i = 0; i < children.size(); i++) {
259             ((ReportVisitor)children.get(i)).visitStyle(elem, state);
260          }
261       }
262    }
263 
264 }