axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Veithen <andreas.veit...@gmail.com>
Subject Re: Axiom Class cast exception on iterator of that class!
Date Sun, 11 Nov 2012 19:26:57 GMT
On Thu, Nov 8, 2012 at 11:49 PM, Brian Reinhold
<brianreinhold@lampreynetworks.com> wrote:
> Why does this code throw a java.lang.ClassCastException:
> org.apache.axiom.om.impl.llom.OMTextImpl cannot be cast to
> org.apache.axiom.om.OMElement
>
>
>
>              MessageContext msgContext = data.getInMessageContext();
>
>              SOAPHeader header = msgContext.getEnvelope().getHeader();
>
>              Iterator<OMElement> iter = header.getDescendants(false);
>
>              String user = "";
>
>              while(iter.hasNext())
>
>              {
>
>                  OMElement element = iter.next();
>
>                  if(element.getType() == OMNode.ELEMENT_NODE)
>
>                  {
>
>                      element = element.getFirstChildWithName(new
> QName(wsseNamespace, "Username"));
>
>                      if(element != null)
>
>                      {
>
>                          user = element.getText();
>
>                      }
>
>                  }
>
>              }
>
>
>
> The getDescendants() method of Axiom states that it returns an iterator over
> OMElements. Yet I get that class cast exception with no way to guard against
> it. Can someone explain how this can happen?
>

The Javadoc says this: "Get an iterator over all descendants of the
container. The items are returned in document order. Note that
attributes and namespace declarations are not considered descendants."
It doesn't restrict the result to elements.

>
> Thanks
>
>
>
> Brian

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
For additional commands, e-mail: java-dev-help@axis.apache.org


Mime
View raw message