1 16 17 package org.apache.xerces.impl.xs.identity; 18 19 import org.apache.xerces.xs.XSIDCDefinition; 20 import org.apache.xerces.xs.StringList; 21 import org.apache.xerces.xs.XSNamespaceItem; 22 import org.apache.xerces.xs.XSObjectList; 23 import org.apache.xerces.xs.XSConstants; 24 import org.apache.xerces.impl.xs.util.StringListImpl; 25 import org.apache.xerces.impl.xs.util.XSObjectListImpl; 26 import org.apache.xerces.impl.xs.XSAnnotationImpl; 27 28 36 public abstract class IdentityConstraint implements XSIDCDefinition { 37 38 42 43 protected short type; 44 45 46 protected String fNamespace; 47 48 49 protected String fIdentityConstraintName; 50 51 52 protected String fElementName; 53 54 55 protected Selector fSelector; 56 57 58 protected int fFieldCount; 59 60 61 protected Field[] fFields; 62 63 protected XSAnnotationImpl [] fAnnotations = null; 65 66 protected int fNumAnnotations; 68 69 73 74 protected IdentityConstraint(String namespace, String identityConstraintName, String elemName) { 75 fNamespace = namespace; 76 fIdentityConstraintName = identityConstraintName; 77 fElementName = elemName; 78 } 80 84 85 public String getIdentityConstraintName() { 86 return fIdentityConstraintName; 87 } 89 90 public void setSelector(Selector selector) { 91 fSelector = selector; 92 } 94 95 public Selector getSelector() { 96 return fSelector; 97 } 99 100 public void addField(Field field) { 101 if (fFields == null) 102 fFields = new Field[4]; 103 else if (fFieldCount == fFields.length) 104 fFields = resize(fFields, fFieldCount*2); 105 fFields[fFieldCount++] = field; 106 } 108 109 public int getFieldCount() { 110 return fFieldCount; 111 } 113 114 public Field getFieldAt(int index) { 115 return fFields[index]; 116 } 118 public String getElementName () { 120 return fElementName; 121 } 123 127 128 public String toString() { 129 String s = super.toString(); 130 int index1 = s.lastIndexOf('$'); 131 if (index1 != -1) { 132 return s.substring(index1 + 1); 133 } 134 int index2 = s.lastIndexOf('.'); 135 if (index2 != -1) { 136 return s.substring(index2 + 1); 137 } 138 return s; 139 } 141 public boolean equals(IdentityConstraint id) { 145 boolean areEqual = fIdentityConstraintName.equals(id.fIdentityConstraintName); 146 if(!areEqual) return false; 147 areEqual = fSelector.toString().equals(id.fSelector.toString()); 148 if(!areEqual) return false; 149 areEqual = (fFieldCount == id.fFieldCount); 150 if(!areEqual) return false; 151 for(int i=0; i<fFieldCount; i++) 152 if(!fFields[i].toString().equals(id.fFields[i].toString())) return false; 153 return true; 154 } 156 static final Field[] resize(Field[] oldArray, int newSize) { 157 Field[] newArray = new Field[newSize]; 158 System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); 159 return newArray; 160 } 161 162 165 public short getType() { 166 return XSConstants.IDENTITY_CONSTRAINT; 167 } 168 169 173 public String getName() { 174 return fIdentityConstraintName; 175 } 176 177 182 public String getNamespace() { 183 return fNamespace; 184 } 185 186 189 public short getCategory() { 190 return type; 191 } 192 193 196 public String getSelectorStr() { 197 return (fSelector != null) ? fSelector.toString() : null; 198 } 199 200 203 public StringList getFieldStrs() { 204 String [] strs = new String [fFieldCount]; 205 for (int i = 0; i < fFieldCount; i++) 206 strs[i] = fFields[i].toString(); 207 return new StringListImpl(strs, fFieldCount); 208 } 209 210 215 public XSIDCDefinition getRefKey() { 216 return null; 217 } 218 219 222 public XSObjectList getAnnotations() { 223 return new XSObjectListImpl(fAnnotations, fNumAnnotations); 224 } 225 226 229 public XSNamespaceItem getNamespaceItem() { 230 return null; 232 } 233 234 public void addAnnotation(XSAnnotationImpl annotation) { 235 if(annotation == null) 236 return; 237 if(fAnnotations == null) { 238 fAnnotations = new XSAnnotationImpl[2]; 239 } else if(fNumAnnotations == fAnnotations.length) { 240 XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1]; 241 System.arraycopy(fAnnotations, 0, newArray, 0, fNumAnnotations); 242 fAnnotations = newArray; 243 } 244 fAnnotations[fNumAnnotations++] = annotation; 245 } 246 247 } | Popular Tags |