View Javadoc
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  
21  package org.apache.directory.api.ldap.extras.controls.vlv_impl;
22  
23  
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.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  
32  /**
33   * The VLV grammar. It's an implementation of https://www.ietf.org/archive/id/draft-ietf-ldapext-ldapv3-vlv-09.txt
34   * 
35   * Here is the grammar :
36   * 
37   * <pre>
38   *    VirtualListViewRequest ::= SEQUENCE { 
39   *        beforeCount    INTEGER (0..maxInt), 
40   *        afterCount     INTEGER (0..maxInt), 
41   *        target       CHOICE { 
42   *                       byOffset        [0] SEQUENCE {                           
43   *                            offset          INTEGER (1 .. maxInt), 
44   *                            contentCount    INTEGER (0 .. maxInt) 
45   *                       }, 
46   *                       greaterThanOrEqual [1] AssertionValue 
47   *        }, 
48   *        contextID     OCTET STRING OPTIONAL 
49   *  } 
50   * </pre>
51   *
52   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
53   */
54  public final class VirtualListViewRequestGrammar extends AbstractGrammar<VirtualListViewRequestContainer>
55  {
56      static final Logger LOG = LoggerFactory.getLogger( VirtualListViewRequestGrammar.class );
57  
58      static final boolean IS_DEBUG = LOG.isDebugEnabled();
59  
60      private static Grammar<?> instance = new VirtualListViewRequestGrammar();
61  
62  
63      /**
64       * Creates a new VirtualListViewRequestGrammar object.
65       */
66      @SuppressWarnings("unchecked")
67      private VirtualListViewRequestGrammar()
68      {
69          setName( VirtualListViewRequestGrammar.class.getName() );
70  
71          super.transitions = new GrammarTransition[VirtualListViewRequestStates.END_STATE.ordinal()][256];
72  
73          super.transitions[VirtualListViewRequestStates.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
74              new GrammarTransition<VirtualListViewRequestContainer>(
75                  VirtualListViewRequestStates.START_STATE,
76                  VirtualListViewRequestStates.VLV_SEQUENCE_STATE,
77                  UniversalTag.SEQUENCE.getValue(),
78                  null );
79  
80          super.transitions[VirtualListViewRequestStates.VLV_SEQUENCE_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
81              new GrammarTransition<VirtualListViewRequestContainer>(
82                  VirtualListViewRequestStates.VLV_SEQUENCE_STATE,
83                  VirtualListViewRequestStates.VLV_BEFORE_COUNT_STATE,
84                  UniversalTag.INTEGER.getValue(),
85                  new StoreBeforeCount() );
86  
87          super.transitions[VirtualListViewRequestStates.VLV_BEFORE_COUNT_STATE.ordinal()][UniversalTag.INTEGER
88              .getValue()] =
89              new GrammarTransition<VirtualListViewRequestContainer>(
90                  VirtualListViewRequestStates.VLV_BEFORE_COUNT_STATE,
91                  VirtualListViewRequestStates.VLV_AFTER_COUNT_STATE,
92                  UniversalTag.INTEGER.getValue(),
93                  new StoreAfterCount() );
94  
95          super.transitions[VirtualListViewRequestStates.VLV_AFTER_COUNT_STATE.ordinal()][VirtualListViewerTags.BY_OFFSET_TAG
96              .getValue()] =
97              new GrammarTransition<VirtualListViewRequestContainer>(
98                  VirtualListViewRequestStates.VLV_AFTER_COUNT_STATE,
99                  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 }