All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.xml.ws.message.AbstractHeaderImpl Maven / Gradle / Ivy

There is a newer version: 4.0.2
Show newest version
/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the License).  You may not use this file except in
 * compliance with the License.
 * 
 * You can obtain a copy of the license at
 * https://glassfish.dev.java.net/public/CDDLv1.0.html.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL
 * Header Notice in each file and include the License file
 * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * you own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 * 
 * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
 */

package com.sun.xml.ws.message;

import com.sun.istack.NotNull;
import com.sun.xml.bind.api.Bridge;
import com.sun.xml.bind.api.BridgeContext;
import com.sun.xml.ws.api.SOAPVersion;
import com.sun.xml.ws.api.addressing.AddressingVersion;
import com.sun.xml.ws.api.addressing.WSEndpointReference;
import com.sun.xml.ws.api.message.Header;
import com.sun.xml.ws.api.streaming.XMLStreamReaderFactory;
import org.xml.sax.helpers.AttributesImpl;

import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.util.Set;

/**
 * Partial default implementation of {@link Header}.
 *
 * 

* This is meant to be a convenient base class * for {@link Header}-derived classes. * * @author Kohsuke Kawaguchi */ public abstract class AbstractHeaderImpl implements Header { protected AbstractHeaderImpl() { } /** * @deprecated */ public final T readAsJAXB(Bridge bridge, BridgeContext context) throws JAXBException { return readAsJAXB(bridge); } public T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException { try { return (T)unmarshaller.unmarshal(readHeader()); } catch (Exception e) { throw new JAXBException(e); } } public T readAsJAXB(Bridge bridge) throws JAXBException { try { return bridge.unmarshal(readHeader()); } catch (XMLStreamException e) { throw new JAXBException(e); } } /** * Default implementation that copies the infoset. Not terribly efficient. */ public WSEndpointReference readAsEPR(AddressingVersion expected) throws XMLStreamException { XMLStreamReader xsr = readHeader(); WSEndpointReference epr = new WSEndpointReference(xsr, expected); XMLStreamReaderFactory.recycle(xsr); return epr; } public boolean isIgnorable(@NotNull SOAPVersion soapVersion, @NotNull Set roles) { // check mustUnderstand String v = getAttribute(soapVersion.nsUri, "mustUnderstand"); if(v==null || !parseBool(v)) return true; // now role return !roles.contains(getRole(soapVersion)); } public @NotNull String getRole(@NotNull SOAPVersion soapVersion) { String v = getAttribute(soapVersion.nsUri, soapVersion.roleAttributeName); if(v==null) v = soapVersion.implicitRole; return v; } public boolean isRelay() { String v = getAttribute(SOAPVersion.SOAP_12.nsUri,"relay"); if(v==null) return false; // on SOAP 1.1 message there shouldn't be such an attribute, so this works fine return parseBool(v); } public String getAttribute(QName name) { return getAttribute(name.getNamespaceURI(),name.getLocalPart()); } /** * Parses a string that looks like xs:boolean into boolean. * * This method assumes that the whilespace normalization has already taken place. */ protected final boolean parseBool(String value) { if(value.length()==0) return false; char ch = value.charAt(0); return ch=='t' || ch=='1'; } public String getStringContent() { try { XMLStreamReader xsr = readHeader(); xsr.nextTag(); return xsr.getElementText(); } catch (XMLStreamException e) { return null; } } protected static final AttributesImpl EMPTY_ATTS = new AttributesImpl(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy