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 * https://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 @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}