[jdom-interest] IllegalAccessError : how to pass Element to constructor

James Sinnamon sinnamon at usq.edu.au
Tue Feb 27 20:58:10 PST 2001


Philip,

Thanks for your help.

Firstly, the problem seems to have
gone away, but I don't know for how long, and not
knowing why is rather unsettling.

If the proble doesn't come back, I won't complain, however
if you have any thoughts about what might have caused
the problem (see code below) or if you could tell me if you think
that I am on the right track,  I would be very grateful.

Philip Nelson wrote:

>
>
> -----Original Message-----
> From: James Sinnamon
> To: GB/DEV - Philip Nelson
> Sent: 2/27/01 8:59 PM
> Subject: jdom-user list problems
>
> Philip,
>
> >Can you please help me?
> Maybe ;^)
>
> >A  messsage, I sent about 30
> >minutes
> >ago (see below), does not seem to have got there.
> >
> >Do you know of any reason, why this might be the case?
>
> No, it seems to run on a schedule rather than immediate delivery.
>

30 minutes seems like an eternity, when one is stuck on a difficult
problem, like this.  I hope that this may change.

>
> >Secondly, are you able to help me with the query in my e-mail?
>
> I think I would need to see the actual code.  That error appears to be in
> your class, not something to do with the JDOM element

The code, in which the constructors, are located ,is:

-------------------------------------------
package org.multipi;
import org.jdom.Element;

public class Interactor {
 Element initState;
  public Interactor (Element initSt) {
    initState =  initSt;
  }
}// Interactor
-----------------------------------------------
package org.multipi;

import org.jdom.Element;

public class Interaction {
  Element InitState;
  Interaction(Element initSt) {
    InitState = initSt;
  }
}// Interaction
-------------------------------------------------

... and the program, from which I call the constructors is:

-----------------------------------------

package org.multipi;
import java.util.Iterator;
import java.util.List;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.jdom.Attribute;
import org.jdom.Comment;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.adapters.DOMAdapter;
import org.jdom.input.DOMBuilder;
import org.jdom.output.XMLOutputter;

public class Team {

  /** Default DOM Adapter class to use */
  private static final String DEFAULT_DOM_ADAPTER_CLASS =
  "org.jdom.adapters.XercesDOMAdapter";

  /** DOM Adapter Class to use */
  private String domAdapterClass;

  private DOMBuilder builder;

  public Team(String domAdapterClass) {
    this.domAdapterClass = domAdapterClass;
    builder = new DOMBuilder(domAdapterClass);
  }

  public void testBuilder(String filename, OutputStream out)
  throws IOException, JDOMException {

    //build a DOM tree with the specified or default parser
    DOMAdapter domAdapter;
    FileInputStream in = new FileInputStream(filename);
    try {
      Class parserClass = Class.forName(domAdapterClass);
      domAdapter = (DOMAdapter)parserClass.newInstance();
    } catch (ClassNotFoundException e) {
      throw new JDOMException("Parser class " + domAdapterClass +
      " not found");
    } catch (Exception e) {
      throw new JDOMException("Parser class " + domAdapterClass +
      " instantiation error");
    }


    // Build the JDOM Document - validating is off by default for this
example
    // because of the document root issue
    org.w3c.dom.Document w3cdoc =
    domAdapter.getDocument((InputStream)in, false);
    Document doc = builder.build(w3cdoc);
    Element rootElmt = doc.getRootElement();
    List processList = rootElmt.getChildren();
    Iterator i = processList.iterator();
    System.out.println("here");
    while(i.hasNext()) {
      Object o = i.next();
      Interactor iactor = new Interactor((Element) o);
    }
    System.out.println("there");
  }

  /**
  * <p>
  * This provides a static entry point for creating a JDOM
  *   <code>{@link Document}</code> object using a DOM
  *   tree.
  * </p>
  *
  * @param args <code>String[]</code>
  *        <ul>
  *         <li>First argument: filename of XML document to parse</li>
  *         <li>Second argument: optional name of DOM Adapter class</li>
  *        </ul>
  */
  public static void main(String[] args) {
    if ((args.length < 1) || (args.length > 2)) {
      System.out.println("Usage: java org.jdom.examples.io.DOMBuilderTest "
+
      "[XML document filename] ([DOM Adapter Class])");
      System.exit(-1);
    }

    // Load filename and SAX driver class
    String filename = args[0];
    String domAdapterClass = DEFAULT_DOM_ADAPTER_CLASS;
    if (args.length == 2) {
      domAdapterClass = args[1];
    }

    // Create an instance of the tester and test
    try {
      Team demo = new Team(domAdapterClass);
      demo.testBuilder(filename, System.out);
    } catch (JDOMException e) {
      if (e.getRootCause() != null) {
        e.getRootCause().printStackTrace();
      } else {
        e.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
------------------------------------------------------

 Thanks again,

James

--
James Sinnamon  sinnamon at usq.edu.au

ph +61 7 46311490, +61 412 319669
PO Box 517 Darling Heights QLD 4350








More information about the jdom-interest mailing list