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  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     public Enum<Dsmlv2StatesEnum> getState()
156     {
157         return state;
158     }
159 
160 
161     /**
162      * Set the new current state
163      * 
164      * @param state the new state
165      */
166     public void setState( Enum<Dsmlv2StatesEnum> state )
167     {
168         this.state = state;
169     }
170 
171 
172     /**
173      * Get the transition
174      * 
175      * @return the transition from the previous state to the new state
176      */
177     public Enum<Dsmlv2StatesEnum> getTransition()
178     {
179         return transition;
180     }
181 
182 
183     /**
184      * Update the transition from a state to another
185      * 
186      * @param transition the transition to set
187      */
188     public void setTransition( Enum<Dsmlv2StatesEnum> transition )
189     {
190         this.transition = transition;
191     }
192 
193 
194     /**
195      * Get the states for this container's grammars
196      * 
197      * @return the states.
198      */
199     public Enum<Dsmlv2StatesEnum>[] getStates()
200     {
201         return states;
202     }
203 
204 
205     /**
206      * Gets the grammar
207      *
208      * @return the grammar
209      */
210     public AbstractGrammar getGrammar()
211     {
212         return grammar;
213     }
214 
215 
216     /**
217      * Sets the Grammar
218      * 
219      * @param grammar the grammar to set
220      */
221     public void setGrammar( AbstractGrammar grammar )
222     {
223         this.grammar = grammar;
224     }
225 
226 
227     /**
228      * Get the transition associated with the state and tag
229      * 
230      * @param currentState the current state
231      * @param currentTag the current tag
232      * @return a valid transition if any, or null.
233      */
234     public GrammarTransition getTransition( Enum<Dsmlv2StatesEnum> currentState, Tag currentTag )
235     {
236         return grammar.getTransition( currentState, currentTag );
237     }
238 }