1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.asn1.ber ;
18
19
20 /***
21 * Abstract base class for type safe tag enumerations following the agreed upon
22 * convention for representing tags as integers. This way the type safe
23 * enumeration also represents a preconstructed tag. ASN.1 application module
24 * specific enumerations should extend this base for use with the digester.
25 *
26 * @see <a href="">link to a document explaining how we encoded prefab tags</a>
27 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
28 * @version $Rev: 289141 $
29 */
30 public abstract class TagEnum
31 {
32 /*** the id for this tag */
33 private final int id ;
34 /*** the name of this enumeration element */
35 private final String name;
36 /*** the value of this enumeration element */
37 private final int value;
38
39
40 protected TagEnum( final String name, final int value, final int id )
41 {
42 this.id = id ;
43 this.name = name;
44 this.value = value;
45 }
46
47
48 /***
49 * Get's the name of this enumeration element.
50 *
51 * @return the name of the enumeration element
52 */
53 public final String getName()
54 {
55 return this.name;
56 }
57
58
59 /***
60 * Get's the value of this enumeration element.
61 *
62 * @return the value of the enumeration element
63 */
64 public final int getValue()
65 {
66 return this.value;
67 }
68
69
70 /***
71 * Gets the id of this tag.
72 *
73 * @return the id of the tag
74 */
75 public final int getTagId()
76 {
77 return this.id ;
78 }
79
80
81 /***
82 * Gets the primitive version of a tag.
83 *
84 * @return the primitive version of a tag with the P/C bit set to 0
85 */
86 public final int getPrimitiveTag()
87 {
88 return getValue() & 0xDFFFFFFF ;
89 }
90
91
92 /***
93 * Gets the constructed version of a tag.
94 *
95 * @return the constructed version of a tag with the P/C bit set to 1
96 */
97 public final int getConstructedTag()
98 {
99 return getValue() | 0x20000000 ;
100 }
101
102
103 /***
104 * Gets the type class of a tag.
105 *
106 * @return the type class for this tag enumeration.
107 */
108 public final TypeClass getTypeClass()
109 {
110 return TypeClass.getTypeClass( getValue() >> 24 ) ;
111 }
112 }