a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The contents of this file are subject to the terms
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * of the Common Development and Distribution License
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * (the License). You may not use this file except in
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * compliance with the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * You can obtain a copy of the License at
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * See the License for the specific language governing
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * permission and limitations under the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * When distributing Covered Code, include this CDDL
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Header Notice in each file and include the License file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * If applicable, add the following below the CDDL Header,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * with the fields enclosed by brackets [] replaced by
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * your own identifying information:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * $Id: StatusCode.java,v 1.2 2008/06/25 05:47:37 qcheng Exp $
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml.common.SAMLConstants;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml.common.SAMLException;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml.common.SAMLRequesterException;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This class represents the <code>StatusCode</code> and
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>SubStatusCode</code> element. It corresponds to
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>samlp:StatusCodeType</code> in SAML protocol schema.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @supported.all.api
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This is the default constructor of <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructs an instance of <code>StatusCode</code> from a DOM element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param statusCode An DOM Element that's rooted by
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code><StatusCode></code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @exception SAMLException when an error occurs.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public StatusCode(Element statusCode) throws SAMLException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("StatusCode: null input.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("StatusCode: Wrong input: " + tagName);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((value == null) || (value.length() == 0)) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("StatusCode: empty attribute Value.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.bundle.getString("missingAttribute"));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster List subCodenl = XMLUtils.getElementsByTagNameNS1(
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster "StatusCode");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster subStatusCode = new StatusCode((Element) subCodenl.get(0));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("StatusCode: Included more than one"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Construct a <code>StatusCode</code> object from a value String and a sub
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param value The value of the <code>StatusCode</code>. This could be
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * prefixed by <code>samlp:</code>. If it is not prefixed, or
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * prefixed by prefix other than <code>samlp:</code>,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>samlp:</code> will be used instead.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param subCode The optional sub <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @exception SAMLException if value string is null, empty, or contains
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * wrong value.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public StatusCode(String value, StatusCode subCode) throws SAMLException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Construct a <code>StatusCode</code> object from a value String.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param value The value of the <code>StatusCode</code>. This could be
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * prefixed by <code>samlp:</code>. It it is not prefixed, or
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * prefixed by prefix other than <code>samlp:</code>,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>samlp:</code> will be used instead.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @exception SAMLException if value string is null, empty, or contains
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * wrong value.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public StatusCode(String value) throws SAMLException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster private String checkAndGetValue(String value) throws SAMLException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((value == null) || (value.length() == 0)) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("StatusCode: empty attribute Value.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.bundle.getString("missingAttribute"));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (SAMLConstants.PROTOCOL_PREFIX + value);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster StringTokenizer st = new StringTokenizer(value, ":");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("StatusCode: wrong attribute value.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Sets the sub <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param subcode <code>StatusCode</code> to be included.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public void setStatusCode(StatusCode subcode) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Gets the sub <code>StatusCode</code> of the <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Gets the value of the <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return A String representing the value of the <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Translates the <code>StatusCode</code> to an XML document String
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * based on the SAML schema.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return An XML String representing the <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return toString(true, false);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Creates a String representation of the
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code><samlp:StatusCode></code> element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param includeNS Determines whether or not the namespace qualifier
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * is prepended to the Element when converted
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param declareNS Determines whether or not the namespace is declared
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * within the Element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return A string containing the valid XML for this element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public String toString(boolean includeNS, boolean declareNS) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster xml.append("<").append(prefix).append(tag).append(uri).
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (value.startsWith(SAMLConstants.PROTOCOL_PREFIX)) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.error("StatusCode.toString: ", e);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster xml.append(subStatusCode.toString(includeNS, false));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster xml.append("</").append(prefix).append(tag).append(">\n");