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: DSTModifyResponse.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.Date;
034import java.util.List;
035import java.util.ArrayList;
036import com.sun.identity.shared.DateUtils;
037import com.sun.identity.liberty.ws.common.Status;
038import org.w3c.dom.Element;
039import org.w3c.dom.Node;
040import org.w3c.dom.NodeList;
041
042/**
043 * The <code>DSTModifyResponse</code> class represents a <code>DST</code>
044 * response for <code>DST</code> modify request.
045 * 
046 * The following schema fragment specifies the expected content within the
047 * <code>DSTModifyResponse</code> object.
048 * <pre>
049 * &lt;complexType name="ResponseType">
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 ref="{urn:liberty:idpp:2003-08}Extension"
055 *         maxOccurs="unbounded" minOccurs="0"/>
056 *       &lt;/sequence>
057 *       &lt;attribute name="timeStamp"
058 *       type="{http://www.w3.org/2001/XMLSchema}dateTime" />
059 *       &lt;attribute name="itemIDRef"
060 *       type="{urn:liberty:idpp:2003-08}IDReferenceType" />
061 *       &lt;attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" />
062 *     &lt;/restriction>
063 *   &lt;/complexContent>
064 * &lt;/complexType>
065 * </pre>
066 * 
067 * @supported.all.api
068 */
069public class DSTModifyResponse {
070
071    private Status status;
072    private Date timeStamp;
073    private String id;
074    private String itemIDRef; 
075    private List extension = new ArrayList();
076    private String nameSpaceURI = null;
077    private String prefix = null;
078
079    /**
080     * Default constructor
081     */
082    public DSTModifyResponse () {}
083
084    /**
085     * Constructor
086     * @param element <code>DOM</code> Element.
087     * @throws DSTException
088     */
089    public DSTModifyResponse(org.w3c.dom.Element element) throws DSTException{
090        if(element == null) {
091           DSTUtils.debug.error("DSTModifyResponse(element):null input");
092           throw new DSTException(DSTUtils.bundle.getString("nullInputParams"));
093        }
094        String elementName = element.getLocalName();
095        if(elementName == null || !elementName.equals("ModifyResponse")) {
096           DSTUtils.debug.error("DSTModifyResponse(element):Invalid " +
097           "element name");
098           throw new DSTException(DSTUtils.bundle.getString("invalidElement"));
099        }
100        nameSpaceURI = element.getNamespaceURI();
101        if(nameSpaceURI == null) {
102           DSTUtils.debug.error("DSTModifyResponse(element): NameSpace" +
103           " is not defined");
104           throw new DSTException(DSTUtils.bundle.getString("noNameSpace"));
105        }
106        prefix = element.getPrefix();
107        id = element.getAttribute("id");
108        itemIDRef = element.getAttribute("itemIDRef");
109        String attrib = element.getAttribute("timeStamp");
110
111        if (attrib != null && attrib.length() != 0) {
112            try {
113                timeStamp = DateUtils.stringToDate(attrib);
114            } catch(ParseException ex) {
115                DSTUtils.debug.error(
116                    "DSTModifyResponse(element): can not parse the date", ex); 
117            }
118        }
119
120        NodeList list = element.getChildNodes();
121        if(list == null || list.getLength() == 0) {
122           DSTUtils.debug.error("DSTModifyResponse(element): Response does" +
123           "not have status element.");
124           throw new DSTException(DSTUtils.bundle.getString("noStatus"));
125        }
126
127        for(int i=0; i < list.getLength(); i++) {
128           Node node = list.item(i);
129           if(node.getNodeType() != Node.ELEMENT_NODE) {
130              continue;
131           }
132           String nodeName = node.getLocalName();
133           if(nodeName != null && nodeName.equals("Status")) {
134              status = DSTUtils.parseStatus((Element)node);
135           } else {
136              DSTUtils.debug.error("DSTModifyResponse(element): Response does" +
137              "have invalid element.");
138              throw new DSTException(
139              DSTUtils.bundle.getString("invalidElement"));
140           }
141        }
142      
143        if(status == null) {
144           DSTUtils.debug.error("DSTModifyResponse(element): Response does" +
145           "not have status element.");
146           throw new DSTException(DSTUtils.bundle.getString("noStatus"));
147        }
148    }
149
150    /**
151     * Gets response status 
152     * @return Status
153     */
154    public com.sun.identity.liberty.ws.common.Status getStatus() {
155        return status;
156    }
157
158    /**
159     * Sets response status 
160     * @param status response status to be set 
161     */
162    public void setStatus(com.sun.identity.liberty.ws.common.Status status) {
163        this.status = status;
164    }
165
166    /**
167     * Gets time stamp 
168     * @return Date for the time stamp
169     */
170    public java.util.Date getTimeStamp() {
171        return timeStamp;
172    }
173
174    /**
175     * Sets time stamp 
176     * @param date time stamp date to be set
177     */
178    public void setTimeStamp(java.util.Date date) {
179        this.timeStamp = date;
180    }
181
182    /**
183     * Gets id attribute 
184     * @return String id attribute value
185     */
186    public java.lang.String getId() {
187        return id;
188    }
189
190    /**
191     * Sets id attribute
192     * @param id value of id attribute to be set
193     */
194    public void setId(java.lang.String id) {
195        this.id = id;
196    }
197
198    /**
199     * Gets item id reference 
200     * @return item id reference 
201     */
202    public java.lang.String getItemIDRef() {
203        return itemIDRef;
204    }
205
206    /**
207     * Sets item id reference 
208     * @param value item id reference to be set 
209     */
210    public void setItemIDRef(java.lang.String value) {
211        this.itemIDRef = value;
212    }
213
214    /**
215     * Gets the extension property.
216     * @return List of Object 
217     * 
218     */
219    java.util.List getExtension() {
220        return extension;
221    }
222
223    /**
224     * Gets the name space.
225     *
226     * @return name space.
227     */
228    public java.lang.String getNameSpaceURI() {
229        return nameSpaceURI;
230    }
231
232    /**
233     * Sets the name space.
234     * @param nameSpace Name space URI String
235     */
236    public void setNameSpaceURI(String nameSpace) {
237        this.nameSpaceURI = nameSpace;
238    }
239
240    /**
241     * Sets the name space prefix.
242     * @param prefix Name space prefix.
243     */
244    public void setNameSpacePrefix(String prefix) {
245        this.prefix = prefix;
246    }
247
248    /**
249     * Gets the name space prefix.
250     * @return Name space prefix.
251     */
252    public java.lang.String getNameSpacePrefix() {
253        return prefix;
254    }
255
256    /**
257     * Creates a String representation of this object.
258     * By default name space name is prepended to the element name
259     * @return String A string containing the valid XML for this element
260     */
261    public java.lang.String toString() {
262        return toString(true, false);
263    }
264
265    /**
266     * Creates a String representation of this object.
267     * @param includeNS if true prepends all elements by their name space
268     *        prefix.
269     * @param declareNS if true includes the name space within the generated.
270     * @return A string containing the valid XML for this element
271     */
272    public java.lang.String toString(boolean includeNS, boolean declareNS) {
273
274        String tempPrefix = "";
275        if(includeNS) {
276           if(prefix == null) {
277              prefix = DSTConstants.DEFAULT_NS_PREFIX;
278           }
279           tempPrefix = prefix + ":";
280        }
281        if(declareNS) {
282           if(nameSpaceURI == null) {
283              DSTUtils.debug.error("DSTModifyResponse.toString: NameSpace is" +
284              " not defined");
285              return "";
286           }
287        }
288        StringBuffer sb = new StringBuffer(300);
289        sb.append("<").append(tempPrefix).append("ModifyResponse");
290        if(id != null && id.length() != 0) {
291           sb.append(" id=\"").append(id).append("\"");
292        }
293        if(itemIDRef != null && itemIDRef.length() != 0) {
294           sb.append(" itemIDRef=\"").append(itemIDRef).append("\"");
295        }
296
297        if(timeStamp != null) {
298            sb.append(" timeStamp=\"")
299                .append(DateUtils.toUTCDateFormat(timeStamp))
300                .append("\"");
301        }
302
303        if(declareNS) {
304           sb.append(" xmlns:").append(prefix).append("=\"")
305             .append(nameSpaceURI).append("\"")
306             .append(" xmlns=\"").append(nameSpaceURI).append("\"");
307        }
308        sb.append(">").append(status.toString())
309          .append("</").append(tempPrefix).append("ModifyResponse").append(">");
310
311        return sb.toString();
312    }
313
314}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.