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.methodData;
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.methodData.actions.AddPaData;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  
32  
33  /**
34   * This class implements the METHOD-DATA 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 MethodDataGrammar extends AbstractGrammar<MethodDataContainer>
41  {
42      /** The logger */
43      static final Logger LOG = LoggerFactory.getLogger( MethodDataGrammar.class );
44  
45      /** A speedup for logger */
46      static final boolean IS_DEBUG = LOG.isDebugEnabled();
47  
48      /** The instance of grammar. MethodDataGrammar is a singleton */
49      private static Grammar<MethodDataContainer> instance = new MethodDataGrammar();
50  
51  
52      /**
53       * Creates a new MethodDataGrammar object.
54       */
55      @SuppressWarnings("unchecked")
56      private MethodDataGrammar()
57      {
58          setName( MethodDataGrammar.class.getName() );
59  
60          // Create the transitions table
61          super.transitions = new GrammarTransition[MethodDataStatesEnum.LAST_METHOD_DATA_STATE.ordinal()][256];
62  
63          // ============================================================================================
64          // METHOD-DATA
65          // ============================================================================================
66          // --------------------------------------------------------------------------------------------
67          // Transition from METHOD-DATA init to METHOD-DATA SEQ
68          // --------------------------------------------------------------------------------------------
69          // METHOD-DATA         ::= SEQUENCE
70          super.transitions[MethodDataStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
71              new GrammarTransition<MethodDataContainer>(
72                  MethodDataStatesEnum.START_STATE,
73                  MethodDataStatesEnum.METHOD_DATA_SEQ_STATE,
74                  UniversalTag.SEQUENCE,
75                  new CheckNotNullLength<MethodDataContainer>() );
76  
77          // --------------------------------------------------------------------------------------------
78          // Transition from METHOD-DATA SEQ to PA-DATA
79          // --------------------------------------------------------------------------------------------
80          // METHOD-DATA         ::= SEQUENCE OF <PA-DATA>
81          //
82          super.transitions[MethodDataStatesEnum.METHOD_DATA_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
83              new GrammarTransition<MethodDataContainer>(
84                  MethodDataStatesEnum.METHOD_DATA_SEQ_STATE,
85                  MethodDataStatesEnum.METHOD_DATA_SEQ_STATE,
86                  UniversalTag.SEQUENCE,
87                  new AddPaData() );
88      }
89  
90  
91      /**
92       * Get the instance of this grammar
93       *
94       * @return An instance on the METHOD-DATA Grammar
95       */
96      public static Grammar<MethodDataContainer> getInstance()
97      {
98          return instance;
99      }
100 }