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 grammar for the VLV response which described as :
034 * 
035 * <pre>
036 *  VirtualListViewResponse ::= SEQUENCE {
037 *         targetPosition    INTEGER (0 .. maxInt),
038 *         contentCount     INTEGER (0 .. maxInt),
039 *         virtualListViewResult ENUMERATED {
040 *              success (0),
041 *              operationsError (1),
042 *              protocolError (3),
043 *              unwillingToPerform (53),
044 *              insufficientAccessRights (50),
045 *              timeLimitExceeded (3),
046 *              adminLimitExceeded (11),
047 *              innapropriateMatching (18),
048 *              sortControlMissing (60),
049 *              offsetRangeError (61),
050 *              other(80),
051 *              ... 
052 *         },
053 *         contextID     OCTET STRING OPTIONAL 
054 * }
055 * </pre>
056 * 
057 *
058 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
059 */
060public final class VirtualListViewResponseGrammar extends AbstractGrammar<VirtualListViewResponseContainer>
061{
062    static final Logger LOG = LoggerFactory.getLogger( VirtualListViewResponseGrammar.class );
063
064    static final boolean IS_DEBUG = LOG.isDebugEnabled();
065
066    private static Grammar<?> instance = new VirtualListViewResponseGrammar();
067
068
069    /**
070     * Creates a new VirtualListViewResponseGrammar object.
071     */
072    @SuppressWarnings("unchecked")
073    private VirtualListViewResponseGrammar()
074    {
075        setName( VirtualListViewResponseGrammar.class.getName() );
076
077        super.transitions = new GrammarTransition[VirtualListViewResponseStates.END_STATE.ordinal()][256];
078
079        super.transitions[VirtualListViewResponseStates.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
080            new GrammarTransition<VirtualListViewResponseContainer>(
081                VirtualListViewResponseStates.START_STATE,
082                VirtualListViewResponseStates.VLV_SEQUENCE_STATE,
083                UniversalTag.SEQUENCE.getValue(),
084                null );
085
086        super.transitions[VirtualListViewResponseStates.VLV_SEQUENCE_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
087            new GrammarTransition<VirtualListViewResponseContainer>(
088                VirtualListViewResponseStates.VLV_SEQUENCE_STATE,
089                VirtualListViewResponseStates.VLV_TARGET_POSITION_STATE,
090                UniversalTag.INTEGER.getValue(),
091                new StoreTargetPosition() );
092
093        super.transitions[VirtualListViewResponseStates.VLV_TARGET_POSITION_STATE.ordinal()][UniversalTag.INTEGER
094            .getValue()] =
095            new GrammarTransition<VirtualListViewResponseContainer>(
096                VirtualListViewResponseStates.VLV_TARGET_POSITION_STATE,
097                VirtualListViewResponseStates.VLV_CONTENT_COUNT_STATE,
098                UniversalTag.INTEGER.getValue(),
099                new StoreContentCountResponse() );
100
101        super.transitions[VirtualListViewResponseStates.VLV_CONTENT_COUNT_STATE.ordinal()][UniversalTag.ENUMERATED
102            .getValue()] =
103            new GrammarTransition<VirtualListViewResponseContainer>(
104                VirtualListViewResponseStates.VLV_CONTENT_COUNT_STATE,
105                VirtualListViewResponseStates.VLV_VIRTUAL_LIST_VIEW_RESULT_STATE,
106                UniversalTag.ENUMERATED.getValue(),
107                new StoreVirtualListViewResult() );
108
109        super.transitions[VirtualListViewResponseStates.VLV_VIRTUAL_LIST_VIEW_RESULT_STATE.ordinal()][UniversalTag.OCTET_STRING
110            .getValue()] =
111            new GrammarTransition<VirtualListViewResponseContainer>(
112                VirtualListViewResponseStates.VLV_VIRTUAL_LIST_VIEW_RESULT_STATE,
113                VirtualListViewResponseStates.VLV_CONTEXT_ID_STATE,
114                UniversalTag.OCTET_STRING.getValue(),
115                new StoreContextIdResponse() );
116    }
117
118
119    /**
120     * @return the singleton instance of the VirtualListViewResponseGrammar
121     */
122    public static Grammar<?> getInstance()
123    {
124        return instance;
125    }
126}