Source code: org/pqt/autorib/instr/InstrBlockRequest.java
1 //AutoRIB
2 // Copyright © 1998 - 2002, P W Quint
3 //
4 // Contact: autorib00@aol.com
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 package org.pqt.autorib.instr;
21 import java.io.*;
22 import java.util.*;
23 import org.pqt.autorib.tokenizer.*;
24 import org.pqt.autorib.globals.*;
25 import org.pqt.autorib.util.*;
26 import org.pqt.autorib.rib.*;
27
28
29 /** This class is the superclass of all block style requests,
30 * extending InstrRequest.
31 * It includes methods to process lights and objects (
32 * which check if the block is applies to
33 * the given light
34 * or object and if so iterate through the instructions in the block) and filter
35 * (which is called by process and returns true if the block should be executed for
36 * the given light or object)
37 * <p> Note that the read method of this class reads and stores all the
38 * instructions in the block*/
39
40 public abstract class InstrBlockRequest extends InstrRequest {
41 /** Stores the instructions in the block */
42 protected Vector content = new Vector(10,10);
43
44
45 /** execute the instructions in the block if the current light
46 * passes the filter (if any)
47 * @param rw InstrWReader linked to the current input stream
48 * @param light the light being processed */
49 public void process(InstrWReader rw, RIBLight light) throws FormatException,
50 IOException {
51 Enumeration i;
52
53 if ((content != null) && (filter(light))) {
54 i = content.elements();
55 while (i.hasMoreElements())
56 ((InstrRequest)i.nextElement()).process(rw, light);
57 }
58 }
59
60 /** execute the instructions in the block if appropriate
61 * @param rw InstrWReader linked to the current input stream
62 * @param object the object being processed */
63 public void process(InstrWReader rw, RIBObjectGroup object) throws
64 FormatException, IOException {
65 Enumeration i;
66
67 if ((content != null) && (filter(object))) {
68 i = content.elements();
69 while (i.hasMoreElements())
70 ((InstrRequest)i.nextElement()).process(rw, object);
71 }
72 }
73
74 /** return true if the instructions in the block should be executed
75 * for the given light - return false by default - subclasses
76 * should override this if they handle lights*/
77 protected boolean filter(RIBLight light) throws FormatException {
78 return false;
79 }
80
81 /** return true if the instructions in the block should be executed
82 * for the given object - return false by default
83 * - subclasses should override if they handle objects*/
84 protected boolean filter(RIBObjectGroup object) {
85 return false;
86 }
87
88 }
89
90
91