KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > request > BatchRequestDsml


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.directory.ldapstudio.dsmlv2.request;
21
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.apache.directory.ldapstudio.dsmlv2.DsmlDecorator;
27 import org.apache.directory.ldapstudio.dsmlv2.ParserUtils;
28 import org.apache.directory.ldapstudio.dsmlv2.request.BatchRequest.OnError;
29 import org.apache.directory.ldapstudio.dsmlv2.request.BatchRequest.Processing;
30 import org.apache.directory.ldapstudio.dsmlv2.request.BatchRequest.ResponseOrder;
31 import org.dom4j.Document;
32 import org.dom4j.DocumentHelper;
33 import org.dom4j.Element;
34
35
36 /**
37  * This class represents the Batch Request. It can be used to generate an the XML String of a BatchRequest.
38  *
39  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
40  * @version $Rev$, $Date$
41  */

42 public class BatchRequestDsml
43 {
44     /** The Requests list */
45     private List JavaDoc<DsmlDecorator> requests;
46
47     /** The ID of the request */
48     private int requestID;
49
50     /** The type of processing of the Batch Request */
51     private Processing processing;
52
53     /** The type of on error handling */
54     private OnError onError;
55
56     /** The response order */
57     private ResponseOrder responseOrder;
58
59
60     /**
61      * Creates a new instance of BatchResponseDsml.
62      */

63     public BatchRequestDsml()
64     {
65         requests = new ArrayList JavaDoc<DsmlDecorator>();
66         responseOrder = ResponseOrder.SEQUENTIAL;
67         processing = Processing.SEQUENTIAL;
68         onError = OnError.EXIT;
69     }
70
71
72     /**
73      * Adds a request to the Batch Request DSML.
74      *
75      * @param request
76      * the request to add
77      * @return
78      * true (as per the general contract of the Collection.add method).
79      */

80     public boolean addRequest( DsmlDecorator request )
81     {
82         return requests.add( request );
83     }
84
85
86     /**
87      * Removes a request from the Batch Request DSML.
88      *
89      * @param request
90      * the request to remove
91      * @return
92      * true if this list contained the specified element.
93      */

94     public boolean removeRequest( DsmlDecorator request )
95     {
96         return requests.remove( request );
97     }
98
99
100     /**
101      * Gets the ID of the request
102      *
103      * @return
104      * the ID of the request
105      */

106     public int getRequestID()
107     {
108         return requestID;
109     }
110
111
112     /**
113      * Sets the ID of the request
114      *
115      * @param requestID
116      * the ID to set
117      */

118     public void setRequestID( int requestID )
119     {
120         this.requestID = requestID;
121     }
122
123
124     /**
125      * Gets the processing type of the request
126      *
127      * @return
128      * the processing type of the request
129      */

130     public Processing getProcessing()
131     {
132         return processing;
133     }
134
135
136     /**
137      * Sets the processing type of the request
138      *
139      * @param processing
140      * the processing type to set
141      */

142     public void setProcessing( Processing processing )
143     {
144         this.processing = processing;
145     }
146
147
148     /**
149      * Gets the on error handling type of the request
150      *
151      * @return
152      * the on error handling type of the request
153      */

154     public OnError getOnError()
155     {
156         return onError;
157     }
158
159
160     /**
161      * Sets the on error handling type of the request
162      *
163      * @param onError
164      * the on error handling type to set
165      */

166     public void setOnError( OnError onError )
167     {
168         this.onError = onError;
169     }
170
171
172     /**
173      * Gets the reponse order type of the request
174      *
175      * @return
176      * the reponse order type of the request
177      */

178     public ResponseOrder getResponseOrder()
179     {
180         return responseOrder;
181     }
182
183
184     /**
185      * Sets the reponse order type of the request
186      *
187      * @param responseOrder
188      * the reponse order type to set
189      */

190     public void setResponseOrder( ResponseOrder responseOrder )
191     {
192         this.responseOrder = responseOrder;
193     }
194
195
196     /**
197      * Converts the Batch Request to its XML representation in the DSMLv2 format.
198      */

199     public String JavaDoc toDsml()
200     {
201         Document document = DocumentHelper.createDocument();
202         Element element = document.addElement( "batchRequest" );
203
204         // RequestID
205
if ( requestID != 0 )
206         {
207             element.addAttribute( "requestID", "" + requestID );
208         }
209
210         // ResponseOrder
211
if ( responseOrder == ResponseOrder.UNORDERED )
212         {
213             element.addAttribute( "responseOrder", "unordered" );
214         }
215
216         // Processing
217
if ( processing == Processing.PARALLEL )
218         {
219             element.addAttribute( "processing", "parallel" );
220         }
221
222         // On Error
223
if ( onError == OnError.RESUME )
224         {
225             element.addAttribute( "onError", "resume" );
226         }
227
228         // Requests
229
for ( DsmlDecorator request : requests )
230         {
231             request.toDsml( element );
232         }
233
234         return ParserUtils.styleDocument( document ).asXML();
235     }
236 }
237
Popular Tags