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.request;
022
023
024 import java.util.ArrayList;
025 import java.util.List;
026
027 import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
028
029
030 /**
031 * This class represents the Batch Request of a DSML Request
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 * @version $Rev$, $Date$
035 */
036 public class BatchRequest
037 {
038 /**
039 * The requests contained in the Batch Request
040 */
041 private List<LdapMessageCodec> requests;
042
043 /**
044 * The ID of the request
045 */
046 private int requestID;
047
048 /**
049 * This enum represents the different types of processing for a Batch Request
050 *
051 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
052 * @version $Rev$, $Date$
053 */
054 public enum Processing
055 {
056 SEQUENTIAL, PARALLEL
057 };
058
059 /**
060 * The type of processing of the Batch Request
061 */
062 private Processing processing;
063
064 /**
065 * This enum represents the different types of on error handling for a BatchRequest
066 *
067 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
068 * @version $Rev$, $Date$
069 */
070 public enum OnError
071 {
072 RESUME, EXIT
073 };
074
075 /**
076 * The type of on error handling
077 */
078 private OnError onError;
079
080 /**
081 * This enum represents the different types of response order for a Batch Request
082 *
083 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
084 * @version $Rev$, $Date$
085 */
086 public enum ResponseOrder
087 {
088 SEQUENTIAL, UNORDERED
089 };
090
091 /**
092 * The response order
093 */
094 private ResponseOrder responseOrder;
095
096
097 /**
098 * Creates a new instance of BatchRequest.
099 */
100 public BatchRequest()
101 {
102 requests = new ArrayList<LdapMessageCodec>();
103 responseOrder = ResponseOrder.SEQUENTIAL;
104 processing = Processing.SEQUENTIAL;
105 onError = OnError.EXIT;
106 }
107
108
109 /**
110 * Adds a request
111 *
112 * @param request
113 * the resquest to add
114 * @return
115 * true (as per the general contract of the Collection.add method)
116 */
117 public boolean addRequest( LdapMessageCodec request )
118 {
119 return requests.add( request );
120 }
121
122
123 /**
124 * Gets the current request
125 *
126 * @return
127 * the current request
128 */
129 public LdapMessageCodec getCurrentRequest()
130 {
131 return requests.get( requests.size() - 1 );
132 }
133
134
135 /**
136 * Gets the ID of the request
137 *
138 * @return
139 * the ID of the request
140 */
141 public int getRequestID()
142 {
143 return requestID;
144 }
145
146
147 /**
148 * Sets the ID of the request
149 *
150 * @param requestID
151 * the ID to set
152 */
153 public void setRequestID( int requestID )
154 {
155 this.requestID = requestID;
156 }
157
158
159 /**
160 * Gets the processing type of the request
161 *
162 * @return
163 * the processing type of the request
164 */
165 public Processing getProcessing()
166 {
167 return processing;
168 }
169
170
171 /**
172 * Sets the processing type of the request
173 *
174 * @param processing
175 * the processing type to set
176 */
177 public void setProcessing( Processing processing )
178 {
179 this.processing = processing;
180 }
181
182
183 /**
184 * Gets the on error handling type of the request
185 *
186 * @return
187 * the on error handling type of the request
188 */
189 public OnError getOnError()
190 {
191 return onError;
192 }
193
194
195 /**
196 * Sets the on error handling type of the request
197 *
198 * @param onError
199 * the on error handling type to set
200 */
201 public void setOnError( OnError onError )
202 {
203 this.onError = onError;
204 }
205
206
207 /**
208 * Gets the reponse order type of the request
209 *
210 * @return
211 * the reponse order type of the request
212 */
213 public ResponseOrder getResponseOrder()
214 {
215 return responseOrder;
216 }
217
218
219 /**
220 * Sets the reponse order type of the request
221 *
222 * @param responseOrder
223 * the reponse order type to set
224 */
225 public void setResponseOrder( ResponseOrder responseOrder )
226 {
227 this.responseOrder = responseOrder;
228 }
229
230
231 /**
232 * Gets the List of all the requests in the Batch Request
233 *
234 * @return
235 * the List of all the requests in the Batch Request
236 */
237 public List getRequests()
238 {
239 return requests;
240 }
241
242
243 /* (non-Javadoc)
244 * @see java.lang.Object#toString()
245 */
246 @Override
247 public String toString()
248 {
249 StringBuffer sb = new StringBuffer();
250
251 sb.append( "[" );
252 sb.append( "processing: " + processing );
253 sb.append( " - " );
254 sb.append( "onError: " + onError );
255 sb.append( " - " );
256 sb.append( "responseOrder: " + responseOrder );
257 sb.append( "]" );
258
259 return sb.toString();
260 }
261 }