View Javadoc
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.connect.versioning;
17  
18  import javax.jcr.Item;
19  
20  import org.argeo.connect.ConnectException;
21  
22  /** The result of the comparison of two JCR items. */
23  public class ItemDiff {
24  
25  	public final static Integer MODIFIED = 0;
26  	public final static Integer ADDED = 1;
27  	public final static Integer REMOVED = 2;
28  
29  	private final Integer type;
30  	private final String relPath;
31  	private final Item referenceItem;
32  	private final Item observedItem;
33  
34  	/**
35  	 * 
36  	 * @param type
37  	 * @param relPath
38  	 * @param referenceItem
39  	 * @param observedItem
40  	 */
41  	public ItemDiff(Integer type, String relPath, Item referenceItem, Item observedItem) {
42  		if (type == MODIFIED) {
43  			if (referenceItem == null || observedItem == null)
44  				throw new ConnectException("Reference and new items must be specified.");
45  		} else if (type == ADDED) {
46  			if (referenceItem != null || observedItem == null)
47  				throw new ConnectException("New item and only it must be specified.");
48  		} else if (type == REMOVED) {
49  			if (referenceItem == null || observedItem != null)
50  				throw new ConnectException("Reference item and only it must be specified.");
51  		} else {
52  			throw new ConnectException("Unkown diff type " + type);
53  		}
54  
55  		if (relPath == null)
56  			throw new ConnectException("Relative path must be specified");
57  
58  		this.type = type;
59  		this.relPath = relPath;
60  		this.referenceItem = referenceItem;
61  		this.observedItem = observedItem;
62  	}
63  
64  	public Integer getType() {
65  		return type;
66  	}
67  
68  	public String getRelPath() {
69  		return relPath;
70  	}
71  
72  	public Item getReferenceItem() {
73  		return referenceItem;
74  	}
75  
76  	public Item getObservedItem() {
77  		return observedItem;
78  	}
79  
80  }