[jdom-interest] jdom2 migration issue

Craig Christophersen craigch at synesis7.com
Mon Aug 20 13:00:16 PDT 2012


This is very peculiar.  That line now compiles.
But further down in the class is another method using  "document" that will not(with the same type mismatch error).
The line " Element root = document.getRootElement();” errors.
Method:
  public String getWPNum() throws JDOMException { 
        String wpNum = "";
            Element root = document.getRootElement();
            Element idstatus = (Element)root.getChild("idstatus");
            Element status = (Element)idstatus.getChild("status");
            Element remarks = (Element)status.getChild("remarks");
            wpNum = remarks.getText();
            if(wpNum.equals("")) {
               wpNum = "0"; 
            }
            System.out.println("WPNum in Read DM: " + wpNum);
                    
        return wpNum;
    }

-----Original Message-----
From: Rolf Lear [mailto:jdom at tuis.net] 
Sent: Monday, August 20, 2012 1:02 PM
To: Craig Christophersen
Cc: Jdom interest
Subject: RE: [jdom-interest] jdom2 migration issue


Right, then the next thing to do is to worry about the protected variable 'document'.

In your code you have protected org.jdom2.Document document;

I had assumed that this was the same variable as the one in the line:

    document = builder.build(dmFile);

But, now I am not so sure.... perhaps in this case the document in the build line is some other document variable with the same name from a super class or something.

So, what happens if you replace the build line:

    document = builder.build(dmFile);

with:

    final org.jdom2.Document mydoc = builder.build(dmFile);
    document = mydoc;

Rolf


On Mon, 20 Aug 2012 12:51:33 -0600, "Craig Christophersen"
<craigch at synesis7.com> wrote:
> In the open type window it does show another project in eclipse with 
> "org.jdom.Document".  But it is another project that I will migrate 
> also once I get it working in this project.  The other project is not
referenced
> by the current project.
> 
> There are 8 classes in the project that use jdom.  Below is a typical
> import:
> 
> import java.io.*;
> import java.util.*;
> import java.util.regex.Pattern;
> 
> import org.jdom2.*;
> import org.jdom2.filter.ElementFilter; import 
> org.jdom2.input.SAXBuilder;
> 
> And another class imports:
> 
> import java.io.*;
> import java.util.*;
> import java.io.File.*;
> import java.io.IOException;
> import java.util.concurrent.ConcurrentLinkedQueue;
> 
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.parsers.ParserConfigurationException;
> 
> import org.jaxen.JaxenException;
> 
> import org.jdom2.output.*;
> import org.jdom2.*;
> import org.jdom2.filter.ElementFilter; import 
> org.jdom2.filter.ContentFilter; import org.jdom2.input.*; import 
> org.jdom2.xpath.*;
> 
> -----Original Message-----
> From: Rolf Lear [mailto:jdom at tuis.net]
> Sent: Monday, August 20, 2012 12:25 PM
> To: Craig Christophersen; Jdom interest
> Subject: RE: [jdom-interest] jdom2 migration issue
> 
> 
> In eclipse, edit your file, then type shift-ctrl-T Then type 
> org.jdom.Document
> 
> In the box below, you have all the locations of jdom 1.x Documents.
> 
> As a double-check, can you copy/paste the entire import section in 
> your class.... I am convinced there must be an import from org.jdom.* 
> or something.
> 
> P.S. when you reply, do a reply-all, and I will get your answer 
> faster.....
> 
> Rolf
> 
> 
> On Mon, 20 Aug 2012 12:18:29 -0600, "Craig Christophersen"
> <craigch at synesis7.com> wrote:
>> Hello Rolf; Thank you for your reply.  I have again looked thru stuff
> and
>> found no old jdom.  Are there known jars(I use several apache) that
> would
>> include jdom classes???  I am using eclipse.
>> 
>> 
>> -----Original Message-----
>> From: Rolf Lear [mailto:jdom at tuis.net]
>> Sent: Monday, August 20, 2012 11:35 AM
>> To: Craig Christophersen
>> Cc: jdom-interest at jdom.org
>> Subject: Re: [jdom-interest] jdom2 migration issue
>> 
>> 
>> Hi Craig.
>> 
>> There must be some other imports from the org.jdom package (as well 
>> as org.jdom2....).
>> 
>> The error message you are getting would be impossible unless you have 
>> those imports.
>> 
>> Something is wrong in your imports.... and your build path must have
> some
>> old JDOM classes from places other than just the old JDOM jar.
>> 
>> Finally, it is normal in GUI-type development tools, (eclipse,
IntelliJ,
>> etc) to exclude the package on field names.... i.e. the line:
>> 
>>     protected org.jdom2.Document document;
>> 
>> would not normally be created by Eclipse/IntelliJ unless your class 
>> was already using the org.jdom.Document version somewhere. You should
> probably
>> replace the line with:
>> 
>>     protected Document document;
>> 
>> and ensure that you can import Document from org.jdom2 with
>> 
>>     import org.jdom2.Document;
>> 
>> Bottom line is that you still have old JDOM classes in your build 
>> path, and the copde you have shown us us using *both* Document 
>> versions (org.jdom, as well as org.jdom2).
>> 
>> Rolf
>> 
>> 
>> 
>> 
>> 
>> On Mon, 20 Aug 2012 09:58:15 -0600, "Craig Christophersen"
>> <craigch at synesis7.com> wrote:
>>> Hello;
>>> 
>>> I have been trying to migrate to Jdom2 in an application.  I have
>> followed
>>> the migration guide but get a type mismatch error.
>>> 
>>> Snippit below:
>>> 
>>>    protected org.jdom2.Document document;
>>> 
>>>  
>>> 
>>>     private String str = null;
>>> 
>>>     private String dmString = "";
>>> 
>>>     String f = "f";
>>> 
>>>     String t = "t";
>>> 
>>>     protected DocType dt;
>>> 
>>>     /**
>>> 
>>>      * Read the specified File and parse it to create a JDOM tree
>>> 
>>>      **/
>>> 
>>>     public ReadDmFile(File dmFile)// throws IOException, 
>>> JDOMException

>>> {
>>> 
>>>     {
>>> 
>>>         System.out.println("File in ReadDm X: " + dmFile);
>>> 
>>>        
>>> 
>>>         try {
>>> 
>>>         SAXBuilder builder =
>>> 
>>>             new SAXBuilder(); //"org.apache.xerces.parsers.SAXParser"
>>> 
>>>       
>>> 
>>>         // Parse the specified file and convert it to a JDOM 
>>> document
>>> 
>>>         builder.setIgnoringElementContentWhitespace(true);
>>> 
>>>         document = builder.build(dmFile);
>>> 
>>>  
>>> 
>>>  
>>> 
>>>  
>>> 
>>> On last line I get "Type mismatch: cannot convert from
>> org.jdom2.Document
>>> to
>>> org.jdom.Document"
>>> 
>>> The old jdom jar is removed from this project.
>>> 
>>> Any help would be appreciated.
>>> 
>>>  
>>> 
>>> Thanks,
>>> 
>>>  
>>> 
>>>  
>>> 
>>> Craig Christophersen
>>> 
>>> Software Developer
>>> 
>>> Synesis7
>>> 
>>> craigch at synesis7.com




More information about the jdom-interest mailing list