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     */
020    
021    package org.apache.directory.shared.dsmlv2;
022    
023    
024    import org.apache.directory.shared.dsmlv2.reponse.BatchResponse;
025    import org.apache.directory.shared.dsmlv2.request.BatchRequest;
026    import 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     * @version $Rev$, $Date$
035     */
036    public class Dsmlv2Container implements Container
037    {
038        /** The current state of the decoding */
039        private int state;
040    
041        /** The current transition */
042        private int transition;
043    
044        /** Store the different states for debug purpose */
045        private IStates states;
046    
047        /** The pool parser */
048        private XmlPullParser parser;
049    
050        /** The BatchRequest of the parsing */
051        private BatchRequest batchRequest;
052    
053        /** The BatchResponse of the parsing */
054        private BatchResponse batchResponse;
055    
056        /**  The associated grammar */
057        private AbstractGrammar grammar;
058    
059    
060        /**
061         * Gets the DSML Batch Request
062         * 
063         * @return
064         *      Returns the Batch Request
065         */
066        public BatchRequest getBatchRequest()
067        {
068            return batchRequest;
069        }
070    
071    
072        /**
073         * Sets the DSML Batch Request
074         * 
075         * @param batchRequest
076         *      the Batch Request to set
077         */
078        public void setBatchRequest( BatchRequest batchRequest )
079        {
080            this.batchRequest = batchRequest;
081        }
082    
083    
084        /**
085         * Gets the DSML Batch Response
086         * 
087         * @return
088         *      Returns the Batch Response
089         */
090        public BatchResponse getBatchResponse()
091        {
092            return batchResponse;
093        }
094    
095    
096        /**
097         * Sets the DSML Batch Request
098         * 
099         * @param batchResponse
100         *      the Batch Response to set
101         */
102        public void setBatchResponse( BatchResponse batchResponse )
103        {
104            this.batchResponse = batchResponse;
105        }
106    
107    
108        /**
109         * Gets the parser
110         * 
111         * @return
112         *      the parser
113         */
114        public XmlPullParser getParser()
115        {
116            return parser;
117        }
118    
119    
120        /**
121         * Sets the parser
122         * 
123         * @param parser
124         *      the parser to set
125         */
126        public void setParser( XmlPullParser parser )
127        {
128            this.parser = parser;
129        }
130    
131    
132        /**
133         * Get the current grammar state
134         * 
135         * @return
136         *      the current grammar state
137         */
138        public int getState()
139        {
140            return state;
141        }
142    
143    
144        /**
145         * Set the new current state
146         * 
147         * @param state
148         *      the new state
149         */
150        public void setState( int state )
151        {
152            this.state = state;
153        }
154    
155    
156        /**
157         * Get the transition
158         * 
159         * @return
160         *      the transition from the previous state to the new state
161         */
162        public int getTransition()
163        {
164            return transition;
165        }
166    
167    
168        /**
169         * Update the transition from a state to another
170         * 
171         * @param transition
172         *      the transition to set
173         */
174        public void setTransition( int transition )
175        {
176            this.transition = transition;
177        }
178    
179    
180        /**
181         * Get the states for this container's grammars
182         * 
183         * @return
184         *      the states.
185         */
186        public IStates getStates()
187        {
188            return states;
189        }
190    
191    
192        /**
193         * Gets the grammar
194         *
195         * @return
196         *      the grammar
197         */
198        public AbstractGrammar getGrammar()
199        {
200            return grammar;
201        }
202    
203    
204        /**
205         * Sets the Grammar
206         * 
207         * @param grammar
208         *      the grammar to set
209         */
210        public void setGrammar( AbstractGrammar grammar )
211        {
212            this.grammar = grammar;
213        }
214    
215    
216        /**
217         * Get the transition associated with the state and tag
218         * 
219         * @param state
220         *      the current state
221         * @param tag
222         *      the current tag
223         * @return
224         *      a valid transition if any, or null.
225         */
226        public GrammarTransition getTransition( int state, Tag tag )
227        {
228            return grammar.getTransition( state, tag );
229        }
230    }