001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: DSTQueryResponse.java,v 1.2 2008/06/25 05:47:13 qcheng Exp $
026 *
027 */
028
029
030package com.sun.identity.liberty.ws.dst;
031
032import java.text.ParseException;
033import java.util.List;
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.Iterator;
037import com.sun.identity.shared.DateUtils;
038import com.sun.identity.liberty.ws.common.Status;
039import org.w3c.dom.Node;
040import org.w3c.dom.Element;
041import org.w3c.dom.NodeList;
042
043/**
044 * The class <code>DSTQueryResponse</code> represents a <code>DST</code> query
045 * response.
046 * The following schema fragment specifies the expected content within
047 * the <code>DSTQueryResponse</code> object.
048 * <pre>
049 * &lt;complexType name="QueryResponse">
050 *   &lt;complexContent>
051 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
052 *       &lt;sequence>
053 *         &lt;element ref="{urn:liberty:idpp:2003-08}Status"/>
054 *         &lt;element name="Data" maxOccurs="unbounded" minOccurs="0">
055 *           &lt;complexType>
056 *             &lt;complexContent>
057 *               &lt;restriction 
058 *               base="{http://www.w3.org/2001/XMLSchema}anyType">
059 *                 &lt;sequence>
060 *                   &lt;any/>
061 *                 &lt;/sequence>
062 *                 &lt;attribute name="itemIDRef" 
063 *                 type="{urn:liberty:idpp:2003-08}IDReferenceType" />
064 *                 &lt;attribute name="id"
065 *                 type="{http://www.w3.org/2001/XMLSchema}ID" />
066 *               &lt;/restriction>
067 *             &lt;/complexContent>
068 *           &lt;/complexType>
069 *         &lt;/element>
070 *         &lt;element ref="{urn:liberty:idpp:2003-08}Extension" 
071 *         maxOccurs="unbounded" minOccurs="0"/>
072 *       &lt;/sequence>
073 *       &lt;attribute name="timeStamp" 
074 *       type="{http://www.w3.org/2001/XMLSchema}dateTime" />
075 *       &lt;attribute name="itemIDRef"
076 *       type="{urn:liberty:idpp:2003-08}IDReferenceType" />
077 *       &lt;attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" />
078 *     &lt;/restriction>
079 *   &lt;/complexContent>
080 * &lt;/complexType>
081 * </pre>
082 *
083 * @supported.all.api 
084 */
085public class DSTQueryResponse {
086
087     private Status dstStatus = null;
088     private String itemIDRef = null;
089     private String id = null;
090     private Date dateStamp = null;
091     private List data = new ArrayList();
092     private List extensions = new ArrayList();
093     private String nameSpaceURI = null;
094     private String prefix = null;
095  
096    /**
097     * Default constructor
098     */
099    public DSTQueryResponse() {}
100 
101    /**
102     * Constructor
103     * @param data List of <code>DSTData</code> objects 
104     * @param serviceNS service name space
105     */
106    public DSTQueryResponse(java.util.List data, String serviceNS) {
107        if (data != null) {
108            this.data = data;
109        }
110        nameSpaceURI = serviceNS;
111    }
112
113    /**
114     * Constructor
115     *
116     * @param element <code>DOM</code> Element 
117     * @throws DSTException
118     */
119    public DSTQueryResponse(org.w3c.dom.Element element) throws DSTException {
120        if(element == null) {
121           DSTUtils.debug.error("DSTQueryResponse(element):null input");
122           throw new DSTException(DSTUtils.bundle.getString("nullInputParams"));
123        }
124        String elementName = element.getLocalName();
125        if(elementName == null || !elementName.equals("QueryResponse")) {
126           DSTUtils.debug.error("DSTQueryResponse(element):Invalid " +
127           "element name");
128           throw new DSTException(DSTUtils.bundle.getString("invalidElement"));
129        }
130        nameSpaceURI = element.getNamespaceURI();
131        if(nameSpaceURI == null) {
132           DSTUtils.debug.error("DSTQueryResponse(element): NameSpace is" +
133           " not defined");
134           throw new DSTException(DSTUtils.bundle.getString("noNameSpace"));
135        }
136        prefix = element.getPrefix();
137        id = element.getAttribute("id");
138        itemIDRef = element.getAttribute("itemIDRef");
139        String attrib = element.getAttribute("timeStamp");
140
141        if(attrib != null && attrib.length() != 0) {
142            try {
143                dateStamp = DateUtils.stringToDate(attrib);
144            } catch (ParseException ex) {
145                DSTUtils.debug.error(
146                    "DSTQueryResponse(element): can not parse the date", ex);
147            }
148        }
149        NodeList list = element.getChildNodes();
150        if(list == null || list.getLength() == 0) {
151           DSTUtils.debug.error("DSTQueryResponse(element): Response does" +
152           "not have child elements.");
153           throw new DSTException(DSTUtils.bundle.getString("noStatus"));
154        }
155        for(int i=0; i < list.getLength(); i++) {
156           Node node = list.item(i);
157           if(node.getNodeType() != Node.ELEMENT_NODE) {
158              continue;
159           }
160           String nodeName = node.getLocalName();
161
162           if(nodeName != null && nodeName.equals("Status")) {
163             dstStatus = DSTUtils.parseStatus((Element)node);
164
165           } else if(nodeName != null && nodeName.equals("Data")) {
166             data.add(new DSTData((Element)node));
167
168           } else {
169             DSTUtils.debug.error("DSTQueryResponse(element): Response does" +
170             " have invalid elements.");
171             throw new DSTException(
172              DSTUtils.bundle.getString("invalidElement"));
173           }
174        }
175
176        if(dstStatus == null) {
177           DSTUtils.debug.error("DSTQueryResponse(element): Response does" +
178           "not have Status element.");
179           throw new DSTException(DSTUtils.bundle.getString("noStatus"));
180        }
181    }
182
183    /**
184     * Gets status for the query response
185     * @return Status
186     */
187    public com.sun.identity.liberty.ws.common.Status getStatus() {
188        return dstStatus;
189    }
190
191
192    /**
193     * Sets status for the query response
194     * @param status Status object to be set
195     */
196    public void setStatus(com.sun.identity.liberty.ws.common.Status status) {
197        this.dstStatus = status;
198    }
199
200    /**
201     * Gets time stamp
202     * @return Date
203     */
204    public java.util.Date getTimeStamp() {
205        return dateStamp;
206    }
207
208    /**
209     * Sets time stamp
210     * @param date Date to be set
211     */
212    public void setTimeStamp(java.util.Date date) {
213        this.dateStamp = date;
214    }
215
216    /**
217     * Gets id attribute.
218     *
219     * @return id attribute.
220     */
221    public java.lang.String getId() {
222        return id;
223    }
224
225    /**
226     * Sets id attribute
227     *
228     * @param id id attribute to be set 
229     */
230    public void setId(java.lang.String id) {
231        this.id = id;
232    }
233
234    /**
235     * Gets item reference.
236     *
237     * @return item reference.
238     */
239    public java.lang.String getItemIDRef() {
240        return itemIDRef;
241    }
242
243    /**
244     * Sets item reference.
245     *
246     * @param ref item ID reference to be set.
247     */
248    public void setItemIDRef(java.lang.String ref) {
249        this.itemIDRef = ref;
250    }
251
252    /**
253     * Gets the value of the Data property.
254     * 
255     * @return List of <code>DSTData</code> objects
256     * 
257     */
258    public java.util.List getData() {
259        return data;
260    }
261
262    /**
263     * Gets the extension property.
264     *
265     * @return List of any <code>java.lang.Object</code>
266     * 
267     */
268    public java.util.List getExtension() {
269        return extensions;
270    }
271
272    /**
273     * Gets the name space.
274     * @return Name space.
275     */
276    public java.lang.String getNameSpaceURI() {
277        return nameSpaceURI;
278    }
279
280    /**
281     * Sets the name space.
282     *
283     * @param nameSpace Name space URI.
284     */
285    public void setNameSpaceURI(String nameSpace) {
286        this.nameSpaceURI = nameSpace;
287    }
288
289    /**
290     * Sets the name space prefix.
291     * @param prefix Name Space prefix.
292     */
293    public void setNameSpacePrefix(String prefix) {
294        this.prefix = prefix;
295    }
296
297    /**
298     * Gets the name space prefix.
299     * @return Name Space prefix.
300     */
301    public java.lang.String getNameSpacePrefix() {
302        return prefix;
303    }
304
305    /**
306     * Creates a String representation of this object.
307     * By default name space name is prepended to the element name
308     * @return String A string containing the valid XML for this element
309     */
310    public java.lang.String toString() {
311        return toString(true, false);
312    }
313
314    /**
315     * Creates a String representation of this object.
316     * @param includeNS if true prepends all elements by their name space 
317     *                  prefix
318     * @param declareNS if true includes the name space  within the
319     *                  generated.
320     * @return String A string containing the valid XML for this element
321     */
322    public java.lang.String toString(boolean includeNS, boolean declareNS) {
323   
324        if(dstStatus == null) {
325           DSTUtils.debug.error("DSTQueryResponse.toString: Status is null");
326           return "";
327        }
328
329        String tempPrefix = "";
330        if(includeNS) {
331           if(prefix == null) {
332              prefix = DSTConstants.DEFAULT_NS_PREFIX;
333           }
334           tempPrefix = prefix + ":";
335        }
336        if(declareNS) {
337           if(nameSpaceURI == null) {
338              DSTUtils.debug.error("DSTQueryResponse.toString: Name Space is " +
339              "not defined");
340              return "";
341           }
342        }
343        StringBuffer sb = new StringBuffer(500);
344        sb.append("<").append(tempPrefix).append("QueryResponse");
345        if(id != null && id.length() != 0) {
346           sb.append(" id=\"").append(id).append("\"");
347        }
348        if(itemIDRef != null && itemIDRef.length() != 0) {
349           sb.append(" itemIDRef=\"").append(itemIDRef).append("\"");
350        }
351
352        if (dateStamp != null) {
353            sb.append(" timeStamp=\"")
354                .append(DateUtils.toUTCDateFormat(dateStamp))
355                .append("\"");
356        }
357        if(declareNS) {
358           sb.append(" xmlns:").append(prefix).append("=\"")
359             .append(nameSpaceURI).append("\"")
360             .append(" xmlns=\"").append(nameSpaceURI).append("\"");
361        }
362
363        sb.append(">").append(DSTConstants.NL).append(dstStatus.toString());
364        Iterator iter = data.iterator();
365        while(iter.hasNext()) {
366           DSTData dstData = (DSTData)iter.next(); 
367           sb.append(dstData.toString());
368        }
369        sb.append("</").append(tempPrefix).append("QueryResponse").append(">");
370        return sb.toString();
371    }
372
373
374}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.