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: DSTModify.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 com.sun.identity.liberty.ws.disco.EncryptedResourceID;
033import java.util.List;
034import java.util.ArrayList;
035import java.util.Iterator;
036import org.w3c.dom.NodeList;
037import org.w3c.dom.Node;
038import org.w3c.dom.Element;
039import com.sun.identity.shared.xml.XMLUtils;
040
041/**
042 * The <code>DSTModify</code> class represents a <code>DST</code> modify
043 * request.
044 * 
045 * The following schema fragment specifies the expected content within
046 * the <code>DSTModify</code> object.
047 * 
048 * <pre>
049 * &lt;complexType name="ModifyType">
050 *   &lt;complexContent>
051 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
052 *       &lt;sequence>
053 *         &lt;group ref="{urn:liberty:idpp:2003-08}ResourceIDGroup"/>
054 *         &lt;element name="Modification" maxOccurs="unbounded">
055 *           &lt;complexType>
056 *             &lt;complexContent>
057 *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}
058 *                anyType">
059 *                 &lt;sequence>
060 *                   &lt;element name="Select"
061 *                   type="{urn:liberty:idpp:2003-08}SelectType"/>
062 *                   &lt;element name="NewData" minOccurs="0">
063 *                     &lt;complexType>
064 *                       &lt;complexContent>
065 *                         &lt;restriction 
066 *                         base="{http://www.w3.org/2001/XMLSchema}anyType">
067 *                           &lt;sequence>
068 *                           &lt;any/>
069 *                           &lt;/sequence>
070 *                         &lt;/restriction>
071 *                       &lt;/complexContent>
072 *                     &lt;/complexType>
073 *                   &lt;/element>
074 *                 &lt;/sequence>
075 *                 &lt;attribute name="overrideAllowed"
076 *                 type="{http://www.w3.org/2001/XMLSchema}boolean" />
077 *                 &lt;attribute name="id"
078 *                 type="{http://www.w3.org/2001/XMLSchema}ID" />
079 *               &lt;/restriction>
080 *             &lt;/complexContent>
081 *           &lt;/complexType>
082 *         &lt;/element>
083 *         &lt;element ref="{urn:liberty:idpp:2003-08}Extension"
084 *         maxOccurs="unbounded" minOccurs="0"/>
085 *       &lt;/sequence>
086 *       &lt;attribute name="id" type="{http://www.w3.org/2001/XMLSchema}ID" />
087 *       &lt;attribute name="itemID" type="{urn:liberty:idpp:2003-08}IDType" />
088 *     &lt;/restriction>
089 *   &lt;/complexContent>
090 * &lt;/complexType>
091 * </pre>
092 * 
093 * @supported.all.api
094 */
095public class DSTModify {
096
097    private String resourceID;
098    private EncryptedResourceID encryptedResourceID;
099    private List modification = new ArrayList();
100    private String itemID;
101    private String id;
102    private List extension = new ArrayList();
103    private String nameSpaceURI = null;
104    private String prefix = null;
105
106    /**
107     * Constructor
108     */
109    public DSTModify() {}
110
111    /**
112     * Constructor
113     * @param resourceID id for the resource to be modified. 
114     * @param modifications list of <code>DSTModification</code> to be
115     *        performed. 
116     * @param serviceNS service name space.
117     */
118    public DSTModify(String resourceID, 
119                     java.util.List modifications,
120                     String serviceNS) {
121        this.resourceID = resourceID;
122        if(modifications != null) {
123           modification.addAll(modifications);
124           DSTModification dm = (DSTModification)modifications.get(0);
125           if(serviceNS == null) {
126              nameSpaceURI = dm.getNameSpaceURI();
127           } else {
128              nameSpaceURI = serviceNS;
129           }
130           prefix = dm.getNameSpacePrefix();
131        }
132    }
133
134    /**
135     * Constructor
136     * @param encResourceID id for encrypted resource to be modified.
137     * @param modifications list of <code>DSTModification</code> to be
138     *        performed.
139     * @param serviceNS service name space.
140     */
141    public DSTModify(
142           com.sun.identity.liberty.ws.disco.EncryptedResourceID encResourceID, 
143           java.util.List modifications,
144           String serviceNS) {
145        this.encryptedResourceID = encResourceID;
146        if(modifications != null) {
147           modification.addAll(modifications);
148           DSTModification dm = (DSTModification)modifications.get(0);
149           if(serviceNS == null) {
150              nameSpaceURI = dm.getNameSpaceURI();
151           } else {
152              nameSpaceURI = serviceNS;
153           }
154           prefix = dm.getNameSpacePrefix();
155        }
156    }
157
158    /**
159     * Constructor
160     * @param element <code>DOM</code> Element.
161     * @exception DSTException
162     */
163    public DSTModify(org.w3c.dom.Element element) throws DSTException{
164        if(element == null) {
165           DSTUtils.debug.error("DSTModify(element):null input");
166           throw new DSTException(DSTUtils.bundle.getString("nullInputParams"));
167        }
168        String elementName = element.getLocalName();
169        if(elementName == null || !elementName.equals("Modify")) {
170           DSTUtils.debug.error("DSTModify(element):Invalid element name");
171           throw new DSTException(DSTUtils.bundle.getString("invalidElement"));
172        }
173        nameSpaceURI = element.getNamespaceURI();
174        if(nameSpaceURI == null) {
175           DSTUtils.debug.error("DSTModify(element): NameSpace is not defined");
176           throw new DSTException(DSTUtils.bundle.getString("noNameSpace"));
177        }
178        prefix = element.getPrefix();
179        id = element.getAttribute("id");
180        itemID = element.getAttribute("itemID");
181        
182        NodeList list = element.getElementsByTagNameNS(
183                        nameSpaceURI, "ResourceID");
184
185        if((list.getLength() == 0) || (list.getLength() > 1)) { 
186           DSTUtils.debug.error("DSTModify(element): ResourceIDNode is null" +
187           " or more than one resource id is found.");
188           throw new DSTException(
189           DSTUtils.bundle.getString("invalidResourceID"));
190        }
191        resourceID = XMLUtils.getElementValue((Element)list.item(0));
192        if(resourceID == null) {
193           DSTUtils.debug.error("DSTModify(element): ResourceID is null" );
194           throw new DSTException(
195           DSTUtils.bundle.getString("invalidResourceID"));
196        }
197
198        NodeList modificationNodes = element.getElementsByTagNameNS(
199                 nameSpaceURI, "Modification"); 
200        if(modificationNodes == null || modificationNodes.getLength() == 0) {
201           DSTUtils.debug.error("DSTModify(element): Modifications are null" );
202           throw new DSTException(
203           DSTUtils.bundle.getString("nullModifications"));
204        }
205        int size = modificationNodes.getLength();
206        for(int i=0; i < size; i++) {
207            Node node = modificationNodes.item(0);
208            DSTModification dstModification = 
209                     new DSTModification((Element)node);
210            modification.add(dstModification);
211        }
212    }
213
214
215    /**
216     * Gets the modifications to be performed.
217     * 
218     * @return List of <code>DSTModification</code> object
219     * 
220     */
221    public java.util.List getModification() {
222        return modification;
223    }
224
225    /**
226     * Gets id attribute 
227     * @return 
228     * {@link java.lang.String}
229     */
230    public java.lang.String getId() {
231        return id;
232    }
233
234    /**
235     * Sets id attribute 
236     * @param id id attribute value to be set 
237     */
238    public void setId(java.lang.String id) {
239        this.id = id;
240    }
241
242    /**
243     * Gets the encrypted resource ID.
244     * @return encrypted resource ID.
245     */
246    public com.sun.identity.liberty.ws.disco.EncryptedResourceID 
247    getEncryptedResourceID() {
248        return encryptedResourceID;
249    }
250
251    /**
252     * Sets encrypted resource ID 
253     * @param resourceID encrypted resource ID to be set
254     */
255    public void setEncryptedResourceID(
256     com.sun.identity.liberty.ws.disco.EncryptedResourceID resourceID) {
257        this.encryptedResourceID = resourceID;
258    }
259
260    /**
261     * Gets resource ID 
262     * @return
263     * {@link java.lang.String}
264     */
265    public java.lang.String getResourceID() {
266        return resourceID;
267    }
268
269    /**
270     * Sets the resource ID 
271     * @param resourceID  resource ID to be set
272     */
273    public void setResourceID(String resourceID) {
274        this.resourceID = resourceID;
275    }
276
277    /**
278     * Gets item id attribute 
279     * @return 
280     * {@link java.lang.String}
281     */
282    public java.lang.String getItemID() {
283        return itemID;
284    }
285
286    /**
287     * Sets item id attribute 
288     * @param itemID item ID to be set
289     */
290    public void setItemID(java.lang.String itemID) {
291        this.itemID = itemID;
292    }
293
294    /**
295     * Gets the extension property 
296     * 
297     * @return List of Object
298     * 
299     */
300    public java.util.List getExtension() {
301        return extension;
302    }
303
304    /**
305     * Sets the extension property 
306     *
307     * @param extensions List of Object to be set
308     *
309     */
310    public void setExtension(java.util.List extensions) {
311        if(extensions != null) {
312           extension.addAll(extensions);
313        }
314    }
315
316    /**
317     * Gets the name space.
318     *
319     * @return name space.
320     */
321    public java.lang.String getNameSpaceURI() {
322        return nameSpaceURI;
323    }
324
325    /**
326     * Sets the name space.
327     * @param nameSpace name space URI.
328     */
329    public void setNameSpaceURI(String nameSpace) {
330        this.nameSpaceURI = nameSpace;
331    }
332
333    /**
334     * Sets the name space prefix.
335     * @param prefix name space prefix.
336     */
337    public void setNameSpacePrefix(String prefix) {
338        this.prefix = prefix;
339    }
340
341    /**
342     * Gets the name space prefix.
343     * @return Name space prefix.
344     */
345    public java.lang.String getNameSpacePrefix() {
346        return prefix;
347    }
348
349    /**
350     * Creates a String representation of this object.
351     * By default name space name is prepended to the element name
352     * @return String A string containing the valid XML for this element
353     */
354    public java.lang.String toString() {
355        return toString(true, false);
356    }
357
358    /**
359     * Creates a String representation of this object.
360     * @param includeNS if true prepends all elements by their name space prefix
361     * @param declareNS if true includes the name space within the
362     *                  generated.
363     * @return String A string containing the valid XML for this element
364     */
365    public java.lang.String toString(boolean includeNS, boolean declareNS) {
366
367        String tempPrefix = "";
368        if(includeNS) {
369           if(prefix == null) {
370              prefix = DSTConstants.DEFAULT_NS_PREFIX;
371           }
372           tempPrefix = prefix + ":";
373        }
374        if(declareNS) {
375           if(nameSpaceURI == null) {
376              DSTUtils.debug.error("DSTModify.toString: Name Space is " +
377              "not defined");
378              return "";
379           }
380        }
381        StringBuffer sb = new StringBuffer(300);
382        sb.append("<").append(tempPrefix).append("Modify");
383        if(id != null && id.length() != 0) {
384           sb.append(" id=\"").append(id).append("\"");
385        }
386        if(itemID != null && itemID.length() != 0) {
387           sb.append(" itemID=\"").append(itemID).append("\"");
388        }
389        if(declareNS) {
390           sb.append(" xmlns:").append(prefix).append("=\"")
391             .append(nameSpaceURI).append("\"")
392             .append(" xmlns=\"").append(nameSpaceURI).append("\"");
393        }
394        sb.append(">");
395        if(encryptedResourceID == null) {
396           sb.append("<").append(tempPrefix).append("ResourceID").append(">")
397             .append(resourceID).append("</").append(tempPrefix)
398             .append("ResourceID").append(">");
399        } else {
400           sb.append(encryptedResourceID.toString(nameSpaceURI));
401        }
402
403        Iterator iter = modification.iterator();
404        while(iter.hasNext()) {
405            DSTModification modification = (DSTModification)iter.next();
406            sb.append(modification.toString());
407        }
408        sb.append("</").append(tempPrefix).append("Modify").append(">");
409        if(DSTUtils.debug.messageEnabled()) {
410           DSTUtils.debug.message("DSTModify.toString: " + sb.toString());
411        }
412        return sb.toString(); 
413    }
414
415}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.