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: IDPEntries.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 java.util.List;
033import java.util.Collections;
034import java.util.Iterator;
035import java.util.ArrayList;
036
037import org.w3c.dom.Element;
038import org.w3c.dom.Node;
039import org.w3c.dom.NodeList;
040
041import com.sun.identity.saml.common.SAMLUtils;
042import com.sun.identity.federation.common.FSUtils;
043import com.sun.identity.federation.common.IFSConstants;
044
045/**
046 * This class defines methods to set/retrieve multiple Identity Providers.
047 *
048 * @supported.all.api
049 * @deprecated since 12.0.0
050 */
051@Deprecated
052public class IDPEntries {
053    private List idpEntryList = null;
054    private List otherElements = null;
055    
056    /**
057     * Default Constructor.
058     */
059    public IDPEntries() {
060    }
061    
062    
063    /**
064     * Constructor creates <code>IDPEntries</code> object.
065     *
066     * @param idpEntries list of identity providers.
067     */
068    public IDPEntries(List idpEntries) {
069        this.idpEntryList = idpEntries;
070    }
071    
072    /**
073     * Returns the list of Identity Providers.
074     *
075     * @return  list of Identity Providers.
076     * @see #setIDPEntryList(List)
077     */
078    public List getIDPEntryList() {
079        return idpEntryList;
080    }
081    
082    /**
083     * Sets the list of Identity Providers.
084     *
085     * @param idpEntryList the list of Identity Providers.
086     * @see #getIDPEntryList
087     */
088    public void setIDPEntryList(List idpEntryList) {
089        this.idpEntryList = idpEntryList;
090    }
091    
092    /**
093     * Returns the string representation of this object.
094     * This method translates the response to an XML document string.
095     *
096     * @return An XML String representing the response. NOTE: this is a
097     *         complete SAML response xml string with ResponseID,
098     *         MajorVersion, etc.
099     */
100    
101    public String toXMLString() throws FSMsgException {
102        return toXMLString(true, true);
103    }
104    
105    /**
106     * Returns a String representation of this object.
107     *
108     * @param includeNS : Determines whether or not the namespace qualifier
109     *        is prepended to the Element when converted
110     * @param declareNS : Determines whether or not the namespace is declared
111     *        within the Element.
112     * @return a string containing the valid XML for this element
113     * @throws FSMsgException if there is an error converting
114     *         this object ot a string.
115     */
116    
117    public String toXMLString(boolean includeNS, boolean declareNS)
118    throws FSMsgException {
119        return toXMLString(includeNS, declareNS, false);
120    }
121    
122    /**
123     * Returns a String representation of this object.
124     *
125     * @param includeNS Determines whether or not the namespace qualifier
126     *        is prepended to the Element when converted
127     * @param declareNS Determines whether or not the namespace is declared
128     *        within the Element.
129     * @param includeHeader Determines whether the output include the xml
130     *        declaration header.
131     * @return a string containing the valid XML for this element
132     * @throws FSMsgException if there is an error converting
133     *         this object ot a string.
134     */
135    public String toXMLString(boolean includeNS,boolean declareNS,
136            boolean includeHeader) throws FSMsgException {
137        StringBuffer xml = new StringBuffer(300);
138        if (includeHeader) {
139            xml.append("<?xml version=\"1.0\" encoding=\"").
140                    append(IFSConstants.DEFAULT_ENCODING).append("\" ?>\n");
141        }
142        String prefix = "";
143        String uri = "";
144        if (includeNS) {
145            prefix = IFSConstants.LIB_PREFIX;
146        }
147        if (declareNS) {
148            uri = IFSConstants.LIB_NAMESPACE_STRING;
149        }
150        
151        xml.append("<").append(prefix).append("IDPEntries").append(uri).
152                append(">\n");
153        
154        
155        if((idpEntryList != null) && (idpEntryList != Collections.EMPTY_LIST)){
156            Iterator i = idpEntryList.iterator();
157            
158            while (i.hasNext()) {
159                IDPEntry entry = (IDPEntry)i.next();
160                xml.append(entry.toXMLString(true, false));
161            }
162        }
163        xml.append("</").append(prefix).append("IDPEntries>\n");
164        
165        return xml.toString();
166    }
167    /**
168     * Constructor creates <code>IDPEntries</code> object from
169     * a Document Element.
170     *
171     * @param root the Document Element object.
172     * @throws FSMsgException on error.
173     */
174    public IDPEntries(Element root) throws FSMsgException {
175        if (root == null) {
176            SAMLUtils.debug.message("IDPEntries.parseXML: null input.");
177            throw new FSMsgException("nullInput",null);
178        }
179        String tag = null;
180        if (((tag = root.getLocalName()) == null) ||
181                (!tag.equals("IDPEntries"))) {
182            FSUtils.debug.message("IDPEntries.parseXML: wrong input.");
183            throw new FSMsgException("wrongInput",null);
184        }
185        NodeList nl = root.getChildNodes();
186        Node child;
187        String childName;
188        int length = nl.getLength();
189        for (int i = 0; i < length; i++) {
190            child = nl.item(i);
191            if ((childName = child.getLocalName()) != null) {
192                if (childName.equals("IDPEntry")) {
193                    if ((idpEntryList == null) ||
194                            (idpEntryList == Collections.EMPTY_LIST)) {
195                        idpEntryList = new ArrayList();
196                    }
197                    idpEntryList.add(new IDPEntry((Element)child));
198                }else{
199                }
200            }
201        }
202    }
203}