OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   RE: [xml-dev] Error in a Class Cast

[ Lists Home | Date Index | Thread Index ]

Title: Message
Hi Joao,
the error message tells you everything you need to know: your Document is not a com.sun.tree.xml.Document, but one from the apache crimson project. The Crimson parser is a further development of the older Sun parser. You will find most of the methods in the Crimson parser, that were also in the Sun parser.
But why do you want to do this? Normally you should not work on the specific implementation classes, but on the general interfaces!
Best regards,
-----Original Message-----
From: Joćo Sarraipa [mailto:jfss@uninova.pt]
Sent: Mittwoch, 12. Juni 2002 18:35
To: xml-dev@lists.xml.org
Subject: [xml-dev] Error in a Class Cast

I have the following exception....
exception java.lang.ClassCastException: org.apache.crimson.tree.XmlDocument
when I try make A class cast from org.w3c.dom.Document to com.sun.tree.xml.XmlDocument
The code:
private DocumentBuilderFactory m_documentBuilderFactory = DocumentBuilderFactory.newInstance();
  /** */
  private DocumentBuilder m_documentBuilder;
    try {
      m_documentBuilder = m_documentBuilderFactory.newDocumentBuilder();
    } catch (Exception e) {
      throw new RuntimeException(e.getMessage());
    Document returnDoc = null;
    Node tempNode =  msg.getContent();
    tempNode = FIPA.ACL.Util.getNode(tempNode, FIPAConstants.Apply);
    if (FIPAConstants.Action.equals(tempNode.getFirstChild().getNodeName())) {
      tempNode = FIPA.ACL.Util.getNode(tempNode, FIPAConstants.Apply);
      // checks whether it is really a forward action ...
      String messageType = tempNode.getFirstChild().getFirstChild().getFirstChild().getNodeValue();
      if (messageType.indexOf(FIPAConstants.Forward) >= 0 ) {
        tempNode = Util.getNode(tempNode, FIPAConstants.Message );
        if (tempNode == null) {
          System.out.println("ACC: message content is null !!");
        returnDoc = m_documentBuilder.newDocument();
        try {
          Node copy = tempNode.cloneNode(true);
          com.sun.xml.tree.XmlDocument xmlD=(com.sun.xml.tree.XmlDocument) returnDoc;    ***********Localization of ERROR **************
          returnDoc.appendChild(copy); //aha
        } catch (Exception e) {
          System.out.print("ACC: caught exception "+e.toString()+"\n");
          e.printStackTrace() ;
Can you help me?
Thanks in advanced.
Joćo Sarraipa


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS