KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > lists > FilterConsumer


1 // Copyright (c) 2000, 2001 Per M.A. Bothner and Brainfood Inc.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.lists;
5
6 /** A Consumer that wraps some other Consumer. */
7
8 public class FilterConsumer
9   implements Consumer
10 {
11   protected Consumer base;
12   protected boolean skipping;
13   /** We seen a beginAttribute but not the closing endAttribute. */
14   protected boolean inAttribute;
15   /** The 'attribute type' from the most recent beginAttribute. */
16   protected Object JavaDoc attributeType;
17
18   public FilterConsumer (Consumer base)
19   {
20     this.base = base;
21   }
22
23   protected void beforeContent ()
24   {
25   }
26
27   public void write (int v)
28   {
29     beforeContent();
30     if (! skipping)
31       base.write(v);
32   }
33
34   public void writeBoolean(boolean v)
35   {
36     beforeContent();
37     if (! skipping)
38       base.writeBoolean(v);
39   }
40
41   public void writeFloat(float v)
42   {
43     beforeContent();
44     if (! skipping)
45       base.writeFloat(v);
46   }
47
48   public void writeDouble(double v)
49   {
50     beforeContent();
51     if (! skipping)
52       base.writeDouble(v);
53   }
54
55   public void writeInt(int v)
56   {
57     beforeContent();
58     if (! skipping)
59       base.writeInt(v);
60   }
61
62   public void writeLong(long v)
63   {
64     beforeContent();
65     if (! skipping)
66       base.writeLong(v);
67   }
68
69   public void beginDocument()
70   {
71     if (! skipping)
72       base.beginDocument();
73   }
74
75   public void endDocument()
76   {
77     if (! skipping)
78       base.endDocument();
79   }
80
81   public void beginGroup (Object JavaDoc type)
82   {
83     if (! skipping)
84       base.beginGroup(type);
85   }
86
87   public void endGroup ()
88   {
89     if (! skipping)
90       base.endGroup();
91   }
92
93   public void beginAttribute (Object JavaDoc attrType)
94   {
95     attributeType = attrType;
96     inAttribute = true;
97     if (! skipping)
98       base.beginAttribute(attrType);
99   }
100
101   public void endAttribute()
102   {
103     if (! skipping)
104       base.endAttribute();
105     inAttribute = false;
106   }
107
108   public void writeObject(Object JavaDoc v)
109   {
110     beforeContent();
111     if (! skipping)
112       base.writeObject(v);
113   }
114
115   public boolean ignoring()
116   {
117     return base.ignoring();
118   }
119
120   public void write(char[] buf, int off, int len)
121   {
122     beforeContent();
123     if (! skipping)
124       base.write(buf, off, len);
125   }
126
127   public void write (String JavaDoc str)
128   {
129     write(str, 0, str.length());
130   }
131
132   /* #ifdef use:java.lang.CharSequence */
133   public void write (CharSequence JavaDoc str, int start, int length)
134   /* #else */
135   // public void write (String str, int start, int length)
136
/* #endif */
137   {
138     beforeContent();
139     if (! skipping)
140       base.write(str, start, length);
141   }
142
143   /* #ifdef JAVA5 */
144   // public Consumer append (char c)
145
// {
146
// write(c);
147
// return this;
148
// }
149

150   // public Consumer append (CharSequence csq)
151
// {
152
// if (csq == null)
153
// csq = "null";
154
// append(csq, 0, csq.length());
155
// return this;
156
// }
157

158   // public Consumer append (CharSequence csq, int start, int end)
159
// {
160
// beforeContent();
161
// if (! skipping)
162
// {
163
// if (csq == null)
164
// csq = "null";
165
// base.append(csq, start, end);
166
// }
167
// return this;
168
// }
169
/* #endif */
170 }
171
Popular Tags