From 9acfee03a24aa52a4aae6bb77a1093c5b9780a9f Mon Sep 17 00:00:00 2001 From: kelvingoodson Date: Wed, 13 Aug 2008 12:09:23 +0000 Subject: alter copy helper to do late state setting of ChangeSummary logging -- a necessary but not sufficient step towards change summary copying git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@685525 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tuscany/sdo/helper/CopyHelperImpl.java | 77 +++++++++++++++------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CopyHelperImpl.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CopyHelperImpl.java index d768076ecb..b4d3b257b0 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CopyHelperImpl.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CopyHelperImpl.java @@ -20,6 +20,10 @@ package org.apache.tuscany.sdo.helper; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; @@ -37,48 +41,75 @@ public class CopyHelperImpl implements CopyHelper { public DataObject copyShallow(DataObject dataObject) { - Copier copier = new Copier() + Copier copier = new SDOCopier() { protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) { } - protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) { - if(("ChangeSummaryType".equals(eAttribute.getEType().getName()) && "commonj.sdo".equals(eAttribute.getEType().getEPackage().getNsURI()))) { - boolean isLogging = ((ChangeSummary)eObject.eGet(eAttribute)).isLogging(); - ChangeSummary destSum = (ChangeSummary)copyEObject.eGet(eAttribute); - if(isLogging) { - if(!destSum.isLogging()) destSum.beginLogging(); - } else { - if(destSum.isLogging()) destSum.endLogging(); - } - } else { - super.copyAttribute(eAttribute, eObject, copyEObject); - } - } + }; - EObject result = copier.copy((EObject)dataObject); - copier.copyReferences(); - return (DataObject)result; + return (DataObject)copier.copy((EObject)dataObject); } public DataObject copy(DataObject dataObject) { - Copier copier = new Copier() - { + Copier copier = new SDOCopier(){ protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) { if(("ChangeSummaryType".equals(eAttribute.getEType().getName()) && "commonj.sdo".equals(eAttribute.getEType().getEPackage().getNsURI()))) { - throw new UnsupportedOperationException("This will be implemented when change summary serialization/deserialization is in place"); + throw new UnsupportedOperationException("Copying of change summary yet to be done"); } else { super.copyAttribute(eAttribute, eObject, copyEObject); } } }; - EObject result = copier.copy((EObject)dataObject); - copier.copyReferences(); - return (DataObject)result; + + return (DataObject)copier.copy((EObject)dataObject); } } + + +class SDOCopier extends Copier { + + List csToTurnOn = new ArrayList(); + List csToTurnOff = new ArrayList(); + + public EObject copy(EObject object) { + + EObject result = super.copy(object); + copyReferences(); + + for (Iterator csit = csToTurnOn.iterator(); csit.hasNext();) { + ChangeSummary cs = (ChangeSummary) csit.next(); + if(!cs.isLogging()) { cs.beginLogging(); } + } + for (Iterator csit = csToTurnOff.iterator(); csit.hasNext();) { + ChangeSummary cs = (ChangeSummary) csit.next(); + if(cs.isLogging()) { cs.endLogging(); } + } + + return result; + } + + + + protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) { + + if(("ChangeSummaryType".equals(eAttribute.getEType().getName()) && "commonj.sdo".equals(eAttribute.getEType().getEPackage().getNsURI()))) { + if (((ChangeSummary)eObject.eGet(eAttribute)).isLogging()) { + csToTurnOn.add(((DataObject)copyEObject).getChangeSummary()); + } else { + csToTurnOff.add(((DataObject)copyEObject).getChangeSummary()); + } + ChangeSummary copyCS = (ChangeSummary)copyEObject.eGet(eAttribute); + if(copyCS.isLogging()) copyCS.endLogging(); + + } else { + super.copyAttribute(eAttribute, eObject, copyEObject); + } + } + +} \ No newline at end of file -- cgit v1.2.3