FileDocCategorySizeDatePackage
SOAPHeaderElement.javaAPI DocApache Axis 1.410413Sat Apr 22 18:57:28 BST 2006org.apache.axis.message

SOAPHeaderElement

public class SOAPHeaderElement extends MessageElement implements SOAPHeaderElement
A simple header element abstraction. Extends MessageElement with header-specific stuff like mustUnderstand, actor, and a 'processed' flag.
author
Glen Daniels (gdaniels@apache.org)
author
Glyn Normington (glyn@apache.org)

Fields Summary
protected boolean
processed
protected String
actor
protected boolean
mustUnderstand
protected boolean
relay
boolean
alreadySerialized
Constructors Summary
public SOAPHeaderElement(String namespace, String localPart)


         
    
        super(namespace, localPart);
    
public SOAPHeaderElement(Name name)

        super(name);
    
public SOAPHeaderElement(QName qname)

        super(qname);
    
public SOAPHeaderElement(String namespace, String localPart, Object value)

        super(namespace, localPart, value);
    
public SOAPHeaderElement(QName qname, Object value)

        super(qname, value);
    
public SOAPHeaderElement(Element elem)

        super(elem);

        // FIXME : This needs to come from someplace reasonable, perhaps
        // TLS (SOAPConstants.getCurrentVersion() ?)
        SOAPConstants soapConstants = getSOAPConstants();

        String val = elem.getAttributeNS(soapConstants.getEnvelopeURI(),
                                         Constants.ATTR_MUST_UNDERSTAND);

        try {
            setMustUnderstandFromString(val, (soapConstants == 
                                              SOAPConstants.SOAP12_CONSTANTS));
        } catch (AxisFault axisFault) {
            // Log the bad MU value, since this constructor can't throw
            log.error(axisFault);
        }

        QName roleQName = soapConstants.getRoleAttributeQName();
        actor = elem.getAttributeNS(roleQName.getNamespaceURI(),
                                    roleQName.getLocalPart());
//        if (actor == null) {
//            actor = "";
//        }
        
        if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
            String relayVal = elem.getAttributeNS(soapConstants.getEnvelopeURI(),
                                                  Constants.ATTR_RELAY);
            relay = ((relayVal != null) && (relayVal.equals("true") || relayVal.equals("1"))) ? true : false;
        }
    
public SOAPHeaderElement(String namespace, String localPart, String prefix, Attributes attributes, org.apache.axis.encoding.DeserializationContext context)

        super(namespace, localPart, prefix, attributes, context);

        SOAPConstants soapConstants = getSOAPConstants();

        // Check for mustUnderstand
        String val = attributes.getValue(soapConstants.getEnvelopeURI(),
                                         Constants.ATTR_MUST_UNDERSTAND);

        setMustUnderstandFromString(val, (soapConstants == 
                                          SOAPConstants.SOAP12_CONSTANTS));

        QName roleQName = soapConstants.getRoleAttributeQName();
        actor = attributes.getValue(roleQName.getNamespaceURI(),
                                    roleQName.getLocalPart());
//        if (actor == null) {
//            actor = "";
//        }

        if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
            String relayVal = attributes.getValue(soapConstants.getEnvelopeURI(),
                                                  Constants.ATTR_RELAY);
            relay = ((relayVal != null) && (relayVal.equals("true") || relayVal.equals("1"))) ? true : false;
        }

        processed = false;
        alreadySerialized = true;
    
Methods Summary
public java.lang.StringgetActor()

 return( actor ); 
public org.w3c.dom.NamedNodeMapgetAttributes()

        makeAttributesEditable();
        SOAPConstants soapConstants = getSOAPConstants();
        String mustUnderstand = attributes.getValue(soapConstants.getEnvelopeURI(),
                                         Constants.ATTR_MUST_UNDERSTAND);
        QName roleQName = soapConstants.getRoleAttributeQName();
        String actor = attributes.getValue(roleQName.getNamespaceURI(),roleQName.getLocalPart());
        
        if(mustUnderstand == null){
            if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                setAttributeNS(soapConstants.getEnvelopeURI(), 
                            Constants.ATTR_MUST_UNDERSTAND,"false");
            } else {
                setAttributeNS(soapConstants.getEnvelopeURI(), 
                            Constants.ATTR_MUST_UNDERSTAND,"0");
            }
        }
        if(actor == null){
            setAttributeNS(roleQName.getNamespaceURI(),
                         roleQName.getLocalPart(), this.actor);
        }
        return super.getAttributes();
    
public booleangetMustUnderstand()

 return( mustUnderstand ); 
public booleangetRelay()

        return relay;
    
public java.lang.StringgetRole()

 return( actor ); 
private org.apache.axis.soap.SOAPConstantsgetSOAPConstants()

        SOAPConstants soapConstants = null;
        if (context != null) {
            return context.getSOAPConstants();
        }
        if (getNamespaceURI() != null &&
                getNamespaceURI().equals(SOAPConstants.SOAP12_CONSTANTS.getEnvelopeURI())) {
            soapConstants = SOAPConstants.SOAP12_CONSTANTS;
        }
        if (soapConstants == null && getEnvelope() != null) {
            soapConstants = getEnvelope().getSOAPConstants();
        }
        if (soapConstants == null) {
            soapConstants = SOAPConstants.SOAP11_CONSTANTS;
        }
        return soapConstants;
    
public booleanisProcessed()

        return( processed );
    
protected voidoutputImpl(org.apache.axis.encoding.SerializationContext context)
Subclasses can override


            
          
        if (!alreadySerialized) {
            SOAPConstants soapVer = getSOAPConstants();
            QName roleQName = soapVer.getRoleAttributeQName();

            if (actor != null) {
                setAttribute(roleQName.getNamespaceURI(),
                             roleQName.getLocalPart(), actor);
            }
            
            String val;
            if (context.getMessageContext() != null && context.getMessageContext().getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS)
                val = mustUnderstand ? "true" : "false";
            else
                val = mustUnderstand ? "1" : "0";

            setAttribute(soapVer.getEnvelopeURI(),
                         Constants.ATTR_MUST_UNDERSTAND,
                         val);
            
            if (soapVer == SOAPConstants.SOAP12_CONSTANTS && relay) {
                setAttribute(soapVer.getEnvelopeURI(), Constants.ATTR_RELAY,
                             "true");
            }
        }

        super.outputImpl(context);
    
public voidsetActor(java.lang.String a)

        actor = a ;
    
public voidsetMustUnderstand(boolean b)

        mustUnderstand = b ;
    
private voidsetMustUnderstandFromString(java.lang.String val, boolean isSOAP12)

        if (val != null && val.length() > 0) {
            if ("0".equals(val)) {
                mustUnderstand = false;
            } else if ("1".equals(val)) {
                mustUnderstand = true;
            } else if (isSOAP12) {
                if ("true".equalsIgnoreCase(val)) {
                    mustUnderstand = true;
                } else if ("false".equalsIgnoreCase(val)) {
                    mustUnderstand = false;
                } else {
                    throw new AxisFault(
                            Messages.getMessage("badMUVal",
                                                val,
                                                new QName(namespaceURI,
                                                          name).toString()));
                }
            } else {
                throw new AxisFault(
                        Messages.getMessage("badMUVal",
                                            val,
                                            new QName(namespaceURI,
                                                      name).toString()));
            }
        }
    
public voidsetParentElement(javax.xml.soap.SOAPElement parent)

        if(parent == null) {
            throw new IllegalArgumentException(Messages.getMessage("nullParent00"));
        }
        // migration aid
        if (parent instanceof SOAPEnvelope) {
            log.warn(Messages.getMessage("bodyHeaderParent"));
            parent = ((SOAPEnvelope)parent).getHeader();
        }
        if (!(parent instanceof SOAPHeader)) {
            throw new IllegalArgumentException(Messages.getMessage("illegalArgumentException00"));
        }

        super.setParentElement(parent);
    
public voidsetProcessed(boolean value)

        processed = value ;
    
public voidsetRelay(boolean relay)

        this.relay = relay;
    
public voidsetRole(java.lang.String a)

        actor = a ;