1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.asn1.ber.digester.rules ;
18
19
20 import org.apache.asn1.ber.TypeClass;
21 import org.apache.asn1.ber.digester.AbstractRule;
22 import org.apache.asn1.ber.digester.BERDigester;
23 import org.apache.commons.lang.exception.NestableRuntimeException;
24
25
26 /***
27 * Rule implementation that creates a new object and pushes it onto the
28 * object stack when a TLV is encountered. When the TLV is complete,
29 * the object will be popped off of the stack.
30 *
31 * @author <a href="mailto:dev@directory.apache.org">Apache Direclectory Project</a>
32 * @version $Rev: 157644 $
33 */
34 public class ObjectCreateRule extends AbstractRule
35 {
36 /*** the class of object to instantiate and push */
37 private final Class clazz ;
38
39
40 /***
41 * Creates a rule that creates an instance of an object when the tag
42 *
43 * @param clazz the class to create an instance of.
44 */
45 public ObjectCreateRule( BERDigester digester, Class clazz )
46 {
47 this.clazz = clazz ;
48 setDigester( digester ) ;
49 }
50
51
52
53
54
55
56 public void tag( int id, boolean isPrimitive, TypeClass typeClass )
57 {
58 try
59 {
60 Object obj = clazz.newInstance() ;
61 getDigester().push( obj ) ;
62 }
63 catch ( InstantiationException e )
64 {
65 throw new NestableRuntimeException( e ) ;
66 }
67 catch ( IllegalAccessException e )
68 {
69 throw new NestableRuntimeException( e ) ;
70 }
71 }
72
73
74
75
76
77 public void finish()
78 {
79 getDigester().pop() ;
80 }
81 }
82