1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.identity; 59 60 import com.sun.org.apache.xerces.internal.xs.XSIDCDefinition; 61 import com.sun.org.apache.xerces.internal.xs.StringList; 62 import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem; 63 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 64 import com.sun.org.apache.xerces.internal.xs.XSConstants; 65 import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl; 66 import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 67 import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl; 68 69 75 public abstract class IdentityConstraint implements XSIDCDefinition { 76 77 81 82 protected short type; 83 84 85 protected String fNamespace; 86 87 88 protected String fIdentityConstraintName; 89 90 91 protected String fElementName; 92 93 94 protected Selector fSelector; 95 96 97 protected int fFieldCount; 98 99 100 protected Field[] fFields; 101 102 protected XSAnnotationImpl [] fAnnotations = null; 104 105 protected int fNumAnnotations; 107 108 112 113 protected IdentityConstraint(String namespace, String identityConstraintName, String elemName) { 114 fNamespace = namespace; 115 fIdentityConstraintName = identityConstraintName; 116 fElementName = elemName; 117 } 119 123 124 public String getIdentityConstraintName() { 125 return fIdentityConstraintName; 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 if (fFields == null) 141 fFields = new Field[4]; 142 else if (fFieldCount == fFields.length) 143 fFields = resize(fFields, fFieldCount*2); 144 fFields[fFieldCount++] = field; 145 } 147 148 public int getFieldCount() { 149 return fFieldCount; 150 } 152 153 public Field getFieldAt(int index) { 154 return fFields[index]; 155 } 157 public String getElementName () { 159 return fElementName; 160 } 162 166 167 public String toString() { 168 String s = super.toString(); 169 int index1 = s.lastIndexOf('$'); 170 if (index1 != -1) { 171 return s.substring(index1 + 1); 172 } 173 int index2 = s.lastIndexOf('.'); 174 if (index2 != -1) { 175 return s.substring(index2 + 1); 176 } 177 return s; 178 } 180 public boolean equals(IdentityConstraint id) { 184 boolean areEqual = fIdentityConstraintName.equals(id.fIdentityConstraintName); 185 if(!areEqual) return false; 186 areEqual = fSelector.toString().equals(id.fSelector.toString()); 187 if(!areEqual) return false; 188 areEqual = (fFieldCount == id.fFieldCount); 189 if(!areEqual) return false; 190 for(int i=0; i<fFieldCount; i++) 191 if(!fFields[i].toString().equals(id.fFields[i].toString())) return false; 192 return true; 193 } 195 static final Field[] resize(Field[] oldArray, int newSize) { 196 Field[] newArray = new Field[newSize]; 197 System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); 198 return newArray; 199 } 200 201 204 public short getType() { 205 return XSConstants.IDENTITY_CONSTRAINT; 206 } 207 208 212 public String getName() { 213 return fIdentityConstraintName; 214 } 215 216 221 public String getNamespace() { 222 return fNamespace; 223 } 224 225 228 public short getCategory() { 229 return type; 230 } 231 232 235 public String getSelectorStr() { 236 return fSelector.toString(); 237 } 238 239 242 public StringList getFieldStrs() { 243 String [] strs = new String [fFieldCount]; 244 for (int i = 0; i < fFieldCount; i++) 245 strs[i] = fFields[i].toString(); 246 return new StringListImpl(strs, fFieldCount); 247 } 248 249 254 public XSIDCDefinition getRefKey() { 255 return null; 256 } 257 258 261 public XSObjectList getAnnotations() { 262 return new XSObjectListImpl(fAnnotations, fNumAnnotations); 263 } 264 265 268 public XSNamespaceItem getNamespaceItem() { 269 return null; 271 } 272 273 public void addAnnotation(XSAnnotationImpl annotation) { 274 if(annotation == null) 275 return; 276 if(fAnnotations == null) { 277 fAnnotations = new XSAnnotationImpl[2]; 278 } else if(fNumAnnotations == fAnnotations.length) { 279 XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1]; 280 System.arraycopy(fAnnotations, 0, newArray, 0, fNumAnnotations); 281 fAnnotations = newArray; 282 } 283 fAnnotations[fNumAnnotations++] = annotation; 284 } 285 286 } | Popular Tags |