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: ProcessingContextHeader.java,v 1.2 2008/06/25 05:47:22 qcheng Exp $
026 *
027 */
028
029
030package com.sun.identity.liberty.ws.soapbinding; 
031
032import org.w3c.dom.Document;
033import org.w3c.dom.Element;
034import com.sun.identity.saml.common.SAMLUtils;
035import com.sun.identity.shared.xml.XMLUtils;
036
037/**
038 * The <code>ProcessingContextHeader</code> class represents
039 * <code>ProcessingContext</code> element defined in SOAP binding schema.
040 * 
041 * @supported.all.api
042 */
043public class ProcessingContextHeader {   
044
045    private String elementValue = null;
046    private String id = null;
047    private Boolean mustUnderstand = null;
048    private String actor = null;
049
050    /**
051     * Constructor.
052     *
053     * @param elementValue the processing context header string.
054     * @throws SOAPBindingException if the elementValue is null
055     */
056    public ProcessingContextHeader(String elementValue) 
057                                   throws SOAPBindingException {
058        if (elementValue == null) {
059            String msg = Utils.bundle.getString("missingPCvalue");
060            Utils.debug.error("ProcessingContextHeader: " + msg);
061            throw new SOAPBindingException(msg);
062        }
063        this.elementValue = elementValue;
064    }
065
066    /**
067     * Constructor.
068     *
069     * @param processingContextElement a ProcessingContext element
070     * @throws SOAPBindingException if an error occurs while parsing
071     *                                 the ProcessingContext element
072     */
073    ProcessingContextHeader(Element processingContextElement)
074                            throws SOAPBindingException {
075        elementValue = XMLUtils.getElementValue(processingContextElement);
076        if (elementValue == null) {
077            String msg = Utils.bundle.getString("missingPCvalue");
078            Utils.debug.error("ProcessingContextHeader: " + msg);
079            throw new SOAPBindingException(msg);
080        }
081        if (elementValue == null) {
082            String msg = Utils.bundle.getString("missingPCvalue");
083            Utils.debug.error("ProcessingContextHeader: " + msg);
084            throw new SOAPBindingException(msg);
085        }
086        id = XMLUtils.getNodeAttributeValue(processingContextElement,
087                SOAPBindingConstants.ATTR_id);
088        String str = XMLUtils.getNodeAttributeValueNS(
089                processingContextElement,
090                SOAPBindingConstants.NS_SOAP,
091                SOAPBindingConstants.ATTR_MUSTUNDERSTAND);
092        if (str != null && str.length() > 0) {
093            try {
094                mustUnderstand = Utils.StringToBoolean(str);
095            } catch (Exception pe) {
096                String msg = Utils.bundle.getString("invalidMustUnderstand");
097                Utils.debug.error("ProcessingContextHeader: " + msg, pe);
098                throw new SOAPBindingException(msg);
099            }
100        }
101        
102        actor = XMLUtils.getNodeAttributeValueNS(
103                processingContextElement,
104                SOAPBindingConstants.NS_SOAP,
105                SOAPBindingConstants.ATTR_ACTOR);
106    }
107
108    /**
109     * Returns value of <code>ProcessingContext</code> element.
110     *
111     * @return value of <code>ProcessingContext</code> element.
112     */
113    public String getElementValue() {
114        return elementValue;
115    }
116
117    /**
118     * Returns value of <code>id</code> attribute.
119     *
120     * @return value of <code>id</code> attribute
121     */
122    public String getId() {
123        return id;
124    }
125
126    /**
127     * Returns value of 'mustUnderstand' attribute.
128     *
129     * @return value of 'mustUnderstand' attribute
130     */
131    public Boolean getMustUnderstand() {
132        return mustUnderstand;
133    }
134
135    /**
136     * Returns value of <code>actor</code> attribute.
137     *
138     * @return value of <code>actor</code> attribute
139     */
140    public String getActor() {
141        return actor;
142    }
143
144    /**
145     * Sets value of <code>ProcessingContex</code> element if it is not null.
146     *
147     * @param elementValue value of <code>ProcessingContext</code> element
148     */
149    public void setElementValue(String elementValue) {
150        if (elementValue != null) {
151            this.elementValue = elementValue;
152        }
153    }
154
155    /**
156     * Sets value of <code>mustUnderstand</code> attribute.
157     *
158     * @param mustUnderstand value of <code>mustUnderstand</code> attribute
159     */
160    public void setMustUnderstand(Boolean mustUnderstand) {
161        this.mustUnderstand = mustUnderstand;
162    }
163
164    /**
165     * Sets value of <code>actor</code> attribute.
166     *
167     * @param actor value of <code>actor</code> attribute
168     */
169    public void setActor(String actor) {
170        this.actor = actor;
171    }
172
173    /**
174     * Sets the sign flag. If the value is set to true then the header
175     * will be signed.
176     *
177     * @param signFlag the value of the sign flag.
178     */
179    public void setSignFlag(boolean signFlag) {
180        if (signFlag) {
181            id = SAMLUtils.generateID();
182        } else {
183            id = null;
184        }
185    }
186
187    /**
188     * Converts this header to <code>org.w3c.dom.Element</code> and add to
189     * parent Header Element.
190     *
191     * @param headerE parent Header Element
192     */
193    void addToParent(Element headerE) {
194        Document doc = headerE.getOwnerDocument();
195        Element processingContextHeaderE = doc.createElementNS(
196                SOAPBindingConstants.NS_SOAP_BINDING,
197                SOAPBindingConstants.PTAG_PROCESSING_CONTEXT);
198        headerE.appendChild(processingContextHeaderE);
199        
200        processingContextHeaderE.appendChild(doc.createTextNode(elementValue));
201        if (id != null) {
202            processingContextHeaderE.setAttributeNS(null,
203                    SOAPBindingConstants.ATTR_id, id);
204        }
205        if (mustUnderstand != null) {
206            processingContextHeaderE.setAttributeNS(
207                    SOAPBindingConstants.NS_SOAP,
208                    SOAPBindingConstants.PATTR_MUSTUNDERSTAND,
209                    Utils.BooleanToString(mustUnderstand));
210        }
211        if (actor != null) {
212            processingContextHeaderE.setAttributeNS(
213                    SOAPBindingConstants.NS_SOAP,
214                    SOAPBindingConstants.PATTR_ACTOR,
215                    actor);
216        }
217    }
218}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.