View Javadoc
1 /*
2 * Copyright (c) 2003 Scott Howlett & Paul Libbrecht.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. The end-user documentation included with the redistribution,
18 * if any, must include the following acknowledgment:
19 * "This product includes software developed by the Xwing
20 * Project ( http://xwing.sourceforge.net/ )."
21 * Alternately, this acknowledgment may appear in the software itself,
22 * if and wherever such third-party acknowledgments normally appear.
23 *
24 * 4. The name "Xwing" must not be used to endorse or promote products
25 * derived from this software without prior written permission. For
26 * written permission, please contact the project authors via
27 * the Xwing project site, http://xwing.sourceforge.net/ .
28 *
29 * 5. Products derived from this software may not be called "Xwing",
30 * nor may "Xwing" appear in their name, without prior written
31 * permission of the Xwing project.
32 *
33 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36 * DISCLAIMED. IN NO EVENT SHALL THE XWING AUTHORS OR THE PROJECT
37 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
40 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
43 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * SUCH DAMAGE.
45 *
46 * For more information on Xwing, please see
47 * < http://xwing.sourceforge.net/ >.
48 */
49
50 package net.sourceforge.xwing.dom;
51
52 import java.util.Vector;
53
54 public class ChangeInfo {
55
56 public static final int SAME = 0;
57 public static final int ADDS = 1;
58 public static final int DELETES = 2;
59 public static final int COMPLEX = 3;
60
61 private XTreeNode changeRoot;
62 private XTreeNode newChangeRoot;
63 private int status;
64 private int[] childIndices;
65 private Object[] children;
66 private Vector contentChanges;
67
68 public ChangeInfo(
69 XTreeNode pChangeRoot,
70 XTreeNode pNewChangeRoot,
71 int pStatus) {
72 changeRoot = pChangeRoot;
73 newChangeRoot = pNewChangeRoot;
74 status = pStatus;
75 childIndices = null;
76 children = null;
77 contentChanges = null;
78 }
79
80 public ChangeInfo(
81 XTreeNode pChangeRoot,
82 XTreeNode pNewChangeRoot,
83 int pStatus,
84 int[] pChildIndices,
85 Object[] pChildren) {
86 changeRoot = pChangeRoot;
87 newChangeRoot = pNewChangeRoot;
88 status = pStatus;
89 childIndices = pChildIndices;
90 children = pChildren;
91 }
92
93 public XTreeNode getChangeRoot() {
94 return changeRoot;
95 }
96
97 public XTreeNode getNewChangeRoot() {
98 return newChangeRoot;
99 }
100
101 public int[] getChildIndices() {
102 return childIndices;
103 }
104
105 public int getStatus() {
106 return status;
107 }
108
109 public Object[] getChildren() {
110 return children;
111 }
112
113 public Vector getContentChanges() {
114 return contentChanges;
115 }
116
117 public void merge(ChangeInfo other) {
118 if (status == ChangeInfo.COMPLEX) {
119 return;
120 }
121
122 if (other.status != ChangeInfo.SAME) {
123 if (status != ChangeInfo.SAME) {
124 status = ChangeInfo.COMPLEX;
125 childIndices = null;
126 children = null;
127 return;
128 }
129 status = other.status;
130 children = other.children;
131 childIndices = other.childIndices;
132 changeRoot = other.changeRoot;
133 newChangeRoot = other.newChangeRoot;
134 }
135
136 if (other.contentChanges != null) {
137 if (contentChanges == null) {
138 contentChanges = other.contentChanges;
139 } else {
140 contentChanges.addAll(other.contentChanges);
141 }
142 }
143
144 }
145
146 public void addContentChange(
147 XTreeNode parent,
148 int[] indices,
149 Object[] changeNodes) {
150 if (contentChanges == null) {
151 contentChanges = new Vector();
152 }
153 contentChanges.add(
154 new ChangeInfo(
155 parent,
156 null,
157 ChangeInfo.SAME,
158 indices,
159 changeNodes));
160
161 }
162 }
This page was automatically generated by Maven