1 package org.dom4j.persistence.nativ; 2 3 import org.dom4j.io.SAXContentHandler; 4 import org.dom4j.io.SAXWriter; 5 import org.dom4j.persistence.DocumentMarshalling; 6 import org.dom4j.persistence.MarshallingContext; 7 8 9 /*** 10 * 11 * @author Tobias Rademacher 12 * @version 1.0 13 */ 14 15 public abstract class XMLDBStrategy extends DocumentMarshalling { 16 17 protected SAXContentHandler extractContent; 18 protected SAXWriter resolver; 19 protected MarshallingContext context; 20 21 /* 22 * 23 * temporarily commented out until we get this compiling again... 24 * 25 protected TransactionService transactionService; 26 protected Collection collection; 27 28 public XMLDBStrategy(MarshallingContext context) throws IllegalAccessException, java.lang.InstantiationException { 29 this.context = context; 30 Database database = (Database) this.context.getDatabaseDriver().newInstance(); 31 this.collection = DatabaseManager.getCollection(this.context.getDatabaseLocation().toExternalForm()); 32 TransactionService transaction = 33 (TransactionService) this.collection.getService("TransactionService", "1.0"); 34 } 35 36 public void marshal(String aId, Node aNode) throws Exception { 37 this.resolve(aNode); 38 SAXResource resource = (SAXResource) this.collection.createResource(aId, "SAXResource"); 39 resource.setContentHandler(this.extractContent); 40 this.collection.storeResource(resource); 41 if(this.context.isAutoCommiting()) 42 transactionService.commit(); 43 } 44 45 public Node unmarshal(String systemId) { 46 XMLResource resource = (XMLResource) this.collection.getResource(systemId); 47 resource.getContentAsSAX(this.extractContent); 48 return this.extractContent.getDocument(); 49 } 50 51 protected void resolve(Node aNode) throws SAXException { 52 this.extractContent = new SAXContentHandler(); 53 this.resolver = new SAXWriter(this.extractContent); 54 this.resolver.write((Document)aNode); 55 } 56 57 public void setContext(MarshallingContext aContext) { 58 this.context = aContext; 59 } 60 */ 61 62 }