Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/org.eclipse.emf.teneo.samples/src/temporal/mod/TemporalEStoreHandler.java')
-rwxr-xr-xtests/org.eclipse.emf.teneo.samples/src/temporal/mod/TemporalEStoreHandler.java172
1 files changed, 97 insertions, 75 deletions
diff --git a/tests/org.eclipse.emf.teneo.samples/src/temporal/mod/TemporalEStoreHandler.java b/tests/org.eclipse.emf.teneo.samples/src/temporal/mod/TemporalEStoreHandler.java
index 56f4b0089..02ce44f00 100755
--- a/tests/org.eclipse.emf.teneo.samples/src/temporal/mod/TemporalEStoreHandler.java
+++ b/tests/org.eclipse.emf.teneo.samples/src/temporal/mod/TemporalEStoreHandler.java
@@ -15,11 +15,12 @@ import temporal.TemporalPackage;
import temporal.VersionHolder;
/**
- * When editing in the past this handler will use the next EStore to propagate the values to the next versions. This is
- * necessary to bypass the temporality handler and just set the values in the next versions. TODO: It may be more
- * efficient to use the next EStore whenever we want to get/set values from the Temporal base class. Right now I get/set
- * the values from the Temporal base class with the generated getters and setters. It makes the code clear to read
- * however it does rely on the fact that the set checks if the request is for the Temporal base class. It may be more
+ * When editing in the past this handler will use the next EStore to propagate the values to the
+ * next versions. This is necessary to bypass the temporality handler and just set the values in the
+ * next versions. TODO: It may be more efficient to use the next EStore whenever we want to get/set
+ * values from the Temporal base class. Right now I get/set the values from the Temporal base class
+ * with the generated getters and setters. It makes the code clear to read however it does rely on
+ * the fact that the set checks if the request is for the Temporal base class. It may be more
* efficient to forward these request to the next EStore directly. This would need to be tried out.
*
* @author jcmcote
@@ -28,14 +29,16 @@ import temporal.VersionHolder;
public class TemporalEStoreHandler {
/**
- * Temporal processing for setters. The main purpose of the temporal setter hook is to find a matching verionned
- * object given the current Now time. If none are found it will create a new versionned object and perform the
- * "setting" request on it. If we find a versionned object that matches we delegate the "setting" request to it.
+ * Temporal processing for setters. The main purpose of the temporal setter hook is to find a
+ * matching verionned object given the current Now time. If none are found it will create a new
+ * versionned object and perform the "setting" request on it. If we find a versionned object that
+ * matches we delegate the "setting" request to it.
*
- * We also set the value to all subsequent versions. We stop when we hit a version which has this attribute already
- * set by the user.
+ * We also set the value to all subsequent versions. We stop when we hit a version which has this
+ * attribute already set by the user.
*/
- public static boolean set(InternalEObject givenEObject, EStructuralFeature feature, int index, Object value, Object retOldValue[]) {
+ public static boolean set(InternalEObject givenEObject, EStructuralFeature feature, int index,
+ Object value, Object retOldValue[]) {
boolean handled = false;
InternalEObject version = findVersionToDelegateMutatorTo(givenEObject, feature);
if (version != null) {
@@ -48,15 +51,13 @@ public class TemporalEStoreHandler {
// And propagate the value to subsequent versions without affecting the touched flags.
propagateSetToNextVersions(version, feature, index, value);
- }
- else {
+ } else {
// Handle the setting into a EList case EList.set(index, value).
retOldValue[0] = getList(version, feature).set(index, value);
}
handled = true;
- }
- else {
+ } else {
// If the mutator request is not forked to a version we still must make sure
// to set the touched attributes.
if (isTemporalFeature(givenEObject, feature)) {
@@ -72,7 +73,8 @@ public class TemporalEStoreHandler {
return handled;
}
- public static boolean add(InternalEObject givenEObject, EStructuralFeature feature, int index, Object value) {
+ public static boolean add(InternalEObject givenEObject, EStructuralFeature feature, int index,
+ Object value) {
InternalEObject version = findVersionToDelegateMutatorTo(givenEObject, feature);
if (version != null) {
// Delegate setting operation to this versioned object.
@@ -92,7 +94,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean move(InternalEObject givenEObject, EStructuralFeature feature, int targetIndex, int sourceIndex, Object[] retValue) {
+ public static boolean move(InternalEObject givenEObject, EStructuralFeature feature,
+ int targetIndex, int sourceIndex, Object[] retValue) {
InternalEObject version = findVersionToDelegateMutatorTo(givenEObject, feature);
if (version != null) {
// Delegate setting operation to this versioned object.
@@ -103,7 +106,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean remove(InternalEObject givenEObject, EStructuralFeature feature, int index, Object[] retOldValue) {
+ public static boolean remove(InternalEObject givenEObject, EStructuralFeature feature, int index,
+ Object[] retOldValue) {
InternalEObject version = findVersionToDelegateMutatorTo(givenEObject, feature);
if (version != null) {
// Delegate setting operation to this versioned object.
@@ -114,19 +118,19 @@ public class TemporalEStoreHandler {
}
/**
- * Temporal processing for getters. The main purpose of the temporal setter is to forward setter requests to the
- * versioned objects.
+ * Temporal processing for getters. The main purpose of the temporal setter is to forward setter
+ * requests to the versioned objects.
*
* TODO: implement the is-feature-temporal check.
*/
- public static boolean get(InternalEObject givenEObject, EStructuralFeature feature, int index, Object[] retValue) {
+ public static boolean get(InternalEObject givenEObject, EStructuralFeature feature, int index,
+ Object[] retValue) {
InternalEObject version = findVersionToDelegateAccessorTo(givenEObject, feature);
if (version != null) {
// Delegate to the a versioned object.
if (index == -1) {
retValue[0] = getObject(version, feature);
- }
- else {
+ } else {
retValue[0] = getList(version, feature).get(index);
}
return true;
@@ -134,7 +138,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean size(InternalEObject givenEObject, EStructuralFeature feature, int[] retValue) {
+ public static boolean size(InternalEObject givenEObject, EStructuralFeature feature,
+ int[] retValue) {
InternalEObject version = findVersionToDelegateAccessorTo(givenEObject, feature);
if (version != null) {
// Delegate to the a versioned object.
@@ -144,7 +149,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean lastIndexOf(InternalEObject givenEObject, EStructuralFeature feature, Object value, int[] retValue) {
+ public static boolean lastIndexOf(InternalEObject givenEObject, EStructuralFeature feature,
+ Object value, int[] retValue) {
InternalEObject version = findVersionToDelegateAccessorTo(givenEObject, feature);
if (version != null) {
// Delegate to the a versioned object.
@@ -154,7 +160,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean indexOf(InternalEObject givenEObject, EStructuralFeature feature, Object value, int[] retValue) {
+ public static boolean indexOf(InternalEObject givenEObject, EStructuralFeature feature,
+ Object value, int[] retValue) {
InternalEObject version = findVersionToDelegateAccessorTo(givenEObject, feature);
if (version != null) {
// Delegate to the a versioned object.
@@ -164,7 +171,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean toArray(InternalEObject givenEObject, EStructuralFeature feature, Object[][] retValue) {
+ public static boolean toArray(InternalEObject givenEObject, EStructuralFeature feature,
+ Object[][] retValue) {
InternalEObject version = findVersionToDelegateAccessorTo(givenEObject, feature);
if (version != null) {
// Delegate to the a versioned object.
@@ -174,7 +182,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean toArray(InternalEObject givenEObject, EStructuralFeature feature, Object[] array, Object[][] retValue) {
+ public static boolean toArray(InternalEObject givenEObject, EStructuralFeature feature,
+ Object[] array, Object[][] retValue) {
InternalEObject version = findVersionToDelegateAccessorTo(givenEObject, feature);
if (version != null) {
// Delegate to the a versioned object.
@@ -184,7 +193,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean isEmpty(InternalEObject givenEObject, EStructuralFeature feature, boolean[] retValue) {
+ public static boolean isEmpty(InternalEObject givenEObject, EStructuralFeature feature,
+ boolean[] retValue) {
InternalEObject version = findVersionToDelegateAccessorTo(givenEObject, feature);
if (version != null) {
// Delegate to the a versioned object.
@@ -194,7 +204,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean contains(InternalEObject givenEObject, EStructuralFeature feature, Object value, boolean[] retValue) {
+ public static boolean contains(InternalEObject givenEObject, EStructuralFeature feature,
+ Object value, boolean[] retValue) {
InternalEObject version = findVersionToDelegateAccessorTo(givenEObject, feature);
if (version != null) {
// Delegate to the a versioned object.
@@ -204,7 +215,8 @@ public class TemporalEStoreHandler {
return false;
}
- public static boolean hashCode(InternalEObject givenEObject, EStructuralFeature feature, int[] retValue) {
+ public static boolean hashCode(InternalEObject givenEObject, EStructuralFeature feature,
+ int[] retValue) {
InternalEObject version = findVersionToDelegateAccessorTo(givenEObject, feature);
if (version != null) {
// Delegate to the a versioned object.
@@ -220,14 +232,17 @@ public class TemporalEStoreHandler {
* @param feature
* @return
*/
- public static boolean isFeatureFromTemporalBaseClass(EObject givenEObject, EStructuralFeature feature) {
+ public static boolean isFeatureFromTemporalBaseClass(EObject givenEObject,
+ EStructuralFeature feature) {
EClass containingEClass = feature.getEContainingClass();
return (containingEClass == TemporalEStoreHandler.temporalEClass);
}
public static byte[] getTouchedAttributes(EObject givenEObject) {
- TemporalEStoreImpl temporalEStore = (TemporalEStoreImpl) ((InternalEObject) givenEObject).eStore();
- byte[] touched = (byte[]) temporalEStore.getNext().get((InternalEObject) givenEObject, TemporalPackage.eINSTANCE.getTemporal_TouchedAttributes(), -1);
+ TemporalEStoreImpl temporalEStore = (TemporalEStoreImpl) ((InternalEObject) givenEObject)
+ .eStore();
+ byte[] touched = (byte[]) temporalEStore.getNext().get((InternalEObject) givenEObject,
+ TemporalPackage.eINSTANCE.getTemporal_TouchedAttributes(), -1);
if (touched == null) {
touched = new byte[givenEObject.eClass().getFeatureCount()];
TemporalEStoreHandler.setTouchedAttributes((Temporal) givenEObject, touched);
@@ -237,7 +252,8 @@ public class TemporalEStoreHandler {
public static void setTouchedAttributes(Temporal temporal, byte[] b) {
TemporalEStoreImpl temporalEStore = (TemporalEStoreImpl) ((InternalEObject) temporal).eStore();
- temporalEStore.getNext().set((InternalEObject) temporal, TemporalPackage.eINSTANCE.getTemporal_TouchedAttributes(), -1, b);
+ temporalEStore.getNext().set((InternalEObject) temporal,
+ TemporalPackage.eINSTANCE.getTemporal_TouchedAttributes(), -1, b);
}
private static void setTouchedAttribute(EObject givenEObject, EStructuralFeature feature) {
@@ -247,7 +263,8 @@ public class TemporalEStoreHandler {
}
/**
- * This method check if the givenEObject is a Temporal and if the feature is from a Temporal subclass.
+ * This method check if the givenEObject is a Temporal and if the feature is from a Temporal
+ * subclass.
*
* @param givenEObject
* @param feature
@@ -256,10 +273,9 @@ public class TemporalEStoreHandler {
private static boolean isTemporalFeature(EObject givenEObject, EStructuralFeature feature) {
if (givenEObject instanceof Temporal) {
/**
- * JCC: added this to support versioning of containment features.
- * containment setter / getters must trigger versioning, however there are no
- * feature for the container attribute of the EObjectImpl.
- * Note: I should rename isTemporalFeatureOnContinuity to isFeatureOnContinuity
+ * JCC: added this to support versioning of containment features. containment setter / getters
+ * must trigger versioning, however there are no feature for the container attribute of the
+ * EObjectImpl. Note: I should rename isTemporalFeatureOnContinuity to isFeatureOnContinuity
*/
if (feature == null || !isFeatureFromTemporalBaseClass(givenEObject, feature)) {
return true;
@@ -269,18 +285,20 @@ public class TemporalEStoreHandler {
}
/**
- * This method determines if the feature on the given EObject is on the continuity. It checks if the feature is an
- * attribute of Temporal derived classes but not one of the Temporal base class itself. These are used internally
- * and are not versionned. For example features like "date", "versionHolder" from the Temporal class should not
- * trigger versionning. However features like "brand", "nbDoors" from the Car class should trigger versionning. This
- * method determins if the feature is temporal "brand", temporal "nbDoor" on a continuity.
+ * This method determines if the feature on the given EObject is on the continuity. It checks if
+ * the feature is an attribute of Temporal derived classes but not one of the Temporal base class
+ * itself. These are used internally and are not versionned. For example features like "date",
+ * "versionHolder" from the Temporal class should not trigger versionning. However features like
+ * "brand", "nbDoors" from the Car class should trigger versionning. This method determins if the
+ * feature is temporal "brand", temporal "nbDoor" on a continuity.
*
* @param givenEObject
* @param feature
* @return
*/
private static boolean isFeatureOnContinuity(EObject givenEObject, EStructuralFeature feature) {
- // Check if the givenEObject is a Temporal and the requests is for a feature from a Temporal subclass.
+ // Check if the givenEObject is a Temporal and the requests is for a feature from a Temporal
+ // subclass.
if (isTemporalFeature(givenEObject, feature)) {
// Check if we are dealing with the continuity object.
// We don't want to do anything special with the getters and setters of
@@ -298,38 +316,40 @@ public class TemporalEStoreHandler {
}
/**
- * Finds the version to apply the accessor request to (a getter). This method uses the current date and the
- * granularity to find to which version the getter request should be forwarded to.
+ * Finds the version to apply the accessor request to (a getter). This method uses the current
+ * date and the granularity to find to which version the getter request should be forwarded to.
*
* @param givenEObject
* @param feature
* @return
*/
- public static InternalEObject findVersionToDelegateAccessorTo(EObject givenEObject, EStructuralFeature feature) {
+ public static InternalEObject findVersionToDelegateAccessorTo(EObject givenEObject,
+ EStructuralFeature feature) {
InternalEObject versionToDelegateTo = null;
if (isFeatureOnContinuity(givenEObject, feature)) {
Temporal continuity = (Temporal) givenEObject;
// Forward the request to the appropriate version.
Temporal temporalObjectAtNow = continuity.currentVersion();
// If we get back null from currentVersion it means we are pass the oldest version.
- if( temporalObjectAtNow == null){
+ if (temporalObjectAtNow == null) {
versionToDelegateTo = (InternalEObject) createPrimordialVersion(continuity);
}
// Make sure the version we get back is not in fact the continuity.
- else if(temporalObjectAtNow != continuity) {
+ else if (temporalObjectAtNow != continuity) {
// Ok, it is a versioned object.
- versionToDelegateTo = (InternalEObject)temporalObjectAtNow;
+ versionToDelegateTo = (InternalEObject) temporalObjectAtNow;
}
- // else it is the continuity (returning null will forward processing to continuity).
+ // else it is the continuity (returning null will forward processing to continuity).
}
return versionToDelegateTo;
}
/**
- * When the requested accessor is for a date before any already existing versions we will
- * create a version to forward the accessor to it. The accessor will thus effectively return the
- * default value. When a mutator is invoked at this given time it will affect the version we
- * are creating here.
+ * When the requested accessor is for a date before any already existing versions we will create a
+ * version to forward the accessor to it. The accessor will thus effectively return the default
+ * value. When a mutator is invoked at this given time it will affect the version we are creating
+ * here.
+ *
* @param continuity
*/
private static Temporal createPrimordialVersion(Temporal continuity) {
@@ -344,32 +364,34 @@ public class TemporalEStoreHandler {
// be ready to accept mutators.
newVersion.eSet(TemporalPackage.eINSTANCE.getTemporal_Date(), TemporalUtil.getTrimedNow());
- // Remove the version holder by containment reference it is only needed by the continuity for persistence reasons.
+ // Remove the version holder by containment reference it is only needed by the continuity for
+ // persistence reasons.
newVersion.eSet(TemporalPackage.eINSTANCE.getTemporal_VersionHolderContainment(), null);
newVersion.eSet(TemporalPackage.eINSTANCE.getTemporal_VersionHolder(), null);
-
+
// Add the newly created version to the versionHolder at the end of the list.
EList versions = continuity.versions();
int insertIndex = versions.size();
versions.add(insertIndex, newVersion);
Resource resource = continuity.eResource();
- if(resource != null){
+ if (resource != null) {
resource.getContents().add(newVersion);
}
-
+
return newVersion;
}
/**
- * Finds a version to apply the mutator (setter) to. It uses the current date and the granularity of the temporal to
- * determine to which version to forward the setter request to.
+ * Finds a version to apply the mutator (setter) to. It uses the current date and the granularity
+ * of the temporal to determine to which version to forward the setter request to.
*
* @param givenEObject
* @param feature
* @return
*/
- public static InternalEObject findVersionToDelegateMutatorTo(EObject givenEObject, EStructuralFeature feature) {
+ public static InternalEObject findVersionToDelegateMutatorTo(EObject givenEObject,
+ EStructuralFeature feature) {
InternalEObject versionToDelegateTo = null;
if (isFeatureOnContinuity(givenEObject, feature)) {
Temporal continuityTemporal = (Temporal) givenEObject;
@@ -381,8 +403,7 @@ public class TemporalEStoreHandler {
// Now test if the version we found will work or if we will need to create a new version.
if (temporalObjectAtNow != null && temporalObjectAtNow.isDateWithinVersion(currentNowDate)) {
versionToDelegateTo = (InternalEObject) temporalObjectAtNow;
- }
- else {
+ } else {
// The current now date is outside any of our versioned objects.
// Lets create a new version object and copy the modifications
// made in the continuity to the newly created version object.
@@ -403,16 +424,17 @@ public class TemporalEStoreHandler {
}
/**
- * This method propagates the values being set on the startVersion object. It makes sure not to affect the touched
- * flags of the subsequent versions. It also makes sure to stop propagating this value when it encounters a version
- * that was already set explicitly by the user.
+ * This method propagates the values being set on the startVersion object. It makes sure not to
+ * affect the touched flags of the subsequent versions. It also makes sure to stop propagating
+ * this value when it encounters a version that was already set explicitly by the user.
*
* @param startVersion
* @param feature
* @param index
* @param value
*/
- private static void propagateSetToNextVersions(EObject startVersion, EStructuralFeature feature, int index, Object value) {
+ private static void propagateSetToNextVersions(EObject startVersion, EStructuralFeature feature,
+ int index, Object value) {
EList versions = ((Temporal) startVersion).versions();
// Start at version just after the one being edited.
int versionIndex = versions.indexOf(startVersion) - 1;
@@ -420,8 +442,7 @@ public class TemporalEStoreHandler {
InternalEObject version = (InternalEObject) versions.get(versionIndex);
if (isTouchedAttribute(version, feature) == false) {
nextEStore(version).set(version, feature, -1, value);
- }
- else {
+ } else {
break;
}
versionIndex--;
@@ -451,12 +472,13 @@ public class TemporalEStoreHandler {
return givenEObject.eGet(feature);
}
- private static EStore nextEStore(EObject givenEObject){
- TemporalEStoreImpl temporalEStore = (TemporalEStoreImpl) ((InternalEObject) givenEObject).eStore();
+ private static EStore nextEStore(EObject givenEObject) {
+ TemporalEStoreImpl temporalEStore = (TemporalEStoreImpl) ((InternalEObject) givenEObject)
+ .eStore();
EStore nextEStore = temporalEStore.getNext();
return nextEStore;
}
-
+
private static final EClass temporalEClass = TemporalPackage.eINSTANCE.getTemporal();
private static final TemporalDateProvider temporalDateProvider = TemporalDateProvider.eINSTANCE;

Back to the top