]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.server.jcr/newsrc/org/argeo/jcr/PropertyDiff.java
bdd316f31846f10e95a468992af24849af2260f4
[lgpl/argeo-commons.git] / org.argeo.server.jcr / newsrc / org / argeo / jcr / PropertyDiff.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.jcr;
17
18 import javax.jcr.Value;
19
20 import org.argeo.ArgeoException;
21
22 /** The result of the comparison of two JCR properties. */
23 public class PropertyDiff {
24 public final static Integer MODIFIED = 0;
25 public final static Integer ADDED = 1;
26 public final static Integer REMOVED = 2;
27
28 private final Integer type;
29 private final String relPath;
30 private final Value referenceValue;
31 private final Value newValue;
32
33 public PropertyDiff(Integer type, String relPath, Value referenceValue,
34 Value newValue) {
35 super();
36
37 if (type == MODIFIED) {
38 if (referenceValue == null || newValue == null)
39 throw new ArgeoException(
40 "Reference and new values must be specified.");
41 } else if (type == ADDED) {
42 if (referenceValue != null || newValue == null)
43 throw new ArgeoException(
44 "New value and only it must be specified.");
45 } else if (type == REMOVED) {
46 if (referenceValue == null || newValue != null)
47 throw new ArgeoException(
48 "Reference value and only it must be specified.");
49 } else {
50 throw new ArgeoException("Unkown diff type " + type);
51 }
52
53 if (relPath == null)
54 throw new ArgeoException("Relative path must be specified");
55
56 this.type = type;
57 this.relPath = relPath;
58 this.referenceValue = referenceValue;
59 this.newValue = newValue;
60 }
61
62 public Integer getType() {
63 return type;
64 }
65
66 public String getRelPath() {
67 return relPath;
68 }
69
70 public Value getReferenceValue() {
71 return referenceValue;
72 }
73
74 public Value getNewValue() {
75 return newValue;
76 }
77
78 }