View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.directory.shared.kerberos.codec.etypeInfo;
21  
22  
23  import org.apache.directory.api.asn1.actions.CheckNotNullLength;
24  import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
25  import org.apache.directory.api.asn1.ber.grammar.Grammar;
26  import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
27  import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
28  import org.apache.directory.shared.kerberos.codec.etypeInfo.actions.AddETypeInfoEntry;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  
32  
33  /**
34   * This class implements the ETYPE-INFO structure. All the actions are declared
35   * in this class. As it is a singleton, these declaration are only done once. If
36   * an action is to be added or modified, this is where the work is to be done !
37   *
38   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39   */
40  public final class ETypeInfoGrammar extends AbstractGrammar<ETypeInfoContainer>
41  {
42      /** The logger */
43      static final Logger LOG = LoggerFactory.getLogger( ETypeInfoGrammar.class );
44  
45      /** A speedup for logger */
46      static final boolean IS_DEBUG = LOG.isDebugEnabled();
47  
48      /** The instance of grammar. ETypeInfoGrammar is a singleton */
49      private static Grammar<ETypeInfoContainer> instance = new ETypeInfoGrammar();
50  
51  
52      /**
53       * Creates a new ETypeInfoGrammar object.
54       */
55      @SuppressWarnings("unchecked")
56      private ETypeInfoGrammar()
57      {
58          setName( ETypeInfoGrammar.class.getName() );
59  
60          // Create the transitions table
61          super.transitions = new GrammarTransition[ETypeInfoStatesEnum.LAST_ETYPE_INFO_STATE.ordinal()][256];
62  
63          // ============================================================================================
64          // ETYPE-INFO
65          // ============================================================================================
66          // --------------------------------------------------------------------------------------------
67          // Transition from ETYPE-INFO init to ETYPE-INFO SEQ
68          // --------------------------------------------------------------------------------------------
69          // ETYPE-INFO-ENTRY         ::= SEQUENCE
70          super.transitions[ETypeInfoStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
71              new GrammarTransition<ETypeInfoContainer>(
72                  ETypeInfoStatesEnum.START_STATE,
73                  ETypeInfoStatesEnum.ETYPE_INFO_SEQ_STATE,
74                  UniversalTag.SEQUENCE,
75                  new CheckNotNullLength<ETypeInfoContainer>() );
76  
77          // --------------------------------------------------------------------------------------------
78          // Transition from ETYPE-INFO init to ETYPE-INFO SEQ
79          // --------------------------------------------------------------------------------------------
80          // ETYPE-INFO-ENTRY         ::= SEQUENCE OF <ETYPE-INFO-ENTRY>
81          //
82          super.transitions[ETypeInfoStatesEnum.ETYPE_INFO_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
83              new GrammarTransition<ETypeInfoContainer>(
84                  ETypeInfoStatesEnum.ETYPE_INFO_SEQ_STATE,
85                  ETypeInfoStatesEnum.ETYPE_INFO_SEQ_STATE,
86                  UniversalTag.SEQUENCE,
87                  new AddETypeInfoEntry() );
88      }
89  
90  
91      /**
92       * Get the instance of this grammar
93       *
94       * @return An instance on the ETYPE-INFO Grammar
95       */
96      public static Grammar<ETypeInfoContainer> getInstance()
97      {
98          return instance;
99      }
100 }