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: Status.java,v 1.2 2008/06/25 05:47:09 qcheng Exp $ 026 * 027 */ 028 029 030package com.sun.identity.liberty.ws.common; 031 032import javax.xml.namespace.QName; 033 034/** 035 * This class represents a common status object. 036 * The following schema fragment specifies the expected content within the 037 * <code>Status</code> object. 038 * <pre> 039 * <complexType name="Status"> 040 * <complexContent> 041 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 042 * <sequence> 043 * <element ref="Status" minOccurs="0"/> 044 * </sequence> 045 * <attribute name="code" use="required" type="{http://www.w3.org/2001/XMLSchema}QName" /> 046 * <attribute name="comment" type="{http://www.w3.org/2001/XMLSchema}string" /> 047 * <attribute name="ref" type="{http://www.w3.org/2001/XMLSchema}IDREF" /> 048 * </restriction> 049 * </complexContent> 050 * </complexType> 051 * </pre> 052 * 053 * @supported.all.api 054 */ 055public class Status { 056 057 private Status status; 058 private String ref; 059 private QName code; 060 private String comment; 061 private String ns = null; 062 private String nsPrefix = null; 063 064 /** 065 * Default constructor. 066 */ 067 public Status() {} 068 069 /** 070 * Constructor. 071 * 072 * @param ns Name space for the Status object 073 * @param nsPrefix prefix used for the name space, for example, 074 * <code>disco</code>. 075 */ 076 public Status(String ns, String nsPrefix) { 077 this.ns = ns; 078 this.nsPrefix = nsPrefix; 079 } 080 081 /** 082 * Gets sub status. 083 * @return Status 084 * @see #setSubStatus(Status) 085 */ 086 public Status getSubStatus() { 087 return status; 088 } 089 090 /** 091 * Sets sub status. The sub status is used by a service to convey 092 * second-level status information in addition to the status code. 093 * @param status Status to be set 094 * @see #getSubStatus() 095 */ 096 public void setSubStatus(Status status) { 097 this.status = status; 098 } 099 100 /** 101 * Gets reference attribute. 102 * 103 * @return reference attribute. 104 * @see #setRef(String) 105 */ 106 public String getRef() { 107 return ref; 108 } 109 110 /** 111 * Sets reference attribute. 112 * @param value reference to be set 113 * @see #getRef() 114 */ 115 public void setRef(String value) { 116 this.ref = value; 117 } 118 119 /** 120 * Gets status code. 121 * 122 * @return status code. 123 * @see #setCode(QName) 124 */ 125 public QName getCode() { 126 return code; 127 } 128 129 /** 130 * Sets status code. 131 * @param value status code to be set 132 * @see #getCode() 133 */ 134 public void setCode(QName value) { 135 this.code = value; 136 } 137 138 /** 139 * Gets comment for the status. 140 * 141 * @return comment for the status. 142 * @see #setComment(String) 143 */ 144 public String getComment() { 145 return comment; 146 } 147 148 /** 149 * Sets comment 150 * @param comment String 151 * @see #getComment() 152 */ 153 public void setComment(String comment) { 154 this.comment = comment; 155 } 156 157 /** 158 * Returns string format of the status. 159 * @return String 160 */ 161 public String toString() { 162 StringBuffer sb = new StringBuffer(500); 163 sb.append("<"); 164 if ((nsPrefix != null) && nsPrefix.length() != 0) { 165 sb.append(nsPrefix).append(":Status xmlns:").append(nsPrefix). 166 append("=\""); 167 } else { 168 sb.append("Status xmlns=\""); 169 } 170 // ns must be present 171 sb.append(ns).append("\""); 172 173 if (code != null) { 174 String localPart = code.getLocalPart(); 175 if ((localPart != null) && localPart.length() != 0) { 176 sb.append(" code=\""); 177 String codeNS = code.getNamespaceURI(); 178 if ((codeNS == null) || codeNS.length() == 0) { 179 sb.append(localPart).append("\""); 180 } else { 181 if ((ns != null) && ns.equals(codeNS)) { 182 if ((nsPrefix != null) && nsPrefix.length() != 0) { 183 sb.append(nsPrefix).append(":"); 184 } 185 sb.append(localPart).append("\""); 186 } else { 187 String codePrefix = code.getPrefix(); 188 if ((codePrefix != null) && codePrefix.length() != 0) { 189 sb.append(codePrefix).append(":"). 190 append(localPart).append("\" xmlns:"). 191 append(codePrefix).append("=\""). 192 append(codeNS).append("\""); 193 } else { 194 if ((nsPrefix == null) || nsPrefix.length() == 0) { 195 sb.append("ns1:").append(localPart). 196 append("\" xmlns:").append("ns1=\""). 197 append(codeNS).append("\""); 198 } else { 199 sb.append(localPart).append("\" xmlns=\""). 200 append(codeNS).append("\""); 201 } 202 } 203 } 204 } 205 } 206 } 207 208 if ((ref != null) && ref.length() != 0) { 209 sb.append(" ref=\"").append(ref).append("\""); 210 } 211 212 if ((comment != null) && comment.length() != 0) { 213 sb.append(" comment=\"").append(comment).append("\""); 214 } 215 sb.append(">"); 216 if (status != null) { 217 status.toString(); 218 } 219 if ((nsPrefix != null) && nsPrefix.length() != 0) { 220 sb.append("</").append(nsPrefix).append(":Status>"); 221 } else { 222 sb.append("</Status>"); 223 } 224 return sb.toString(); 225 } 226}
Copyright © 2010-2017, ForgeRock All Rights Reserved.