001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.directory.shared.kerberos.codec.hostAddresses;
021
022
023import org.apache.directory.api.asn1.actions.CheckNotNullLength;
024import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
025import org.apache.directory.api.asn1.ber.grammar.Grammar;
026import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
027import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
028import org.apache.directory.shared.kerberos.codec.hostAddresses.actions.AddHostAddress;
029import org.slf4j.Logger;
030import org.slf4j.LoggerFactory;
031
032
033/**
034 * This class implements the HostAddresses structure. All the actions are declared
035 * in this class. As it is a singleton, these declaration are only done once. If
036 * an action is to be added or modified, this is where the work is to be done !
037 *
038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
039 */
040public final class HostAddressesGrammar extends AbstractGrammar<HostAddressesContainer>
041{
042    /** The logger */
043    static final Logger LOG = LoggerFactory.getLogger( HostAddressesGrammar.class );
044
045    /** A speedup for logger */
046    static final boolean IS_DEBUG = LOG.isDebugEnabled();
047
048    /** The instance of grammar. HostAddressesGrammar is a singleton */
049    private static Grammar<HostAddressesContainer> instance = new HostAddressesGrammar();
050
051
052    /**
053     * Creates a new HostAddressGrammar object.
054     */
055    @SuppressWarnings("unchecked")
056    private HostAddressesGrammar()
057    {
058        setName( HostAddressesGrammar.class.getName() );
059
060        // Create the transitions table
061        super.transitions = new GrammarTransition[HostAddressesStatesEnum.LAST_HOST_ADDRESSES_STATE.ordinal()][256];
062
063        // ============================================================================================
064        // HostAddresses
065        // ============================================================================================
066        // --------------------------------------------------------------------------------------------
067        // Transition from HostAddresses init to HostAddresses SEQUENCE OF
068        // --------------------------------------------------------------------------------------------
069        // HostAddress   ::= SEQUENCE OF
070        super.transitions[HostAddressesStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
071            new GrammarTransition<HostAddressesContainer>(
072                HostAddressesStatesEnum.START_STATE,
073                HostAddressesStatesEnum.HOST_ADDRESSES_ADDRESS_STATE,
074                UniversalTag.SEQUENCE,
075                new CheckNotNullLength<HostAddressesContainer>() );
076
077        // --------------------------------------------------------------------------------------------
078        // Transition from HostAddresses SEQ to HostAddress
079        // --------------------------------------------------------------------------------------------
080        // HostAddresses   ::= SEQUENCE OF
081        //         HostAddress
082        super.transitions[HostAddressesStatesEnum.HOST_ADDRESSES_ADDRESS_STATE.ordinal()][UniversalTag.SEQUENCE
083            .getValue()] =
084            new GrammarTransition<HostAddressesContainer>(
085                HostAddressesStatesEnum.HOST_ADDRESSES_ADDRESS_STATE,
086                HostAddressesStatesEnum.HOST_ADDRESSES_ADDRESS_STATE,
087                UniversalTag.SEQUENCE,
088                new AddHostAddress() );
089    }
090
091
092    // ~ Methods
093    // ------------------------------------------------------------------------------------
094
095    /**
096     * Get the instance of this grammar
097     *
098     * @return An instance on the HostAddresses Grammar
099     */
100    public static Grammar<HostAddressesContainer> getInstance()
101    {
102        return instance;
103    }
104}