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: InsertEntry.java,v 1.2 2008/06/25 05:47:10 qcheng Exp $
026 *
027 */
028
029
030package com.sun.identity.liberty.ws.disco;
031
032import java.util.Iterator;
033import java.util.List;
034import java.util.ArrayList;
035
036import org.w3c.dom.*;
037
038import com.sun.identity.liberty.ws.disco.common.DiscoConstants;
039import com.sun.identity.liberty.ws.disco.common.DiscoUtils;
040
041/**
042 * The class <code>InsertEntry</code> represents a Insert Entry for Discovery
043 * Modify request.
044 * <p>The following schema fragment specifies the expected content within the
045 * <code>InsertEntry</code> object.
046 * <p>
047 * <pre>
048 * &lt;xs:element name="InsertEntry" type="InsertEntryType">
049 * &lt;complexType name="InsertEntryType">
050 *   &lt;complexContent>
051 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
052 *       &lt;sequence>
053 *         &lt;element ref="{urn:liberty:disco:2003-08}ResourceOffering"/>
054 *         &lt;any/>
055 *       &lt;/sequence>
056 *     &lt;/restriction>
057 *   &lt;/complexContent>
058 * &lt;/complexType>
059 * </pre>
060 * 
061 * @supported.all.api
062 */
063public class InsertEntry {
064
065    private ResourceOffering offering = null;
066    private List any = null;
067
068    /**
069     * Constructor.
070     * @param resourceOffering discovery Resource offering to be inserted. 
071     * @param any List of Directive object, this is to allow the requester to
072     *     include directives about the resource offering being inserted.
073     */
074    public InsertEntry(
075        com.sun.identity.liberty.ws.disco.ResourceOffering resourceOffering,
076        java.util.List any)
077    {
078        offering = resourceOffering;
079        this.any = any;
080    }
081
082    /**
083     * Constructor.
084     * @param elem <code>InsertEntry</code> DOM element
085     * @exception DiscoveryException if error occurs
086     */
087    public InsertEntry(Element elem) throws DiscoveryException {
088        if (elem == null) {
089            DiscoUtils.debug.message("InsertEntry(Element): null input.");
090            throw new DiscoveryException(
091                DiscoUtils.bundle.getString("nullInput"));
092        }
093        String nodeName;
094        String nameSpaceURI;
095        if (((nodeName = elem.getLocalName()) == null) ||
096            (!nodeName.equals("InsertEntry")) ||
097            ((nameSpaceURI = elem.getNamespaceURI()) == null) ||
098            (!nameSpaceURI.equals(DiscoConstants.DISCO_NS)))
099        {
100            DiscoUtils.debug.message("InsertEntry(Element): wrong input");
101            throw new DiscoveryException(
102                DiscoUtils.bundle.getString("wrongInput"));
103        }
104
105        NodeList contentnl = elem.getChildNodes();
106        Node child;
107        for (int i = 0, length = contentnl.getLength(); i < length; i++) {
108            child = contentnl.item(i);
109            if ((nodeName = child.getLocalName()) != null) {
110                nameSpaceURI = ((Element) child).getNamespaceURI();
111                if ((nodeName.equals("ResourceOffering")) &&
112                    (nameSpaceURI != null) &&
113                    (nameSpaceURI.equals(DiscoConstants.DISCO_NS)))
114                {
115                    if (offering != null) {
116                        if (DiscoUtils.debug.messageEnabled()) {
117                            DiscoUtils.debug.message("InsertEntry(Element): "
118                                + "included more than one ResourceOffering.");
119                        }
120                        throw new DiscoveryException(
121                            DiscoUtils.bundle.getString("moreElement"));
122                    }
123                    offering = new ResourceOffering((Element) child);
124                } else {
125                    Directive directive = new Directive((Element) child);
126                    if (any == null) {
127                        any = new ArrayList();
128                    }
129                    any.add(directive);
130                }
131            }
132        }
133
134        if (offering == null) {
135            if (DiscoUtils.debug.messageEnabled()) {
136                DiscoUtils.debug.message("InsertEntry(Element): missing "
137                    + "ResourceOffering.");
138            }
139            throw new DiscoveryException(
140                DiscoUtils.bundle.getString("missingResourceOffering"));
141        }
142    }
143
144    /**
145     * Gets the resource offering to be inserted. 
146     *
147     * @return the resource offering to be inserted.
148     * @see #setResourceOffering(ResourceOffering)
149     */
150    public ResourceOffering getResourceOffering() {
151        return offering;
152    }
153
154    /**
155     * Sets the resource offering to be inserted. 
156     *
157     * @param value the resource offering to be inserted.
158     * @see #getResourceOffering()
159     */
160    public void setResourceOffering(ResourceOffering value) {
161        offering = value;
162    }
163
164    /**
165     * Gets the value of the Any property.
166     *
167     * @return List of <code>com.sun.identity.liberty.ws.disco.Directive</code>
168     *                objects.
169     * @see #setAny(List)
170     */
171    public List getAny() {
172        return any;
173    }
174
175    /**
176     * Sets the value of the Any property.
177     *
178     * @param any List of
179     *  <code>com.sun.identity.liberty.ws.disco.Directive</code> objects.
180     * @see #getAny()
181     */
182    public void setAny(List any) {
183        this.any = any;
184    }
185
186    /**
187     * Gets string format.
188     *
189     * @return formatted String.
190     */ 
191    public java.lang.String toString() {
192        StringBuffer sb = new StringBuffer(1000);
193        sb.append("<InsertEntry xmlns=\"").append(DiscoConstants.DISCO_NS).
194            append("\">");
195        if (offering != null) {
196            sb.append(offering);
197        }
198        if (any != null) {
199            Iterator iter = any.iterator();
200            while (iter.hasNext()) {
201                sb.append(iter.next().toString());
202            }
203        }
204        sb.append("</InsertEntry>");
205        return sb.toString();
206    }
207}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.