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.methodData; 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.methodData.actions.AddPaData; 029import org.slf4j.Logger; 030import org.slf4j.LoggerFactory; 031 032 033/** 034 * This class implements the METHOD-DATA 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 MethodDataGrammar extends AbstractGrammar<MethodDataContainer> 041{ 042 /** The logger */ 043 static final Logger LOG = LoggerFactory.getLogger( MethodDataGrammar.class ); 044 045 /** A speedup for logger */ 046 static final boolean IS_DEBUG = LOG.isDebugEnabled(); 047 048 /** The instance of grammar. MethodDataGrammar is a singleton */ 049 private static Grammar<MethodDataContainer> instance = new MethodDataGrammar(); 050 051 052 /** 053 * Creates a new MethodDataGrammar object. 054 */ 055 @SuppressWarnings("unchecked") 056 private MethodDataGrammar() 057 { 058 setName( MethodDataGrammar.class.getName() ); 059 060 // Create the transitions table 061 super.transitions = new GrammarTransition[MethodDataStatesEnum.LAST_METHOD_DATA_STATE.ordinal()][256]; 062 063 // ============================================================================================ 064 // METHOD-DATA 065 // ============================================================================================ 066 // -------------------------------------------------------------------------------------------- 067 // Transition from METHOD-DATA init to METHOD-DATA SEQ 068 // -------------------------------------------------------------------------------------------- 069 // METHOD-DATA ::= SEQUENCE 070 super.transitions[MethodDataStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = 071 new GrammarTransition<MethodDataContainer>( 072 MethodDataStatesEnum.START_STATE, 073 MethodDataStatesEnum.METHOD_DATA_SEQ_STATE, 074 UniversalTag.SEQUENCE, 075 new CheckNotNullLength<MethodDataContainer>() ); 076 077 // -------------------------------------------------------------------------------------------- 078 // Transition from METHOD-DATA SEQ to PA-DATA 079 // -------------------------------------------------------------------------------------------- 080 // METHOD-DATA ::= SEQUENCE OF <PA-DATA> 081 // 082 super.transitions[MethodDataStatesEnum.METHOD_DATA_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = 083 new GrammarTransition<MethodDataContainer>( 084 MethodDataStatesEnum.METHOD_DATA_SEQ_STATE, 085 MethodDataStatesEnum.METHOD_DATA_SEQ_STATE, 086 UniversalTag.SEQUENCE, 087 new AddPaData() ); 088 } 089 090 091 /** 092 * Get the instance of this grammar 093 * 094 * @return An instance on the METHOD-DATA Grammar 095 */ 096 public static Grammar<MethodDataContainer> getInstance() 097 { 098 return instance; 099 } 100}