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: OldProvidedNameIdentifier.java,v 1.2 2008/06/25 05:46:47 qcheng Exp $ 026 * Portions Copyrighted 2014 ForgeRock AS 027 */ 028 029 030package com.sun.identity.federation.message.common; 031 032import org.w3c.dom.Element; 033import com.sun.identity.shared.xml.XMLUtils; 034import com.sun.identity.saml.assertion.NameIdentifier; 035import com.sun.identity.federation.common.FSUtils; 036import com.sun.identity.federation.common.IFSConstants; 037import com.sun.identity.saml.common.SAMLException; 038 039/** 040 * This class has methods to create the original <code>NameIdentifier</code> 041 * object. 042 * 043 * @supported.all.api 044 * @deprecated since 12.0.0 045 */ 046@Deprecated 047public class OldProvidedNameIdentifier extends NameIdentifier { 048 049 protected int minorVersion = IFSConstants.FF_11_PROTOCOL_MINOR_VERSION; 050 051 /** 052 * Constructor to create <code>OldProvidedNameIdentifier</code> object. 053 * 054 * @param name 055 * @param nameQualifier 056 * @param format 057 * @throws SAMLException on error. 058 */ 059 public OldProvidedNameIdentifier(String name,String nameQualifier, 060 String format) throws SAMLException { 061 super(name, nameQualifier, format); 062 } 063 064 /** 065 * Constructor to create <code>OldProvidedNameIdentifier</code> Object 066 * from Document Element. 067 * 068 * @param oldProvidedNameIdentifierElement the Document Element. 069 * @throws FSMsgException if object cannot be created. 070 */ 071 072 public OldProvidedNameIdentifier( 073 Element oldProvidedNameIdentifierElement 074 ) throws FSMsgException { 075 Element elt = (Element) oldProvidedNameIdentifierElement; 076 String eltName = elt.getLocalName(); 077 if (eltName == null) { 078 if (FSUtils.debug.messageEnabled()) { 079 FSUtils.debug.message("OldProvidedNameIdentifier(Element): " 080 + "local name missing"); 081 } 082 throw new FSMsgException("nullInput",null) ; 083 } 084 if (!(eltName.equals("OldProvidedNameIdentifier"))) { 085 if (FSUtils.debug.messageEnabled()) { 086 FSUtils.debug.message("OldProvidedNameIdentifier(Element: " 087 + "invalid root element"); 088 } 089 throw new FSMsgException("invalidElement",null) ; 090 } 091 String read = elt.getAttribute("NameQualifier"); 092 if (read != null) { 093 setNameQualifier(read); 094 } 095 read = elt.getAttribute("Format"); 096 if (read != null) { 097 setFormat(read); 098 } 099 read = XMLUtils.getElementValue(elt); 100 if ((read == null) || (read.length() == 0)) { 101 if (FSUtils.debug.messageEnabled()) { 102 FSUtils.debug.message("OldProvidedNameIdentifier(Element: " 103 + "null input specified"); 104 } 105 throw new FSMsgException("nullInput",null) ; 106 } else { 107 setName(read); 108 } 109 } 110 /** 111 * Constructor creates <code>OldProvidedNameIdentifier</code> object. 112 * 113 * @param securityDomain 114 * @param name 115 * @throws FSMsgException it there is an error creating this object. 116 */ 117 public OldProvidedNameIdentifier( 118 String securityDomain, String name 119 ) throws FSMsgException { 120 if (name== null || name.length() == 0 ) { 121 if (FSUtils.debug.messageEnabled()) { 122 FSUtils.debug.message("OldProvidedNameIdentifier: " 123 + "null input specified"); 124 } 125 throw new FSMsgException("nullInput",null) ; 126 } 127 setName(name); 128 if(securityDomain==null) 129 setNameQualifier(""); 130 else 131 setNameQualifier(securityDomain); 132 } 133 134 /** 135 * Sets the <code>MinorVersion</code>. 136 * 137 * @param version the <code>MinorVersion</code>. 138 * @see #getMinorVersion() 139 */ 140 public void setMinorVersion(int version) { 141 minorVersion = version; 142 } 143 144 /** 145 * Returns the <code>MinorVersion</code>. 146 * 147 * @return the <code>MinorVersion</code>. 148 * @see #setMinorVersion(int) 149 */ 150 public int getMinorVersion() { 151 return minorVersion; 152 } 153 154 /** 155 * Returns a String representation of this object. 156 * 157 * @return a String representation of this object. 158 * @throws FSMsgExceptionif there is an error converting 159 * this object to a string. 160 */ 161 public String toXMLString() throws FSMsgException { 162 String xml = this.toXMLString(true, false); 163 return xml; 164 } 165 166 /** 167 * Returns a String representation of this object. 168 * 169 * @param includeNS : Determines whether or not the namespace qualifier 170 * is prepended to the Element when converted 171 * @param declareNS : Determines whether or not the namespace is declared 172 * within the Element. 173 * @return a <code>XML</code>String representation of this object. 174 * @throws FSMsgException if there is an error converting 175 * this object to a string. 176 */ 177 public String toXMLString(boolean includeNS, boolean declareNS) 178 throws FSMsgException { 179 StringBuffer xml = new StringBuffer(3000); 180 String NS=""; 181 String appendNS=""; 182 if (declareNS) { 183 if (minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) { 184 NS = IFSConstants.LIB_12_NAMESPACE_STRING; 185 } else { 186 NS = IFSConstants.LIB_NAMESPACE_STRING; 187 } 188 } 189 if (includeNS) appendNS=IFSConstants.LIB_PREFIX; 190 xml.append("<").append(appendNS).append("OldProvidedNameIdentifier"). 191 append(" ").append(NS).append(" "); 192 if ((getNameQualifier() != null) && 193 (!(getNameQualifier().length() == 0))) { 194 xml.append("NameQualifier").append("=\""). 195 append(getNameQualifier()). 196 append("\"").append(" "); 197 } 198 if ((getFormat() != null) && (!(getFormat().length() == 0))) { 199 xml.append("Format").append("=\"").append(getFormat()). 200 append("\"").append(" "); 201 } 202 if ((getName() != null) && (!(getName().length() == 0))) { 203 xml.append(">").append(getName()); 204 xml.append("</").append(appendNS). 205 append("OldProvidedNameIdentifier").append(">\n"); 206 } 207 return xml.toString(); 208 } 209}