diff options
author | kelvingoodson <kelvingoodson@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-13 12:09:23 +0000 |
---|---|---|
committer | kelvingoodson <kelvingoodson@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-13 12:09:23 +0000 |
commit | 9acfee03a24aa52a4aae6bb77a1093c5b9780a9f (patch) | |
tree | 656c7fa34d9658bcea89864970557cc706f307d2 | |
parent | 234d45adf59155671db7dfdae2fbf836f21d855b (diff) |
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
Diffstat (limited to '')
-rw-r--r-- | java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CopyHelperImpl.java | 77 |
1 files 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 |