1 11 package org.eclipse.pde.internal.ui.compare; 12 13 import org.eclipse.compare.CompareUI; 14 import org.eclipse.compare.ITypedElement; 15 import org.eclipse.compare.structuremergeviewer.DocumentRangeNode; 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.swt.graphics.Image; 18 19 22 public class XMLNode extends DocumentRangeNode implements ITypedElement { 23 24 private String fValue; 25 private String fName; 26 private String fSignature; 27 private String fOrigId; 28 private XMLNode parent; 29 private String fXMLType; 30 private boolean fUsesIDMAP; 31 32 public int bodies; 34 public XMLNode(String XMLType, String id, String value, String signature, IDocument doc, int start, int length) { 35 super(0, id, doc, start, length); 36 fXMLType= XMLType; 37 fValue= value; 38 fSignature= signature; 39 fOrigId= id; 40 if (XMLStructureCreator.DEBUG_MODE) 41 System.out.println("Created XMLNode with XMLType: " + XMLType + ", id: " + id + ", value: " + value + ", signature: " + fSignature); bodies= 0; 43 fUsesIDMAP= false; 44 } 45 46 void setValue(String value) { 47 fValue= value; 48 } 49 50 String getValue() { 51 return fValue; 52 } 53 54 57 public String getName() { 58 if (fName != null) 59 return fName; 60 return this.getId(); 61 } 62 63 public void setName(String name) { 64 fName= name; 65 } 66 67 71 public String getType() { 72 return "xml"; } 74 75 76 79 public Image getImage() { 80 return CompareUI.getImage(XMLStructureMapping.getImageKey(getXMLType())); 81 } 82 83 public void setParent(XMLNode parent0) { 84 this.parent= parent0; 85 } 86 87 public XMLNode getParent() { 88 return this.parent; 89 } 90 91 String getXMLType() { 92 return fXMLType; 93 } 94 95 String getSignature() { 96 return fSignature; 97 } 98 99 void setOrigId(String id) { 100 fOrigId= id; 101 } 102 103 public String getOrigId() { 104 return fOrigId; 105 } 106 107 public void setUsesIDMAP(boolean b) { 108 fUsesIDMAP= b; 109 } 110 111 public boolean usesIDMAP() { 112 return fUsesIDMAP; 113 } 114 115 public boolean testEquals(Object obj) { 117 if (obj instanceof XMLNode) { 118 XMLNode n= (XMLNode) obj; 119 return fValue.equals(n.getValue()) 120 && fSignature.equals(n.getSignature()) 121 && fXMLType.equals(n.getXMLType()) 122 && fUsesIDMAP == n.usesIDMAP(); 123 } 124 return false; 125 } 126 127 130 public boolean subtreeEquals(Object obj) { 131 if (!testEquals(obj)) 132 return false; 133 if (obj instanceof XMLNode) { 134 XMLNode n= (XMLNode) obj; 135 if (getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE) 136 && n.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) 137 return true; 138 Object [] children= getChildren(); 139 Object [] n_children= n.getChildren(); 140 if ((children == null || children.length <= 0) 142 && (n_children == null || n_children.length <= 0)) 143 return true; 144 148 if ((children == null || children.length <= 0) 149 || (n_children == null || n_children.length <= 0) 150 || (children.length != n_children.length)) 151 return false; 152 for (int i= 0; i < children.length; i++) { 154 157 if (!((XMLNode) children[i]).subtreeEquals(n_children[i])) 158 return false; 159 } 160 } 161 return true; 162 } 163 } 164 | Popular Tags |