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