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 decoder.
23 *
24 * @author <a href="mailto:dev@directory.apache.org">
25 * Apache Directory Project</a>
26 * @version $Rev: 157644 $
27 */
28 public abstract class AbstractStatefulDecoder implements StatefulDecoder
29 {
30 /*** this decoder's callback */
31 private DecoderCallback cb = null ;
32 /*** this decoder's monitor */
33 private DecoderMonitor monitor = null ;
34
35
36
37
38
39
40
41 /***
42 * Creates a stateful decoder where the callback and monitor must be set.
43 */
44 public AbstractStatefulDecoder()
45 {
46 }
47
48
49 /***
50 * Creates a stateful decoder with a callback.
51 *
52 * @param cb the callback to use for this decoder
53 */
54 public AbstractStatefulDecoder( DecoderCallback cb )
55 {
56 setCallback( cb ) ;
57 }
58
59
60 /***
61 * Creates a stateful decoder with a monitor but no callback.
62 *
63 * @param monitor the monitor to use for this decoder
64 */
65 public AbstractStatefulDecoder( DecoderMonitor monitor )
66 {
67 this.monitor = monitor ;
68 }
69
70
71 /***
72 * Creates a stateful decoder.
73 *
74 * @param cb the callback to use for this decoder
75 * @param monitor the monitor to use for this decoder
76 */
77 public AbstractStatefulDecoder( DecoderCallback cb, DecoderMonitor 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( DecoderCallback cb )
94 {
95 DecoderCallback 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 setDecoderMonitor( DecoderMonitor 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 decoder has
122 * decoded a unit of encoded data.
123 *
124 * @param decoded the decoded byproduct.
125 */
126 protected void decodeOccurred( Object decoded )
127 {
128 if ( cb != null )
129 {
130 cb.decodeOccurred( this, decoded ) ;
131 }
132 }
133
134
135 /***
136 * Gets the decoder's monitor.
137 *
138 * @return the monitor for this StatefulDecoder
139 */
140 protected DecoderMonitor getDecoderMonitor()
141 {
142 return monitor ;
143 }
144 }