[New] Using visitor pattern to perform DOM actions
This commit is contained in:
parent
c76d6cebc4
commit
a0d4f2587e
|
@ -126,10 +126,4 @@ public abstract class AbstractDao<T extends StrolchElement> implements StrolchDa
|
||||||
public void removeAll(List<T> objects) {
|
public void removeAll(List<T> objects) {
|
||||||
this.tx.getObjectDao().removeAll(objects);
|
this.tx.getObjectDao().removeAll(objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(String type, String id) {
|
|
||||||
IdOfSubTypeRef objectRef = this.tx.getObjectRefCache().getIdOfSubTypeRef(getClassType(), type, id);
|
|
||||||
this.tx.getObjectDao().removeById(objectRef);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ public class XmlStrolchTransaction implements StrolchTransaction {
|
||||||
private boolean suppressUpdates;
|
private boolean suppressUpdates;
|
||||||
private PersistenceTransaction tx;
|
private PersistenceTransaction tx;
|
||||||
private TransactionCloseStrategy closeStrategy;
|
private TransactionCloseStrategy closeStrategy;
|
||||||
private TransactionResult txResult;
|
|
||||||
|
|
||||||
public XmlStrolchTransaction(PersistenceTransaction tx) {
|
public XmlStrolchTransaction(PersistenceTransaction tx) {
|
||||||
this.suppressUpdates = false;
|
this.suppressUpdates = false;
|
||||||
|
@ -75,18 +74,18 @@ public class XmlStrolchTransaction implements StrolchTransaction {
|
||||||
@Override
|
@Override
|
||||||
public void autoCloseableCommit() {
|
public void autoCloseableCommit() {
|
||||||
|
|
||||||
|
TransactionResult txResult = new TransactionResult();
|
||||||
if (!this.suppressUpdates && this.observerHandler != null) {
|
if (!this.suppressUpdates && this.observerHandler != null) {
|
||||||
this.txResult = new TransactionResult();
|
this.tx.setTransactionResult(txResult);
|
||||||
this.tx.setTransactionResult(this.txResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tx.autoCloseableCommit();
|
this.tx.autoCloseableCommit();
|
||||||
|
|
||||||
if (!this.suppressUpdates && this.observerHandler != null) {
|
if (!this.suppressUpdates && this.observerHandler != null) {
|
||||||
|
|
||||||
Set<String> keys = this.txResult.getKeys();
|
Set<String> keys = txResult.getKeys();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
ModificationResult modificationResult = this.txResult.getModificationResult(key);
|
ModificationResult modificationResult = txResult.getModificationResult(key);
|
||||||
|
|
||||||
this.observerHandler.add(key, modificationResult.<StrolchElement> getCreated());
|
this.observerHandler.add(key, modificationResult.<StrolchElement> getCreated());
|
||||||
this.observerHandler.update(key, modificationResult.<StrolchElement> getUpdated());
|
this.observerHandler.update(key, modificationResult.<StrolchElement> getUpdated());
|
||||||
|
|
|
@ -15,15 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.persistence.impl.model;
|
package li.strolch.persistence.impl.model;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
|
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.model.xml.OrderToDomVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import ch.eitchnet.xmlpers.api.DomParser;
|
import ch.eitchnet.xmlpers.api.DomParser;
|
||||||
import ch.eitchnet.xmlpers.util.DomUtil;
|
|
||||||
|
|
||||||
public class OrderDomParser implements DomParser<Order> {
|
public class OrderDomParser implements DomParser<Order> {
|
||||||
|
|
||||||
|
@ -42,19 +40,13 @@ public class OrderDomParser implements DomParser<Order> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Document toDom() {
|
public Document toDom() {
|
||||||
|
OrderToDomVisitor orderDomVisitor = new OrderToDomVisitor();
|
||||||
DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder();
|
orderDomVisitor.visit(this.order);
|
||||||
Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null);
|
return orderDomVisitor.getDocument();
|
||||||
|
|
||||||
Element orderDom = this.order.toDom(document);
|
|
||||||
document.appendChild(orderDom);
|
|
||||||
|
|
||||||
return document;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromDom(Document document) {
|
public void fromDom(Document document) {
|
||||||
|
|
||||||
Element rootElement = document.getDocumentElement();
|
Element rootElement = document.getDocumentElement();
|
||||||
Order order = new Order(rootElement);
|
Order order = new Order(rootElement);
|
||||||
this.order = order;
|
this.order = order;
|
||||||
|
|
|
@ -15,15 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.persistence.impl.model;
|
package li.strolch.persistence.impl.model;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.xml.ResourceToDomVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import ch.eitchnet.xmlpers.api.DomParser;
|
import ch.eitchnet.xmlpers.api.DomParser;
|
||||||
import ch.eitchnet.xmlpers.util.DomUtil;
|
|
||||||
|
|
||||||
public class ResourceDomParser implements DomParser<Resource> {
|
public class ResourceDomParser implements DomParser<Resource> {
|
||||||
|
|
||||||
|
@ -41,19 +39,13 @@ public class ResourceDomParser implements DomParser<Resource> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Document toDom() {
|
public Document toDom() {
|
||||||
|
ResourceToDomVisitor domVisitor = new ResourceToDomVisitor();
|
||||||
DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder();
|
domVisitor.visit(this.resource);
|
||||||
Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null);
|
return domVisitor.getDocument();
|
||||||
|
|
||||||
Element resourceDom = this.resource.toDom(document);
|
|
||||||
document.appendChild(resourceDom);
|
|
||||||
|
|
||||||
return document;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromDom(Document document) {
|
public void fromDom(Document document) {
|
||||||
|
|
||||||
Element rootElement = document.getDocumentElement();
|
Element rootElement = document.getDocumentElement();
|
||||||
Resource resource = new Resource(rootElement);
|
Resource resource = new Resource(rootElement);
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
|
|
Loading…
Reference in New Issue