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