Update of /cvsroot/xorm/xorm/src/org/xorm/datastore/xml In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv4174/src/org/xorm/datastore/xml Modified Files: DocumentHolder.java JDOMDocumentDriver.java W3CDocumentDriver.java W3CDocumentHolder.java XMLConnectionInfo.java Log Message: The XML driver stuff is still hard-coded to use JDOM, but that can be swapped out easily if and when. ModelMapping now uses W3C DOM. Index: JDOMDocumentDriver.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/JDOMDocumentDriver.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** JDOMDocumentDriver.java 8 Feb 2006 17:26:28 -0000 1.9 --- JDOMDocumentDriver.java 8 Jun 2006 17:33:47 -0000 1.10 *************** *** 21,24 **** --- 21,25 ---- import java.io.IOException; + import java.net.URL; import java.util.ArrayList; import java.util.Collection; *************** *** 65,70 **** * Sets the data source, which must be an instance of DocumentHolder. */ ! public JDOMDocumentDriver(DocumentHolder documentHolder) { ! this.documentHolder = documentHolder; } --- 66,72 ---- * Sets the data source, which must be an instance of DocumentHolder. */ ! public JDOMDocumentDriver(URL url) { ! documentHolder = new JDOMDocumentHolder(); ! documentHolder.setURL(url); } *************** *** 73,77 **** */ public void begin(boolean readOnly) { ! document = documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; --- 75,79 ---- */ public void begin(boolean readOnly) { ! document = (Document)documentHolder.checkout(); this.readOnly = readOnly; onlyDidReads = true; Index: XMLConnectionInfo.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/XMLConnectionInfo.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XMLConnectionInfo.java 17 Dec 2002 17:51:09 -0000 1.2 --- XMLConnectionInfo.java 8 Jun 2006 17:33:47 -0000 1.3 *************** *** 27,47 **** public class XMLConnectionInfo extends ConnectionInfo { ! private DocumentHolder documentHolder; ! ! private DocumentHolder getDocumentHolder() { ! if (documentHolder == null) { ! try { ! URL url = new URL(getConnectionURL()); ! documentHolder = new DocumentHolder(url); ! } catch (MalformedURLException e) { ! // TODO ! e.printStackTrace(); ! } ! } ! return documentHolder; ! } ! public DatastoreDriver getDriver() { ! return new JDOMDocumentDriver(getDocumentHolder()); } } --- 27,46 ---- public class XMLConnectionInfo extends ConnectionInfo { ! static final boolean useJDOM = true; ! public DatastoreDriver getDriver() { ! URL url; ! try { ! url = new URL(getConnectionURL()); ! } catch (MalformedURLException e) { ! // TODO ! throw new RuntimeException(e); ! } ! if (useJDOM) { ! return new JDOMDocumentDriver(url); ! } ! else { ! return new W3CDocumentDriver(url); ! } } } Index: DocumentHolder.java =================================================================== RCS file: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/DocumentHolder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DocumentHolder.java 15 Jul 2003 22:53:10 -0000 1.2 --- DocumentHolder.java 8 Jun 2006 17:33:47 -0000 1.3 *************** *** 20,91 **** package org.xorm.datastore.xml; - import java.io.FileOutputStream; - import java.io.IOException; - import java.io.OutputStream; - import java.net.URL; - import java.net.URLConnection; - import java.net.MalformedURLException; - - import org.jdom.Document; - import org.jdom.JDOMException; - import org.jdom.input.SAXBuilder; - import org.jdom.output.XMLOutputter; /** ! * Wraps a JDOM Document and allows transactional access. * ! * @author Wes Biggs */ ! public class DocumentHolder { ! private URL url; ! private Document document; ! ! public DocumentHolder(URL url) { ! this.url = url; ! try { ! document = new SAXBuilder().build(url); ! } catch (JDOMException e) { ! e.printStackTrace(); ! } catch (IOException e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * Returns a cloned copy of the document. ! */ ! public Document checkout() { ! return (Document) document.clone(); ! } ! ! /** ! * Accepts the changes from the document. If possible, rewrites ! * the content. Changes are synchronized but not checked; if two ! * concurrent threads make different changes, the last one to call ! * checkin() will win. This effectively gives the process a ! * transaction isolation level equivalent to TRANSACTION_READ_COMMITTED. ! */ ! public void checkin(Document document) { ! this.document = document; ! ! synchronized (url) { ! OutputStream outputStream = null; ! try { ! if ("file".equals(url.getProtocol())) { ! outputStream = new FileOutputStream(url.getFile()); ! } else { ! // Try to set "doOutput", may not work ! URLConnection connection = url.openConnection(); ! connection.setDoOutput(true); ! outputStream = connection.getOutputStream(); ! } ! new XMLOutputter(" ", true).output(document, outputStream); ! outputStream.flush(); ! outputStream.close(); ! } catch (IOException e) { ! e.printStackTrace(); ! } ! } // synchronized ! } } --- 20,33 ---- package org.xorm.datastore.xml; import java.net.URL; /** ! * Interface for Document holder objects * ! * @author Dan Checkoway */ ! public interface DocumentHolder { ! void setURL(URL url); ! Object checkout(); ! void checkin(Object document); } |