1 57 58 package org.enhydra.apache.xerces.validators.schema.identity; 59 60 66 public abstract class IdentityConstraint { 67 68 72 73 public static final short UNIQUE = 0; 74 75 76 public static final short KEY = 1; 77 78 79 public static final short KEYREF = 2; 80 81 85 86 protected String fIdentityConstraintName; 87 88 89 protected String fElementName; 90 91 92 protected Selector fSelector; 93 94 95 protected int fFieldCount; 96 97 98 protected Field[] fFields; 99 100 104 105 protected IdentityConstraint(String identityConstraintName, 106 String elementName) { 107 fIdentityConstraintName = identityConstraintName; 108 fElementName = elementName; 109 } 111 115 116 public abstract short getType(); 117 118 119 public String getIdentityConstraintName() { 120 return fIdentityConstraintName; 121 } 123 124 public String getElementName() { 125 return fElementName; 126 } 128 129 public void setSelector(Selector selector) { 130 fSelector = selector; 131 } 133 134 public Selector getSelector() { 135 return fSelector; 136 } 138 139 public void addField(Field field) { 140 try { 141 fFields[fFieldCount] = null; 142 } 143 catch (NullPointerException e) { 144 fFields = new Field[4]; 145 } 146 catch (ArrayIndexOutOfBoundsException e) { 147 Field[] newfields = new Field[fFields.length * 2]; 148 System.arraycopy(fFields, 0, newfields, 0, fFields.length); 149 fFields = newfields; 150 } 151 fFields[fFieldCount++] = field; 152 } 154 155 public int getFieldCount() { 156 return fFieldCount; 157 } 159 160 public Field getFieldAt(int index) { 161 return fFields[index]; 162 } 164 168 169 public String toString() { 170 String s = super.toString(); 171 int index1 = s.lastIndexOf('$'); 172 if (index1 != -1) { 173 return s.substring(index1 + 1); 174 } 175 int index2 = s.lastIndexOf('.'); 176 if (index2 != -1) { 177 return s.substring(index2 + 1); 178 } 179 return s; 180 } 182 public boolean equals(IdentityConstraint id) { 186 boolean areEqual = fIdentityConstraintName.equals(id.fIdentityConstraintName); 187 if(!areEqual) return false; 188 areEqual = fSelector.toString().equals(id.fSelector.toString()); 189 if(!areEqual) return false; 190 areEqual = (fFieldCount == id.fFieldCount); 191 if(!areEqual) return false; 192 for(int i=0; i<fFieldCount; i++) 193 if(!fFields[i].toString().equals(id.fFields[i].toString())) return false; 194 return true; 195 } 197 } | Popular Tags |