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.shared.dsmlv2;
021
022
023import org.apache.directory.shared.asn1.ber.Asn1Container;
024import org.apache.directory.shared.dsmlv2.reponse.BatchResponseDsml;
025import org.apache.directory.shared.dsmlv2.request.BatchRequestDsml;
026import org.apache.directory.shared.ldap.codec.api.LdapApiService;
027import org.xmlpull.v1.XmlPullParser;
028
029
030/**
031 * This class represents the DSML Container.
032 * It used by the DSML Parser to store information.
033 * 
034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035 */
036public class Dsmlv2Container implements Container
037{
038    /** The current state of the decoding */
039    private Enum<Dsmlv2StatesEnum> state;
040
041    /** The current transition */
042    private Enum<Dsmlv2StatesEnum> transition;
043
044    /** Store the different states for debug purpose */
045    private Enum<Dsmlv2StatesEnum>[] states;
046
047    /** The pool parser */
048    private XmlPullParser parser;
049
050    /** The BatchRequest of the parsing */
051    private BatchRequestDsml batchRequest;
052
053    /** The BatchResponse of the parsing */
054    private BatchResponseDsml batchResponse;
055
056    /**  The associated grammar */
057    private AbstractGrammar grammar;
058
059    /** The codec service */
060    private final LdapApiService codec;
061
062    /**
063     * Creates a new LdapMessageContainer object. We will store ten grammars,
064     * it's enough ...
065     */
066    public Dsmlv2Container( LdapApiService codec )
067    {
068        this.codec= codec;
069    }
070    
071    
072    /**
073     * Gets the {@link LdapApiService} associated with this {@link Asn1Container}.
074     *
075     * @return
076     */
077    public LdapApiService getLdapCodecService()
078    {
079        return codec;
080    }
081    
082    
083    /**
084     * Gets the DSML Batch Request
085     * 
086     * @return
087     *      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
099     *      the Batch Request to set
100     */
101    public void setBatchRequest( BatchRequestDsml batchRequest )
102    {
103        this.batchRequest = batchRequest;
104    }
105
106
107    /**
108     * Gets the DSML Batch Response
109     * 
110     * @return
111     *      Returns the Batch Response
112     */
113    public BatchResponseDsml getBatchResponse()
114    {
115        return batchResponse;
116    }
117
118
119    /**
120     * Sets the DSML Batch Request
121     * 
122     * @param batchResponse
123     *      the Batch Response to set
124     */
125    public void setBatchResponse( BatchResponseDsml batchResponse )
126    {
127        this.batchResponse = batchResponse;
128    }
129
130
131    /**
132     * Gets the parser
133     * 
134     * @return
135     *      the parser
136     */
137    public XmlPullParser getParser()
138    {
139        return parser;
140    }
141
142
143    /**
144     * Sets the parser
145     * 
146     * @param parser
147     *      the parser to set
148     */
149    public void setParser( XmlPullParser parser )
150    {
151        this.parser = parser;
152    }
153
154
155    /**
156     * Get the current grammar state
157     * 
158     * @return
159     *      the current grammar state
160     */
161    public Enum<Dsmlv2StatesEnum> getState()
162    {
163        return state;
164    }
165
166
167    /**
168     * Set the new current state
169     * 
170     * @param state
171     *      the new state
172     */
173    public void setState( Enum<Dsmlv2StatesEnum> state )
174    {
175        this.state = state;
176    }
177
178
179    /**
180     * Get the transition
181     * 
182     * @return
183     *      the transition from the previous state to the new state
184     */
185    public Enum<Dsmlv2StatesEnum> getTransition()
186    {
187        return transition;
188    }
189
190
191    /**
192     * Update the transition from a state to another
193     * 
194     * @param transition
195     *      the transition to set
196     */
197    public void setTransition( Enum<Dsmlv2StatesEnum> transition )
198    {
199        this.transition = transition;
200    }
201
202
203    /**
204     * Get the states for this container's grammars
205     * 
206     * @return
207     *      the states.
208     */
209    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UWF_UNWRITTEN_FIELD",
210        justification="it exists a setter for 'states'")
211    public Enum<Dsmlv2StatesEnum>[] getStates()
212    {
213        return states;
214    }
215
216
217    /**
218     * Gets the grammar
219     *
220     * @return
221     *      the grammar
222     */
223    public AbstractGrammar getGrammar()
224    {
225        return grammar;
226    }
227
228
229    /**
230     * Sets the Grammar
231     * 
232     * @param grammar
233     *      the grammar to set
234     */
235    public void setGrammar( AbstractGrammar grammar )
236    {
237        this.grammar = grammar;
238    }
239
240
241    /**
242     * Get the transition associated with the state and tag
243     * 
244     * @param currentState
245     *      the current state
246     * @param currentTag
247     *      the current tag
248     * @return
249     *      a valid transition if any, or null.
250     */
251    public GrammarTransition getTransition( Enum<Dsmlv2StatesEnum> currentState, Tag currentTag )
252    {
253        return grammar.getTransition( currentState, currentTag );
254    }
255}