KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > reponse > BatchResponseDsml


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.reponse;
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.dom4j.Document;
29 import org.dom4j.DocumentHelper;
30 import org.dom4j.Element;
31
32
33 /**
34  * This class represents the Batch Response. It can be used to generate an the XML String of a BatchResponse.
35  *
36  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
37  * @version $Rev$, $Date$
38  */

39 public class BatchResponseDsml
40 {
41     /** The Responses list */
42     private List JavaDoc<DsmlDecorator> responses;
43
44     /** The ID of the response */
45     private int requestID;
46
47
48     /**
49      * Creates a new instance of BatchResponseDsml.
50      */

51     public BatchResponseDsml()
52     {
53         responses = new ArrayList JavaDoc<DsmlDecorator>();
54     }
55
56
57     /**
58      * Adds a request to the Batch Response DSML.
59      *
60      * @param response
61      * the request to add
62      * @return
63      * true (as per the general contract of the Collection.add method).
64      */

65     public boolean addResponse( DsmlDecorator response )
66     {
67         return responses.add( response );
68     }
69
70
71     /**
72      * Removes a request from the Batch Response DSML.
73      *
74      * @param response
75      * the request to remove
76      * @return
77      * true if this list contained the specified element.
78      */

79     public boolean removeResponse( DsmlDecorator response )
80     {
81         return responses.remove( response );
82     }
83
84
85     /**
86      * Gets the ID of the response
87      * @return
88      * the ID of the response
89      */

90     public int getRequestID()
91     {
92         return requestID;
93     }
94
95
96     /**
97      * Sets the ID of the response
98      *
99      * @param requestID
100      * the ID to set
101      */

102     public void setRequestID( int requestID )
103     {
104         this.requestID = requestID;
105     }
106
107
108     /**
109      * Converts the Batch Response to its XML representation in the DSMLv2 format.
110      */

111     public String JavaDoc toDsml()
112     {
113         Document document = DocumentHelper.createDocument();
114         Element element = document.addElement( "batchResponse" );
115
116         // RequestID
117
if ( requestID != 0 )
118         {
119             element.addAttribute( "requestID", "" + requestID );
120         }
121
122         for ( DsmlDecorator response : responses )
123         {
124             response.toDsml( element );
125         }
126
127         return ParserUtils.styleDocument( document ).asXML();
128     }
129 }
130
Popular Tags