]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/PropertyDiff.java
Improve JCR utils
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.jcr / src / main / java / org / argeo / jcr / PropertyDiff.java
diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/PropertyDiff.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/PropertyDiff.java
new file mode 100644 (file)
index 0000000..67e5d8a
--- /dev/null
@@ -0,0 +1,63 @@
+package org.argeo.jcr;
+
+import javax.jcr.Value;
+
+import org.argeo.ArgeoException;
+
+/** The result of the comparison of two JCR properties. */
+public class PropertyDiff {
+       public final static Integer MODIFIED = 0;
+       public final static Integer ADDED = 1;
+       public final static Integer REMOVED = 2;
+
+       private final Integer type;
+       private final String relPath;
+       private final Value referenceValue;
+       private final Value newValue;
+
+       public PropertyDiff(Integer type, String relPath, Value referenceValue,
+                       Value newValue) {
+               super();
+
+               if (type == MODIFIED) {
+                       if (referenceValue == null || newValue == null)
+                               throw new ArgeoException(
+                                               "Reference and new values must be specified.");
+               } else if (type == ADDED) {
+                       if (referenceValue != null || newValue == null)
+                               throw new ArgeoException(
+                                               "New value and only it must be specified.");
+               } else if (type == REMOVED) {
+                       if (referenceValue == null || newValue != null)
+                               throw new ArgeoException(
+                                               "Reference value and only it must be specified.");
+               } else {
+                       throw new ArgeoException("Unkown diff type " + type);
+               }
+
+               if (relPath == null)
+                       throw new ArgeoException("Relative path must be specified");
+
+               this.type = type;
+               this.relPath = relPath;
+               this.referenceValue = referenceValue;
+               this.newValue = newValue;
+       }
+
+       public Integer getType() {
+               return type;
+       }
+
+       public String getRelPath() {
+               return relPath;
+       }
+
+       public Value getReferenceValue() {
+               return referenceValue;
+       }
+
+       public Value getNewValue() {
+               return newValue;
+       }
+
+}