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: DSTData.java,v 1.2 2008/06/25 05:47:13 qcheng Exp $
026 *
027 */
028
029
030package com.sun.identity.liberty.ws.dst;
031
032import java.util.List;
033import java.util.ArrayList;
034import java.util.Iterator;
035import com.sun.identity.shared.xml.XMLUtils;
036import org.w3c.dom.Node;
037import org.w3c.dom.Element;
038import org.w3c.dom.NodeList;
039
040/**
041 * The <code>DSTData</code> class provides a wrapper for any data entry.
042 * 
043 * The following schema fragment specifies the expected content within 
044 * the <code>DSTData</code> object.
045 * <pre>
046 * &lt;complexType>
047 *   &lt;complexContent>
048 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
049 *       &lt;sequence>
050 *         &lt;any/>
051 *       &lt;/sequence>
052 *       &lt;attribute name="itemIDRef" 
053 *       type="{urn:liberty:idpp:2003-08}IDReferenceType" />
054 *       &lt;attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" />
055 *     &lt;/restriction>
056 *   &lt;/complexContent>
057 * &lt;/complexType>
058 * </pre>
059 * 
060 * @supported.all.api
061 */
062
063public class DSTData {
064
065    private List dstData = new ArrayList();
066    private String itemIDRef = null;
067    private String id = null;
068    private String nameSpaceURI = null;
069    private String prefix = null;
070
071    /**
072     * Constructor
073     * @param data List of data XML <code>DOM</code> Elements.
074     * @param serviceNS service nameSpace
075     */
076    public DSTData (java.util.List data, String serviceNS) {
077        if(data != null) {
078           this.dstData.addAll(data);
079        }
080        nameSpaceURI = serviceNS;
081    }
082
083    /**
084     * Constructor
085     *
086     * @param element <code>DOM</code> Element
087     * @throws DSTException
088     */
089    public DSTData(org.w3c.dom.Element element) throws DSTException{
090        if(element == null) {
091           DSTUtils.debug.error("DSTData(element):null input");
092           throw new DSTException(DSTUtils.bundle.getString("nullInputParams"));
093        }
094        String elementName = element.getLocalName();
095        if(elementName == null || !elementName.equals("Data")) {
096           DSTUtils.debug.error("DSTData(element):Invalid element name");
097           throw new DSTException(DSTUtils.bundle.getString("invalidElement"));
098        }
099        nameSpaceURI = element.getNamespaceURI();
100        if(nameSpaceURI == null) {
101           DSTUtils.debug.error("DSTData(element): NameSpace is not defined");
102           throw new DSTException(DSTUtils.bundle.getString("noNameSpace"));
103        }
104        prefix = element.getPrefix();
105        id = element.getAttribute("id");
106        itemIDRef = element.getAttribute("itemIDRef");
107        NodeList list = element.getChildNodes(); 
108        int size = list.getLength();
109        for(int i=0; i < size; i++) {
110           Node dataNode = list.item(i);
111           if(dataNode.getNodeType() == Node.ELEMENT_NODE) {
112              dstData.add((Element)dataNode);
113           }
114        }
115
116    }
117
118    /**
119     * Gets id attribute.
120     *
121     * @return id attribute.
122     */
123    public java.lang.String getId() {
124        return id;
125    }
126
127    /**
128     * Sets id attribute
129     *
130     * @param id attribute 
131     */
132    public void setId(String id) {
133        this.id = id;
134    } 
135
136    /**
137     * Gets item reference.
138     *
139     * @return item reference.
140     */
141    public java.lang.String getItemIDRef() { 
142        return itemIDRef;
143    }
144
145    /**
146     * Sets item reference.
147     *
148     * @param ref reference item.
149     */
150    public void setItemIDRef(java.lang.String ref) {
151        this.itemIDRef = ref;
152    }
153
154    /**
155     * Gets the returned data objects.
156     * 
157     * @return List of any <code>java.lang.Object</code>.
158     * 
159     */
160    public java.util.List getData() {
161        return dstData;
162    }
163
164    /**
165     * Gets the name space.
166     * @return Name space.
167     */
168    public java.lang.String getNameSpaceURI() {
169        return nameSpaceURI;
170    }
171
172    /**
173     * Sets the name space.
174     * @param nameSpace NameSpace URI
175     */
176    public void setNameSpaceURI(String nameSpace) {
177        this.nameSpaceURI = nameSpace;
178    }
179
180    /**
181     * Sets the name space prefix.
182     * @param prefix NameSpace prefix.
183     */
184    public void setNameSpacePrefix(String prefix) {
185        this.prefix = prefix;
186    }
187
188    /**
189     * Gets the name space prefix.
190     * @return String NameSpace prefix.
191     */
192    public java.lang.String getNameSpacePrefix() {
193        return prefix;
194    }
195
196    /**
197     * Creates a String representation of this object.
198     * By default name space name is prepended to the element name
199     * @return String A string containing the valid XML for this element
200     */
201    public java.lang.String toString() {
202        return toString(true, false);
203    }
204
205    /**
206     * Creates a String representation of this object.
207     * @param includeNS if true prepends all elements by their Namespace prefix
208     * @param declareNS if true includes the namespace within the
209     *                  generated.
210     * @return String A string containing the valid XML for this element
211     */
212    public java.lang.String toString(boolean includeNS, boolean declareNS) {
213
214        String tempPrefix = "";
215        if(includeNS) {
216           if(prefix == null) {
217              prefix = DSTConstants.DEFAULT_NS_PREFIX;
218           }
219           tempPrefix = prefix + ":";
220        }
221        if(declareNS)
222        { if(nameSpaceURI == null) {
223              DSTUtils.debug.error("DSTData.toString: Name Space is " +
224              "not defined");
225              return "";
226           }
227        }
228        StringBuffer sb = new StringBuffer(300);
229        sb.append("<").append(tempPrefix).append("Data");
230        if(id != null && id.length() != 0) {
231           sb.append(" id=\"").append(id).append("\"");
232        }
233        if(itemIDRef != null && itemIDRef.length() != 0) {
234           sb.append(" itemIDRef=\"").append(itemIDRef).append("\"");
235        }
236
237        if(declareNS) {
238           sb.append(" xmlns:").append(prefix).append("=\"")
239             .append(nameSpaceURI).append("\"")
240             .append(" xmlns=\"").append(nameSpaceURI).append("\"");
241        }
242        sb.append(">");
243
244        Iterator iter = dstData.iterator();
245        while(iter.hasNext()) {
246           Node node = (Node)iter.next();
247           sb.append(XMLUtils.print(node));
248        }
249        sb.append("</").append(tempPrefix).append("Data").append(">");
250        return sb.toString(); 
251    }
252
253}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.