1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.asn1.codec.stateful ;
18
19
20 /***
21 * Convenience class to not have to reimplement the two setter methods everytime
22 * one starts a new encoder.
23 *
24 * @author <a href="mailto:dev@directory.apache.org">
25 * Apache Directory Project</a>
26 * @version $Rev: 157644 $
27 */
28 public abstract class AbstractStatefulEncoder implements StatefulEncoder
29 {
30 /*** this encoder's callback */
31 private EncoderCallback cb = null ;
32 /*** this encoder's monitor */
33 private EncoderMonitor monitor = null ;
34
35
36
37
38
39
40
41 /***
42 * Creates a stateful encoder where the callback and monitor must be set.
43 */
44 public AbstractStatefulEncoder()
45 {
46 }
47
48
49 /***
50 * Creates a stateful encoder with a callback.
51 *
52 * @param cb the callback to use for this encoder
53 */
54 public AbstractStatefulEncoder( EncoderCallback cb )
55 {
56 setCallback( cb ) ;
57 }
58
59
60 /***
61 * Creates a stateful encoder with a monitor but no callback.
62 *
63 * @param monitor the monitor to use for this encoder
64 */
65 public AbstractStatefulEncoder( EncoderMonitor monitor )
66 {
67 this.monitor = monitor ;
68 }
69
70
71 /***
72 * Creates a stateful encoder.
73 *
74 * @param cb the callback to use for this encoder
75 * @param monitor the monitor to use for this encoder
76 */
77 public AbstractStatefulEncoder( EncoderCallback cb, EncoderMonitor monitor )
78 {
79 this.monitor = monitor ;
80 setCallback( cb ) ;
81 }
82
83
84
85
86
87
88
89
90
91
92
93 public void setCallback( EncoderCallback cb )
94 {
95 EncoderCallback old = this.cb ;
96 this.cb = cb ;
97
98 if ( this.monitor != null )
99 {
100 this.monitor.callbackSet( this, old, cb );
101 }
102 }
103
104
105
106
107
108
109 public void setEncoderMonitor( EncoderMonitor monitor )
110 {
111 this.monitor = monitor ;
112 }
113
114
115
116
117
118
119
120 /***
121 * Notifies via the callback if one has been set that this encoder has
122 * encoded a unit of encoded data.
123 *
124 * @param encoded the encoded byproduct.
125 */
126 protected void encodeOccurred( Object encoded )
127 {
128 if ( cb != null )
129 {
130 cb.encodeOccurred( this, encoded ) ;
131 }
132 }
133
134
135 /***
136 * Gets the encoder's monitor.
137 *
138 * @return the monitor for this StatefulEncoder
139 */
140 protected EncoderMonitor getEncoderMonitor()
141 {
142 return monitor ;
143 }
144 }