|
From: Mark R. D. <mdi...@la...> - 2003-06-12 13:32:23
|
Hmm, its still a little buggy, the file paths to things like the
charts.xml seem to get prepended with the current directory. THis is
cause by my trying to build a File object using the "url" veriosn of the
file location. Luckly, the JAXP parser accepts URL strings as well, so I
fixed this by removing the File object wrapping from my code. I'll be
glad to commit it once I've tested it.
-M.
Nick Collier wrote:
> Mark,
>
> Thanks! Did you commit these changes? If not I can do the patch and
> commit. I have one thing to finish up and then I'll do this. I'll also
> make the appropriate changes in SimBuilder as well.
>
> thanks again,
>
> Nick
>
> On Wed, 2003-06-11 at 14:13, Mark R. Diggory wrote:
>
>>I've identified the following Classes that are the only ones dependent
>>on Xerces (by removing Xerces from my build path).
>>
>>ChartArchiver.java repast/src/uchicago/src/sim/analysis line 76
>>CompUnitParser.java repast/src/uchicago/src/codegen line 12
>>FrameFactory.java repast/src/uchicago/src/sim/gui line 120
>>XMLParameterReader.java repast/src/uchicago/src/sim/parameter line 21
>>
>>I went throught these files and adjusted the code to use JAXP. This is
>>untested. Your current copy of xerces.jar has the JAXP dom and sax
>>parsers api's present in it, so it should still be safe on pre 1.3.
>>
>>-Mark
>>
>>
>>Mark R. Diggory wrote:
>>
>>
>>>Well, the good news is that using JAXP "frees up" the determination of
>>>which XML parser to the point that you could easily package a pre 1.4
>>>"Mac"able version of your packages that has the JAXP and your favorite
>>>parser included and a "post 1.4" version that finds the JAXP in the
>>>J2sdk.
>>>
>>>-M.
>>>
>>>Nick Collier wrote:
>>>
>>>
>>>>I agree. The reason we were using Xerces is for pre 1.4. support for the
>>>>Mac. However, I think Tom and I have decided to standardize on 1.4
>>>>
>>>>Nick
>>>>
>>>>On Wed, 2003-06-11 at 09:55, thowe wrote:
>>>>
>>>>
>>>>
>>>>>I agree, I like abstracting the parser implementation out like this. I
>>>>>also like not having to include the xerces jar file. If there is
>>>>>anyone
>>>>>who is interested in working on this, that would be great. I'll do it,
>>>>>if not, but I'm not sure when I can get to it.
>>>>>
>>>>>Thanks,
>>>>>Tom
>>>>>
>>>>>On Wed, 2003-06-11 at 08:49, Mark R. Diggory wrote:
>>>>>
>>>>>
>>>>>
>>>>>>We keep encountering the following problem with RePast and trying
>>>>>>to use Charts, I've been using a newer version of Xerces, I don't
>>>>>>know if this is to blame. There appear to be issues with Xerces DTD
>>>>>>validation feature attempting to resolve external ftp url's for
>>>>>>some reason.
>>>>>>
>>>>>>I personally would recommend using the JAXP interface over Xerces
>>>>>>directly, the default configuration and validation behavior is more
>>>>>>predictable through the JAXP interface with something like:
>>>>>>
>>>>>>DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>>>>>>DocumentBuilder docBuilder = factory.newDocumentBuilder();
>>>>>>Document doc = docBuilder.parse(new File(file));
>>>>>>
>>>>>>this frees you from the particular Xerces Implementation too. You
>>>>>>can rely on the default parser implmentation included with the
>>>>>>latest J2SDK (which I believe is actually Xerces right now) and not
>>>>>>have to provide a copy of Xerces directly within your distribution.
>>>>>>
>>>>>>-Mark
>>>>>>
>>>>>>The exception:
>>>>>> [java] Error loading persistent chart sizes and positions
>>>>>> [java] java.net.UnknownHostException: C
>>>>>> [java] at
>>>>>>java.net.InetAddress.getAllByName0(InetAddress.java:571)
>>>>>> [java] at
>>>>>>java.net.InetAddress.getAllByName0(InetAddress.java:540)
>>>>>> [java] at
>>>>>>java.net.InetAddress.getByName(InetAddress.java:449)
>>>>>> [java] at java.net.Socket.<init>(Socket.java:100)
>>>>>> [java] at
>>>>>>sun.net.NetworkClient.doConnect(NetworkClient.java:50)
>>>>>> [java] at
>>>>>>sun.net.NetworkClient.openServer(NetworkClient.java:38)
>>>>>> [java] at
>>>>>>sun.net.ftp.FtpClient.openServer(FtpClient.java:267)
>>>>>> [java] at sun.net.ftp.FtpClient.<init>(FtpClient.java:381)
>>>>>> [java] at
>>>>>>sun.net.www.protocol.ftp.FtpURLConnection.connect
>>>>>>(FtpURLConnection.java:77)
>>>>>> [java] at
>>>>>>sun.net.www.protocol.ftp.FtpURLConnection.getInputStream
>>>>>>(FtpURLConnection.java:96)
>>>>>> [java] at java.net.URL.openStream(URL.java:798)
>>>>>> [java] at
>>>>>>org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown
>>>>>>Source)
>>>>>> [java] at
>>>>>>org.apache.xerces.impl.XMLEntityManager.startDocumentEntity
>>>>>>(Unknown Source)
>>>>>> [java] at
>>>>>>org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource
>>>>>>(Unknown Source)
>>>>>> [java] at
>>>>>>org.apache.xerces.parsers.DTDConfiguration.parse(Unknown
>>>>>>Source)
>>>>>> [java] at
>>>>>>org.apache.xerces.parsers.DTDConfiguration.parse(Unknown
>>>>>>Source)
>>>>>> [java] at
>>>>>>org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>>>>>> [java] at
>>>>>>org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
>>>>>> [java] at uchicago.src.sim.analysis.ChartArchiver.loadXML
>>>>>>(ChartArchiver.java:77)
>>>>>> [java] at
>>>>>>uchicago.src.sim.analysis.ChartArchiver.loadCharts
>>>>>>(ChartArchiver.java:67)
>>>>>> [java] at
>>>>>>uchicago.src.sim.engine.AbstractGUIController.setModel
>>>>>>(AbstractGUIController.java:165)
>>>>>> [java] at uchicago.src.sim.engine.Controller.setModel
>>>>>>(Controller.java:146)
>>>>>
>>
>>______________________________________________________________________
>>
>>Index: src/uchicago/src/codegen/CompUnitParser.java
>>===================================================================
>>RCS file: /cvsroot/repast/repast/src/uchicago/src/codegen/CompUnitParser.java,v
>>retrieving revision 1.1.1.1
>>diff -u -r1.1.1.1 CompUnitParser.java
>>--- src/uchicago/src/codegen/CompUnitParser.java 26 Sep 2001 17:07:57 -0000 1.1.1.1
>>+++ src/uchicago/src/codegen/CompUnitParser.java 11 Jun 2003 18:04:57 -0000
>>@@ -1,19 +1,26 @@
>> package uchicago.src.codegen;
>>
>> import java.util.Stack;
>>+import java.io.File;
>> import java.io.IOException;
>>
>>+import javax.xml.parsers.DocumentBuilder;
>>+import javax.xml.parsers.DocumentBuilderFactory;
>>+
>> import org.w3c.dom.*;
>>-import org.apache.xerces.parsers.DOMParser;
>>+
>>
>> public class CompUnitParser {
>>
>> private Stack stack = new Stack();
>>- private DOMParser parser = new DOMParser();
>>
>>+ private Document doc = null;
>>+
>> public CompUnitParser(String fileName) throws IOException {
>> try {
>>- parser.parse(fileName);
>>+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>>+ DocumentBuilder docBuilder = factory.newDocumentBuilder();
>>+ doc = docBuilder.parse(new File(fileName));
>> } catch (Exception ex) {
>> throw new IOException(ex.getMessage());
>> }
>>@@ -49,7 +56,7 @@
>> * Parses the document tree and creates the CompUnitGenerator.
>> */
>> public CompUnitGenerator parse() {
>>- Document doc = parser.getDocument();
>>+
>> doParse(doc.getDocumentElement());
>>
>> return (CompUnitGenerator)stack.pop();
>>Index: src/uchicago/src/sim/analysis/ChartArchiver.java
>>===================================================================
>>RCS file: /cvsroot/repast/repast/src/uchicago/src/sim/analysis/ChartArchiver.java,v
>>retrieving revision 1.3
>>diff -u -r1.3 ChartArchiver.java
>>--- src/uchicago/src/sim/analysis/ChartArchiver.java 3 Jan 2003 14:37:11 -0000 1.3
>>+++ src/uchicago/src/sim/analysis/ChartArchiver.java 11 Jun 2003 18:04:57 -0000
>>@@ -1,6 +1,5 @@
>> package uchicago.src.sim.analysis;
>>
>>-import org.apache.xerces.parsers.DOMParser;
>> import org.w3c.dom.Document;
>> import org.w3c.dom.Element;
>> import org.w3c.dom.NodeList;
>>@@ -12,6 +11,9 @@
>> import java.util.ArrayList;
>> import java.awt.*;
>>
>>+import javax.xml.parsers.DocumentBuilder;
>>+import javax.xml.parsers.DocumentBuilderFactory;
>>+
>> import uchicago.src.sim.engine.SimModel;
>> import uchicago.src.sim.util.SimUtilities;
>>
>>@@ -73,9 +75,9 @@
>> private static ArrayList loadXML(String file, SimModel model) {
>> ArrayList charts = new ArrayList();
>> try {
>>- DOMParser parser = new DOMParser();
>>- parser.parse(file);
>>- Document doc = parser.getDocument();
>>+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>>+ DocumentBuilder docBuilder = factory.newDocumentBuilder();
>>+ Document doc = docBuilder.parse(new File(file));
>> Element root = doc.getDocumentElement();
>> NodeList list = root.getElementsByTagName("ChartModel");
>> for (int i = 0; i < list.getLength(); i++) {
>>Index: src/uchicago/src/sim/gui/FrameFactory.java
>>===================================================================
>>RCS file: /cvsroot/repast/repast/src/uchicago/src/sim/gui/FrameFactory.java,v
>>retrieving revision 1.6
>>diff -u -r1.6 FrameFactory.java
>>--- src/uchicago/src/sim/gui/FrameFactory.java 3 Jan 2003 14:37:22 -0000 1.6
>>+++ src/uchicago/src/sim/gui/FrameFactory.java 11 Jun 2003 18:04:57 -0000
>>@@ -1,6 +1,9 @@
>> package uchicago.src.sim.gui;
>>
>> import javax.swing.*;
>>+import javax.xml.parsers.DocumentBuilder;
>>+import javax.xml.parsers.DocumentBuilderFactory;
>>+
>> import java.awt.Rectangle;
>> import java.awt.event.WindowAdapter;
>> import java.awt.event.WindowEvent;
>>@@ -9,7 +12,7 @@
>> import java.io.*;
>>
>> import org.w3c.dom.*;
>>-import org.apache.xerces.parsers.DOMParser;
>>+
>> import uchicago.src.sim.util.SimUtilities;
>>
>> /**
>>@@ -117,9 +120,9 @@
>>
>> private static void loadXML(String file) {
>> try {
>>- DOMParser parser = new DOMParser();
>>- parser.parse(file);
>>- Document doc = parser.getDocument();
>>+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>>+ DocumentBuilder docBuilder = factory.newDocumentBuilder();
>>+ Document doc = docBuilder.parse(new File(file));
>> Element root = doc.getDocumentElement();
>> NodeList list = root.getElementsByTagName("frame_property");
>> for (int i = 0; i < list.getLength(); i++) {
>>Index: src/uchicago/src/sim/parameter/XMLParameterReader.java
>>===================================================================
>>RCS file: /cvsroot/repast/repast/src/uchicago/src/sim/parameter/XMLParameterReader.java,v
>>retrieving revision 1.1
>>diff -u -r1.1 XMLParameterReader.java
>>--- src/uchicago/src/sim/parameter/XMLParameterReader.java 10 Mar 2003 16:47:51 -0000 1.1
>>+++ src/uchicago/src/sim/parameter/XMLParameterReader.java 11 Jun 2003 18:04:58 -0000
>>@@ -1,15 +1,17 @@
>> package uchicago.src.sim.parameter;
>>
>>+import java.io.File;
>> import java.io.IOException;
>> import java.util.Vector;
>> import java.util.Hashtable;
>> import java.util.StringTokenizer;
>> import java.lang.reflect.Method;
>>
>>+import javax.xml.parsers.DocumentBuilder;
>>+import javax.xml.parsers.DocumentBuilderFactory;
>>+
>> import org.w3c.dom.*;
>>
>>-import org.apache.xerces.parsers.DOMParser;
>>-import uchicago.src.sim.parameter.Parameter;
>>
>>
>> /**
>>@@ -18,7 +20,8 @@
>>
>> public class XMLParameterReader {
>>
>>- private DOMParser parser = new DOMParser();
>>+ private Document doc = null;
>>+
>> private Vector params = new Vector();
>> private Vector tempVec = new Vector();
>> private Hashtable methodTable = new Hashtable();
>>@@ -26,7 +29,9 @@
>>
>> public XMLParameterReader(String fileName) throws IOException {
>> try {
>>- parser.parse(fileName);
>>+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>>+ DocumentBuilder docBuilder = factory.newDocumentBuilder();
>>+ doc = docBuilder.parse(new File(fileName));
>> } catch (Exception ex) {
>> throw new IOException(ex.getMessage());
>> }
>>@@ -106,7 +111,7 @@
>> */
>> public void parse() {
>> createMethodLookupTable();
>>- Document doc = parser.getDocument();
>>+
>> doParse(doc, null, 0);
>>
>> // Only the "top-level" parameters, those with no parents, are put
|