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 */
020
021package org.apache.directory.api.ldap.extras.controls.vlv_impl;
022
023
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.slf4j.Logger;
029import org.slf4j.LoggerFactory;
030
031
032/**
033 * The VLV grammar. It's an implementation of https://www.ietf.org/archive/id/draft-ietf-ldapext-ldapv3-vlv-09.txt
034 * 
035 * Here is the grammar :
036 * 
037 * <pre>
038 *    VirtualListViewRequest ::= SEQUENCE { 
039 *        beforeCount    INTEGER (0..maxInt), 
040 *        afterCount     INTEGER (0..maxInt), 
041 *        target       CHOICE { 
042 *                       byOffset        [0] SEQUENCE {                           
043 *                            offset          INTEGER (1 .. maxInt), 
044 *                            contentCount    INTEGER (0 .. maxInt) 
045 *                       }, 
046 *                       greaterThanOrEqual [1] AssertionValue 
047 *        }, 
048 *        contextID     OCTET STRING OPTIONAL 
049 *  } 
050 * </pre>
051 *
052 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
053 */
054public final class VirtualListViewRequestGrammar extends AbstractGrammar<VirtualListViewRequestContainer>
055{
056    static final Logger LOG = LoggerFactory.getLogger( VirtualListViewRequestGrammar.class );
057
058    static final boolean IS_DEBUG = LOG.isDebugEnabled();
059
060    private static Grammar<?> instance = new VirtualListViewRequestGrammar();
061
062
063    /**
064     * Creates a new VirtualListViewRequestGrammar object.
065     */
066    @SuppressWarnings("unchecked")
067    private VirtualListViewRequestGrammar()
068    {
069        setName( VirtualListViewRequestGrammar.class.getName() );
070
071        super.transitions = new GrammarTransition[VirtualListViewRequestStates.END_STATE.ordinal()][256];
072
073        super.transitions[VirtualListViewRequestStates.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
074            new GrammarTransition<VirtualListViewRequestContainer>(
075                VirtualListViewRequestStates.START_STATE,
076                VirtualListViewRequestStates.VLV_SEQUENCE_STATE,
077                UniversalTag.SEQUENCE.getValue(),
078                null );
079
080        super.transitions[VirtualListViewRequestStates.VLV_SEQUENCE_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
081            new GrammarTransition<VirtualListViewRequestContainer>(
082                VirtualListViewRequestStates.VLV_SEQUENCE_STATE,
083                VirtualListViewRequestStates.VLV_BEFORE_COUNT_STATE,
084                UniversalTag.INTEGER.getValue(),
085                new StoreBeforeCount() );
086
087        super.transitions[VirtualListViewRequestStates.VLV_BEFORE_COUNT_STATE.ordinal()][UniversalTag.INTEGER
088            .getValue()] =
089            new GrammarTransition<VirtualListViewRequestContainer>(
090                VirtualListViewRequestStates.VLV_BEFORE_COUNT_STATE,
091                VirtualListViewRequestStates.VLV_AFTER_COUNT_STATE,
092                UniversalTag.INTEGER.getValue(),
093                new StoreAfterCount() );
094
095        super.transitions[VirtualListViewRequestStates.VLV_AFTER_COUNT_STATE.ordinal()][VirtualListViewerTags.BY_OFFSET_TAG
096            .getValue()] =
097            new GrammarTransition<VirtualListViewRequestContainer>(
098                VirtualListViewRequestStates.VLV_AFTER_COUNT_STATE,
099                VirtualListViewRequestStates.VLV_TARGET_BY_OFFSET_STATE,
100                ( byte ) VirtualListViewerTags.BY_OFFSET_TAG.getValue(),
101                null );
102
103        super.transitions[VirtualListViewRequestStates.VLV_AFTER_COUNT_STATE.ordinal()][VirtualListViewerTags.ASSERTION_VALUE_TAG
104            .getValue()] =
105            new GrammarTransition<VirtualListViewRequestContainer>(
106                VirtualListViewRequestStates.VLV_AFTER_COUNT_STATE,
107                VirtualListViewRequestStates.VLV_ASSERTION_VALUE_STATE,
108                ( byte ) VirtualListViewerTags.ASSERTION_VALUE_TAG.getValue(),
109                new StoreAssertionValue() );
110
111        super.transitions[VirtualListViewRequestStates.VLV_TARGET_BY_OFFSET_STATE.ordinal()][UniversalTag.INTEGER
112            .getValue()] =
113            new GrammarTransition<VirtualListViewRequestContainer>(
114                VirtualListViewRequestStates.VLV_TARGET_BY_OFFSET_STATE,
115                VirtualListViewRequestStates.VLV_OFFSET_STATE,
116                UniversalTag.INTEGER.getValue(),
117                new StoreOffset() );
118
119        super.transitions[VirtualListViewRequestStates.VLV_OFFSET_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
120            new GrammarTransition<VirtualListViewRequestContainer>(
121                VirtualListViewRequestStates.VLV_OFFSET_STATE,
122                VirtualListViewRequestStates.VLV_CONTENT_COUNT_STATE,
123                UniversalTag.INTEGER.getValue(),
124                new StoreContentCount() );
125
126        super.transitions[VirtualListViewRequestStates.VLV_CONTENT_COUNT_STATE.ordinal()][UniversalTag.OCTET_STRING
127            .getValue()] =
128            new GrammarTransition<VirtualListViewRequestContainer>(
129                VirtualListViewRequestStates.VLV_CONTENT_COUNT_STATE,
130                VirtualListViewRequestStates.VLV_CONTEXT_ID_STATE,
131                UniversalTag.OCTET_STRING.getValue(),
132                new StoreContextId() );
133
134        super.transitions[VirtualListViewRequestStates.VLV_ASSERTION_VALUE_STATE.ordinal()][UniversalTag.OCTET_STRING
135            .getValue()] =
136            new GrammarTransition<VirtualListViewRequestContainer>(
137                VirtualListViewRequestStates.VLV_ASSERTION_VALUE_STATE,
138                VirtualListViewRequestStates.VLV_CONTEXT_ID_STATE,
139                UniversalTag.OCTET_STRING.getValue(),
140                new StoreContextId() );
141    }
142
143
144    /**
145     * @return the singleton instance of the VirtualListViewRequestGrammar
146     */
147    public static Grammar<?> getInstance()
148    {
149        return instance;
150    }
151}