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   *    https://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  package org.apache.directory.api.dsmlv2;
21  
22  
23  import org.apache.directory.api.dsmlv2.request.BatchRequestDsml;
24  import org.apache.directory.api.dsmlv2.response.BatchResponseDsml;
25  import org.apache.directory.api.ldap.codec.api.LdapApiService;
26  import org.xmlpull.v1.XmlPullParser;
27  
28  
29  /**
30   * This class represents the DSML Container.
31   * It used by the DSML Parser to store information.
32   * 
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   */
35  public class Dsmlv2Container implements Container
36  {
37      /** The current state of the decoding */
38      private Enum<Dsmlv2StatesEnum> state;
39  
40      /** The current transition */
41      private Enum<Dsmlv2StatesEnum> transition;
42  
43      /** Store the different states for debug purpose */
44      private Enum<Dsmlv2StatesEnum>[] states;
45  
46      /** The pool parser */
47      private XmlPullParser parser;
48  
49      /** The BatchRequest of the parsing */
50      private BatchRequestDsml batchRequest;
51  
52      /** The BatchResponse of the parsing */
53      private BatchResponseDsml batchResponse;
54  
55      /**  The associated grammar */
56      private AbstractGrammar grammar;
57  
58      /** The codec service */
59      private final LdapApiService codec;
60  
61  
62      /**
63       * Creates a new LdapMessageContainer object.
64       * 
65       * @param codec the Codec used to encode/decode the messages
66       */
67      public Dsmlv2Container( LdapApiService codec )
68      {
69          this.codec = codec;
70      }
71  
72  
73      /**
74       * Gets the {@link LdapApiService} associated with this Container.
75       *
76       * @return The codec used to encode/decode the messages
77       */
78      public LdapApiService getLdapCodecService()
79      {
80          return codec;
81      }
82  
83  
84      /**
85       * Gets the DSML Batch Request
86       * 
87       * @return Returns the Batch Request
88       */
89      public BatchRequestDsml getBatchRequest()
90      {
91          return batchRequest;
92      }
93  
94  
95      /**
96       * Sets the DSML Batch Request
97       * 
98       * @param batchRequest the Batch Request to set
99       */
100     public void setBatchRequest( BatchRequestDsml batchRequest )
101     {
102         this.batchRequest = batchRequest;
103     }
104 
105 
106     /**
107      * Gets the DSML Batch Response
108      * 
109      * @return Returns the Batch Response
110      */
111     public BatchResponseDsml getBatchResponse()
112     {
113         return batchResponse;
114     }
115 
116 
117     /**
118      * Sets the DSML Batch Request
119      * 
120      * @param batchResponse the Batch Response to set
121      */
122     public void setBatchResponse( BatchResponseDsml batchResponse )
123     {
124         this.batchResponse = batchResponse;
125     }
126 
127 
128     /**
129      * Gets the parser
130      * 
131      * @return the parser
132      */
133     public XmlPullParser getParser()
134     {
135         return parser;
136     }
137 
138 
139     /**
140      * Sets the parser
141      * 
142      * @param parser the parser to set
143      */
144     public void setParser( XmlPullParser parser )
145     {
146         this.parser = parser;
147     }
148 
149 
150     /**
151      * Get the current grammar state
152      * 
153      * @return the current grammar state
154      */
155     @Override
156     public Enum<Dsmlv2StatesEnum> getState()
157     {
158         return state;
159     }
160 
161 
162     /**
163      * Set the new current state
164      * 
165      * @param state the new state
166      */
167     @Override
168     public void setState( Enum<Dsmlv2StatesEnum> state )
169     {
170         this.state = state;
171     }
172 
173 
174     /**
175      * Get the transition
176      * 
177      * @return the transition from the previous state to the new state
178      */
179     @Override
180     public Enum<Dsmlv2StatesEnum> getTransition()
181     {
182         return transition;
183     }
184 
185 
186     /**
187      * Update the transition from a state to another
188      * 
189      * @param transition the transition to set
190      */
191     @Override
192     public void setTransition( Enum<Dsmlv2StatesEnum> transition )
193     {
194         this.transition = transition;
195     }
196 
197 
198     /**
199      * Get the states for this container's grammars
200      * 
201      * @return the states.
202      */
203     @Override
204     public Enum<Dsmlv2StatesEnum>[] getStates()
205     {
206         return states;
207     }
208 
209 
210     /**
211      * Gets the grammar
212      *
213      * @return the grammar
214      */
215     public AbstractGrammar getGrammar()
216     {
217         return grammar;
218     }
219 
220 
221     /**
222      * Sets the Grammar
223      * 
224      * @param grammar the grammar to set
225      */
226     public void setGrammar( AbstractGrammar grammar )
227     {
228         this.grammar = grammar;
229     }
230 
231 
232     /**
233      * Get the transition associated with the state and tag
234      * 
235      * @param currentState the current state
236      * @param currentTag the current tag
237      * @return a valid transition if any, or null.
238      */
239     public GrammarTransition getTransition( Enum<Dsmlv2StatesEnum> currentState, Tag currentTag )
240     {
241         return grammar.getTransition( currentState, currentTag );
242     }
243 }