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.hostAddress;
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.KerberosConstants;
29  import org.apache.directory.shared.kerberos.codec.hostAddress.actions.HostAddressInit;
30  import org.apache.directory.shared.kerberos.codec.hostAddress.actions.StoreAddrType;
31  import org.apache.directory.shared.kerberos.codec.hostAddress.actions.StoreAddress;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  
36  /**
37   * This class implements the HostAddress structure. All the actions are declared
38   * in this class. As it is a singleton, these declaration are only done once. If
39   * an action is to be added or modified, this is where the work is to be done !
40   *
41   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
42   */
43  public final class HostAddressGrammar extends AbstractGrammar<HostAddressContainer>
44  {
45      /** The logger */
46      static final Logger LOG = LoggerFactory.getLogger( HostAddressGrammar.class );
47  
48      /** A speedup for logger */
49      static final boolean IS_DEBUG = LOG.isDebugEnabled();
50  
51      /** The instance of grammar. HostAddressGrammar is a singleton */
52      private static Grammar<HostAddressContainer> instance = new HostAddressGrammar();
53  
54  
55      /**
56       * Creates a new HostAddressGrammar object.
57       */
58      @SuppressWarnings("unchecked")
59      private HostAddressGrammar()
60      {
61          setName( HostAddressGrammar.class.getName() );
62  
63          // Create the transitions table
64          super.transitions = new GrammarTransition[HostAddressStatesEnum.LAST_HOST_ADDRESS_STATE.ordinal()][256];
65  
66          // ============================================================================================
67          // HostAddress
68          // ============================================================================================
69          // --------------------------------------------------------------------------------------------
70          // Transition from HostAddress init to HostAddress SEQ
71          // --------------------------------------------------------------------------------------------
72          // HostAddress   ::= SEQUENCE
73          super.transitions[HostAddressStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
74              new GrammarTransition<HostAddressContainer>(
75                  HostAddressStatesEnum.START_STATE,
76                  HostAddressStatesEnum.HOST_ADDRESS_SEQ_STATE,
77                  UniversalTag.SEQUENCE,
78                  new HostAddressInit() );
79  
80          // --------------------------------------------------------------------------------------------
81          // Transition from HostAddress SEQ to addr-type tag
82          // --------------------------------------------------------------------------------------------
83          // HostAddress   ::= SEQUENCE
84          //         addr-type       [0]
85          super.transitions[HostAddressStatesEnum.HOST_ADDRESS_SEQ_STATE.ordinal()][KerberosConstants.HOST_ADDRESS_ADDR_TYPE_TAG] =
86              new GrammarTransition<HostAddressContainer>(
87                  HostAddressStatesEnum.HOST_ADDRESS_SEQ_STATE,
88                  HostAddressStatesEnum.HOST_ADDRESS_ADDR_TYPE_TAG_STATE,
89                  KerberosConstants.HOST_ADDRESS_ADDR_TYPE_TAG,
90                  new CheckNotNullLength<HostAddressContainer>() );
91  
92          // --------------------------------------------------------------------------------------------
93          // Transition from addr-type tag to addr-type value
94          // --------------------------------------------------------------------------------------------
95          // HostAddress   ::= SEQUENCE
96          //         addr-type       [0] Int32,
97          super.transitions[HostAddressStatesEnum.HOST_ADDRESS_ADDR_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER
98              .getValue()] =
99              new GrammarTransition<HostAddressContainer>(
100                 HostAddressStatesEnum.HOST_ADDRESS_ADDR_TYPE_TAG_STATE,
101                 HostAddressStatesEnum.HOST_ADDRESS_ADDR_TYPE_STATE,
102                 UniversalTag.INTEGER,
103                 new StoreAddrType() );
104 
105         // --------------------------------------------------------------------------------------------
106         // Transition from addr-type value to address tag
107         // --------------------------------------------------------------------------------------------
108         // HostAddress   ::= SEQUENCE
109         //         ...
110         //         address         [1]
111         super.transitions[HostAddressStatesEnum.HOST_ADDRESS_ADDR_TYPE_STATE.ordinal()][KerberosConstants.HOST_ADDRESS_ADDRESS_TAG] =
112             new GrammarTransition<HostAddressContainer>(
113                 HostAddressStatesEnum.HOST_ADDRESS_ADDR_TYPE_STATE,
114                 HostAddressStatesEnum.HOST_ADDRESS_ADDRESS_TAG_STATE,
115                 KerberosConstants.HOST_ADDRESS_ADDRESS_TAG,
116                 new CheckNotNullLength<HostAddressContainer>() );
117 
118         // --------------------------------------------------------------------------------------------
119         // Transition from address tag to address value
120         // --------------------------------------------------------------------------------------------
121         // HostAddress   ::= SEQUENCE
122         //         ...
123         //         address         [1] OCTET STRING
124         super.transitions[HostAddressStatesEnum.HOST_ADDRESS_ADDRESS_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING
125             .ordinal()] =
126             new GrammarTransition<HostAddressContainer>(
127                 HostAddressStatesEnum.HOST_ADDRESS_ADDRESS_TAG_STATE,
128                 HostAddressStatesEnum.HOST_ADDRESS_ADDRESS_STATE,
129                 UniversalTag.OCTET_STRING,
130                 new StoreAddress() );
131     }
132 
133 
134     /**
135      * Get the instance of this grammar
136      *
137      * @return An instance on the HostAddress Grammar
138      */
139     public static Grammar<HostAddressContainer> getInstance()
140     {
141         return instance;
142     }
143 }