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 */
020package org.apache.directory.api.dsmlv2;
021
022
023import org.apache.directory.api.dsmlv2.request.BatchRequestDsml;
024import org.apache.directory.api.dsmlv2.response.BatchResponseDsml;
025import org.apache.directory.api.ldap.codec.api.LdapApiService;
026import org.xmlpull.v1.XmlPullParser;
027
028
029/**
030 * This class represents the DSML Container.
031 * It used by the DSML Parser to store information.
032 * 
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class Dsmlv2Container implements Container
036{
037    /** The current state of the decoding */
038    private Enum<Dsmlv2StatesEnum> state;
039
040    /** The current transition */
041    private Enum<Dsmlv2StatesEnum> transition;
042
043    /** Store the different states for debug purpose */
044    private Enum<Dsmlv2StatesEnum>[] states;
045
046    /** The pool parser */
047    private XmlPullParser parser;
048
049    /** The BatchRequest of the parsing */
050    private BatchRequestDsml batchRequest;
051
052    /** The BatchResponse of the parsing */
053    private BatchResponseDsml batchResponse;
054
055    /**  The associated grammar */
056    private AbstractGrammar grammar;
057
058    /** The codec service */
059    private final LdapApiService codec;
060
061
062    /**
063     * Creates a new LdapMessageContainer object.
064     * 
065     * @param codec the Codec used to encode/decode the messages
066     */
067    public Dsmlv2Container( LdapApiService codec )
068    {
069        this.codec = codec;
070    }
071
072
073    /**
074     * Gets the {@link LdapApiService} associated with this Container.
075     *
076     * @return The codec used to encode/decode the messages
077     */
078    public LdapApiService getLdapCodecService()
079    {
080        return codec;
081    }
082
083
084    /**
085     * Gets the DSML Batch Request
086     * 
087     * @return Returns the Batch Request
088     */
089    public BatchRequestDsml getBatchRequest()
090    {
091        return batchRequest;
092    }
093
094
095    /**
096     * Sets the DSML Batch Request
097     * 
098     * @param batchRequest the Batch Request to set
099     */
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}