View Javadoc

1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
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 }