Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2012-07-25 11:32:27 -0400
committerGlyn Normington2012-07-25 11:32:27 -0400
commit241a19ac499d70569545ad3d386530ef2fbdb864 (patch)
treecc4281486b518de06e89ddd6c7d4f538143205b4
parent72f68d8f08f27e8e82c214c093a68a76c642321d (diff)
downloadorg.eclipse.virgo.kernel-241a19ac499d70569545ad3d386530ef2fbdb864.tar.gz
org.eclipse.virgo.kernel-241a19ac499d70569545ad3d386530ef2fbdb864.tar.xz
org.eclipse.virgo.kernel-241a19ac499d70569545ad3d386530ef2fbdb864.zip
385743: introduce abstract superclass
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractPathGenerator.java35
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java28
2 files changed, 44 insertions, 19 deletions
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractPathGenerator.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractPathGenerator.java
new file mode 100644
index 00000000..c8a750af
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractPathGenerator.java
@@ -0,0 +1,35 @@
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import org.eclipse.virgo.util.io.PathReference;
+
+public abstract class AbstractPathGenerator {
+
+ private boolean hasPrevious = false;
+
+ protected final Object monitor = new Object();
+
+ public abstract PathReference getCurrentPath();
+
+ public void next() {
+ synchronized (this.monitor) {
+ this.hasPrevious = true;
+ PathReference currentPathReference = getCurrentPath();
+ currentPathReference.getParent().createDirectory();
+ currentPathReference.delete(true);
+ }
+ }
+
+ public void previous() {
+ synchronized (this.monitor) {
+ if (!this.hasPrevious) {
+ throw new IllegalStateException("No previous path available");
+ }
+ getCurrentPath().delete(true);
+ this.hasPrevious = false;
+ }
+ }
+
+ protected abstract PathReference getPreviousPath();
+
+} \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java
index 54be3b9e..96cf31ca 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/install/artifact/internal/GenerationalPathGenerator.java
@@ -3,16 +3,12 @@ package org.eclipse.virgo.kernel.install.artifact.internal;
import org.eclipse.virgo.util.io.PathReference;
-final class GenerationalPathGenerator implements PathGenerator {
+final class GenerationalPathGenerator extends AbstractPathGenerator implements PathGenerator {
private final PathReference baseDirectory;
private long generation = 0;
- private boolean hasPrevious = false; // if true, then generation != 0
-
- private final Object monitor = new Object();
-
private final String baseName;
GenerationalPathGenerator(PathReference basePathReference) {
@@ -30,7 +26,7 @@ final class GenerationalPathGenerator implements PathGenerator {
currentPathReference.delete(true);
}
- /**
+ /**
* {@inheritDoc}
*/
public PathReference getCurrentPath() {
@@ -39,38 +35,32 @@ final class GenerationalPathGenerator implements PathGenerator {
}
}
- /**
+ /**
* {@inheritDoc}
*/
+ @Override
public void next() {
synchronized (this.monitor) {
if (this.generation != 0) {
getPreviousPath().delete(true);
}
this.generation++;
- this.hasPrevious = true;
-
- PathReference currentPathReference = getCurrentPath();
- currentPathReference.getParent().createDirectory();
- currentPathReference.delete(true);
+ super.next();
}
}
- /**
+ /**
* {@inheritDoc}
*/
+ @Override
public void previous() {
synchronized (this.monitor) {
- if (!this.hasPrevious) {
- throw new IllegalStateException("No stash available");
- }
- getCurrentPath().delete(true);
+ super.previous();
this.generation--;
- this.hasPrevious = false;
}
}
- private PathReference getPreviousPath() {
+ protected PathReference getPreviousPath() {
return getGenerationPath(this.generation - 1);
}

Back to the top