The role Attribute
A
DDING
A
TTRIBUTES
143
matches the specified actor. The first method,
examineHeaderElements
, returns
an iterator over all the elements that have the specified actor.
java.util.Iterator headerElements =
header.examineHeaderElements("http://gizmos.com/orders");
The second method,
extractHeaderElements
, not only returns an iterator over
all the
SOAPHeaderElement
objects that have the specified actor attribute but
also detaches them from the
SOAPHeader
object. So, for example, after the order
desk application did its work, it would call
extractHeaderElements
to remove
all the
SOAPHeaderElement
objects that applied to it.
java.util.Iterator headerElements =
header.extractHeaderElements("http://gizmos.com/orders");
Each
SOAPHeaderElement
object can have only one actor attribute, but the same
actor can be an attribute for multiple
SOAPHeaderElement
objects.
Two
additional
SOAPHeader
methods--
examineAllHeaderElements
and
extractAllHeaderElements
--allow you to examine or extract all the header
elements, whether or not they have an actor attribute. For example, you could use
the following code to display the values of all the header elements:
Iterator allHeaders =
header.examineAllHeaderElements();
while (allHeaders.hasNext()) {
SOAPHeaderElement headerElement =
(SOAPHeaderElement)allHeaders.next();
QName headerName =
headerElement.getElementQName();
System.out.println("\nHeader name is " +
headerName.toString());
System.out.println("Actor is " +
headerElement.getActor());
}
The role Attribute
The
role
attribute is the name used by the SOAP 1.2 specification for the SOAP
1.2
actor
attribute. The
SOAPHeaderElement
methods
setRole
and
getRole
perform the same functions as the
setActor
and
getActor
methods.