1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.betwixt.schema;
20
21 import java.io.PrintStream;
22 import java.util.Iterator;
23
24
25
26
27
28
29
30 public class SchemaDiff {
31
32 private PrintStream out;
33
34 public SchemaDiff() {
35 this(System.err);
36 }
37
38 public SchemaDiff(PrintStream out) {
39 this.out = out;
40 }
41
42 public void printDifferences(Schema one, Schema two) {
43 for( Iterator it=one.getComplexTypes().iterator();it.hasNext(); ) {
44 GlobalComplexType complexType = (GlobalComplexType)it.next();
45 if (!two.getComplexTypes().contains(complexType)) {
46 boolean matched = false;
47 for (Iterator otherIter=two.getComplexTypes().iterator(); it.hasNext();) {
48 GlobalComplexType otherType = (GlobalComplexType) otherIter.next();
49 if (otherType.getName().equals(complexType.getName())) {
50 printDifferences(complexType, otherType);
51 matched = true;
52 break;
53 }
54 }
55 if (!matched) {
56 out.println("Missing Complex type: " + complexType);
57 }
58 }
59 }
60
61 }
62
63 public void printDifferences(GlobalComplexType one, GlobalComplexType two) {
64 out.println("Type " + one + " is not equal to " + two);
65 for (Iterator it = one.getElements().iterator(); it.hasNext();) {
66 Element elementOne = (Element) it.next();
67 if (!two.getElements().contains(elementOne)) {
68 boolean matched = false;
69 for (Iterator otherIter=two.getElements().iterator(); it.hasNext();) {
70 Element elementTwo = (Element) otherIter.next();
71 if (elementOne.getName().equals(elementTwo.getName())) {
72 printDifferences(elementOne, elementTwo);
73 matched = true;
74 break;
75 }
76 }
77 if (!matched) {
78 out.println("Missing Element: " + elementOne);
79 }
80 }
81 }
82 for (Iterator it = one.getAttributes().iterator(); it.hasNext();) {
83 Attribute attributeOne = (Attribute) it.next();
84 if (!two.getAttributes().contains(attributeOne)) {
85 boolean matched = false;
86 for (Iterator otherIter=two.getAttributes().iterator(); it.hasNext();) {
87 Attribute attributeTwo = (Attribute) otherIter.next();
88 if (attributeTwo.getName().equals(attributeTwo.getName())) {
89 printDifferences(attributeOne, attributeTwo);
90 matched = true;
91 break;
92 }
93 }
94 if (!matched) {
95 out.println("Missing Attribute: " + attributeOne);
96 }
97 }
98 }
99 }
100
101 private void printDifferences(Attribute one , Attribute two) {
102 out.println("Attribute " + one + " is not equals to " + two);
103 }
104
105 private void printDifferences(Element one , Element two) {
106 out.println("Element " + one + " is not equals to " + two);
107 }
108 }