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: ModifyResponse.java,v 1.2 2008/06/25 05:47:10 qcheng Exp $ 026 * 027 */ 028 029 030package com.sun.identity.liberty.ws.disco; 031 032import java.util.Iterator; 033import java.util.List; 034import java.util.ArrayList; 035import java.util.StringTokenizer; 036 037import org.w3c.dom.*; 038 039import com.sun.identity.shared.xml.XMLUtils; 040import com.sun.identity.liberty.ws.common.Status; 041import com.sun.identity.liberty.ws.disco.common.DiscoConstants; 042import com.sun.identity.liberty.ws.disco.common.DiscoUtils; 043 044/** 045 * The class <code>ModifyResponse</code> represents a discovery response for 046 * modify request. 047 * <p>The following schema fragment specifies the expected content within the 048 * <code>ModifyResponse</code> object. 049 * <p> 050 * <pre> 051 * <complexType name="ModifyResponseType"> 052 * <complexContent> 053 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 054 * <sequence> 055 * <element ref="{urn:liberty:disco:2003-08}Status"/> 056 * </sequence> 057 * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" /> 058 * <attribute name="newEntryIDs"> 059 * <simpleType> 060 * <list itemType="{urn:liberty:disco:2003-08}IDReferenceType" /> 061 * </simpleType> 062 * </attribute> 063 * </restriction> 064 * </complexContent> 065 * </complexType> 066 * </pre> 067 * 068 * @supported.all.api 069 */ 070public class ModifyResponse { 071 072 private String id = null; 073 private List newEntryIDs = null; 074 private Status status = null; 075 private Element extension = null; 076 077 /** 078 * constructor. 079 * @param status Status of the modify response 080 */ 081 public ModifyResponse (com.sun.identity.liberty.ws.common.Status status) { 082 this.status = status; 083 } 084 085 /** 086 * Constructor. 087 * @param root <code>ModifyResponse</code> DOM element. 088 * @exception DiscoveryException if error occurs. 089 */ 090 public ModifyResponse(Element root) throws DiscoveryException { 091 if (root == null) { 092 DiscoUtils.debug.message("ModifyResponse(Element): null input."); 093 throw new DiscoveryException( 094 DiscoUtils.bundle.getString("nullInput")); 095 } 096 String nodeName; 097 String nameSpaceURI; 098 if (((nodeName = root.getLocalName()) == null) || 099 (!nodeName.equals("ModifyResponse")) || 100 ((nameSpaceURI = root.getNamespaceURI()) == null) || 101 (!nameSpaceURI.equals(DiscoConstants.DISCO_NS))) 102 { 103 DiscoUtils.debug.message("ModifyResponse(Element): wrong input"); 104 throw new DiscoveryException( 105 DiscoUtils.bundle.getString("wrongInput")); 106 } 107 108 id = root.getAttribute("id"); 109 110 String ids = root.getAttribute("newEntryIDs"); 111 if ((ids != null) && (ids.length() != 0)) { 112 StringTokenizer st = new StringTokenizer(ids); 113 if (st.countTokens() > 0) { 114 if (newEntryIDs == null) { 115 newEntryIDs = new ArrayList(); 116 } 117 while (st.hasMoreTokens()) { 118 newEntryIDs.add(st.nextToken()); 119 } 120 } 121 } 122 123 NodeList contentnl = root.getChildNodes(); 124 Node child; 125 for (int i = 0, length = contentnl.getLength(); i < length; i++) { 126 child = contentnl.item(i); 127 if ((nodeName = child.getLocalName()) != null) { 128 nameSpaceURI = ((Element) child).getNamespaceURI(); 129 if ((nodeName.equals("Status")) && 130 (nameSpaceURI != null) && 131 (nameSpaceURI.equals(DiscoConstants.DISCO_NS))) 132 { 133 if (status != null) { 134 if (DiscoUtils.debug.messageEnabled()) { 135 DiscoUtils.debug.message("ModifyResponse(Element): " 136 + "included more than one Status."); 137 } 138 throw new DiscoveryException( 139 DiscoUtils.bundle.getString("moreElement")); 140 } 141 status = DiscoUtils.parseStatus((Element) child); 142 } else if ((nodeName.equals("Extension")) && 143 (nameSpaceURI != null) && 144 (nameSpaceURI.equals(DiscoConstants.DISCO_NS))) 145 { 146 if (extension != null) { 147 if (DiscoUtils.debug.messageEnabled()) { 148 DiscoUtils.debug.message("ModifyResponse(Element): " 149 + "included more than one Extension."); 150 } 151 throw new DiscoveryException( 152 DiscoUtils.bundle.getString("moreElement")); 153 } 154 extension = (Element) child; 155 156 } else { 157 if (DiscoUtils.debug.messageEnabled()) { 158 DiscoUtils.debug.message("ModifyResponse(Element): " 159 + "invalid node" + nodeName); 160 } 161 throw new DiscoveryException( 162 DiscoUtils.bundle.getString("wrongInput")); 163 } 164 } 165 } 166 167 if (status == null) { 168 if (DiscoUtils.debug.messageEnabled()) { 169 DiscoUtils.debug.message("ModifyResponse(Element): missing " 170 + "Status."); 171 } 172 throw new DiscoveryException( 173 DiscoUtils.bundle.getString("missingStatus")); 174 } 175 176 177 } 178 179 /** 180 * Gets modify response status. 181 * @return Status 182 * @see #setStatus(com.sun.identity.liberty.ws.common.Status) 183 */ 184 public com.sun.identity.liberty.ws.common.Status getStatus() { 185 return status; 186 } 187 188 /** 189 * Sets modify response status. 190 * @param value Status 191 * @see #getStatus() 192 */ 193 public void setStatus(com.sun.identity.liberty.ws.common.Status value) { 194 status = value; 195 } 196 197 /** 198 * Gets id attribute. 199 * 200 * @return id attribute. 201 * @see #setId(String) 202 */ 203 public java.lang.String getId() { 204 return id; 205 } 206 207 /** 208 * Sets id attribute. 209 * 210 * @param id id attribute. 211 * @see #getId() 212 */ 213 public void setId(String id) { 214 this.id = id; 215 } 216 217 /** 218 * Gets the <code>newEntryIDs</code> attribute. 219 * 220 * @return the <code>newEntryIDs</code> attribute. 221 * @see #setNewEntryIDs(List) 222 */ 223 public List getNewEntryIDs() { 224 return newEntryIDs; 225 } 226 227 /** 228 * Sets the <code>newEntryIDs</code> attribute. 229 * @param ids values of the <code>newEntryIDs</code> attribute. 230 * @see #getNewEntryIDs() 231 */ 232 public void setNewEntryIDs(List ids) { 233 newEntryIDs = ids; 234 } 235 236 /** 237 * Gets modify response Extension Element. 238 * @return Extension Element 239 * @see #setExtension(Element) 240 */ 241 public Element getExtension() { 242 return extension; 243 } 244 245 /** 246 * Sets modify response extension. 247 * @param extension Element 248 * @see #getExtension() 249 */ 250 public void setExtension(Element extension) { 251 this.extension = extension; 252 } 253 254 /** 255 * Gets formatted string of modify response. 256 * 257 * @return formatted string of modify response. 258 */ 259 260 public java.lang.String toString() { 261 StringBuffer sb = new StringBuffer(400); 262 sb.append("<ModifyResponse xmlns=\"").append(DiscoConstants.DISCO_NS). 263 append("\""); 264 if ((id != null) && id.length() != 0) { 265 sb.append(" id=\"").append(id).append("\""); 266 } 267 if (newEntryIDs != null) { 268 sb.append(" newEntryIDs=\""); 269 Iterator iter = newEntryIDs.iterator(); 270 if (iter.hasNext()) { 271 sb.append((String) iter.next()); 272 } 273 while (iter.hasNext()) { 274 sb.append(" ").append((String) iter.next()); 275 } 276 sb.append("\""); 277 } 278 sb.append(">"); 279 if (status != null) { 280 sb.append(status.toString()); 281 } 282 if (extension != null) { 283 sb.append(XMLUtils.print(extension)); 284 } 285 sb.append("</ModifyResponse>"); 286 return sb.toString(); 287 } 288}