1 57 58 package com.sun.org.apache.xerces.internal.impl.dtd.models; 59 60 import com.sun.org.apache.xerces.internal.xni.QName; 61 62 import com.sun.org.apache.xerces.internal.impl.dtd.XMLContentSpec; 63 64 87 public class SimpleContentModel 88 implements ContentModelValidator { 89 90 94 95 public static final short CHOICE = -1; 96 97 98 public static final short SEQUENCE = -1; 99 100 104 105 110 private QName fFirstChild = new QName(); 111 112 117 private QName fSecondChild = new QName(); 118 119 125 private int fOperator; 126 127 128 130 131 135 144 public SimpleContentModel(short operator, QName firstChild, QName secondChild) { 145 fFirstChild.setValues(firstChild); 152 if (secondChild != null) { 153 fSecondChild.setValues(secondChild); 154 } 155 else { 156 fSecondChild.clear(); 157 } 158 fOperator = operator; 159 } 160 161 165 188 public int validate(QName[] children, int offset, int length) { 189 190 switch(fOperator) 195 { 196 case XMLContentSpec.CONTENTSPECNODE_LEAF : 197 if (length == 0) 199 return 0; 200 201 if (children[offset].rawname != fFirstChild.rawname) { 203 return 0; 204 } 205 206 if (length > 1) 208 return 1; 209 break; 210 211 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE : 212 if (length == 1) { 217 if (children[offset].rawname != fFirstChild.rawname) { 218 return 0; 219 } 220 } 221 222 if (length > 1) 227 return 1; 228 break; 229 230 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE : 231 if (length > 0) 238 { 239 for (int index = 0; index < length; index++) { 240 if (children[offset + index].rawname != fFirstChild.rawname) { 241 return index; 242 } 243 } 244 } 245 break; 246 247 case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE : 248 if (length == 0) 253 return 0; 254 255 for (int index = 0; index < length; index++) { 261 if (children[offset + index].rawname != fFirstChild.rawname) { 262 return index; 263 } 264 } 265 break; 266 267 case XMLContentSpec.CONTENTSPECNODE_CHOICE : 268 if (length == 0) 273 return 0; 274 275 if ((children[offset].rawname != fFirstChild.rawname) && 277 (children[offset].rawname != fSecondChild.rawname)) { 278 return 0; 279 } 280 281 if (length > 1) 283 return 1; 284 break; 285 286 case XMLContentSpec.CONTENTSPECNODE_SEQ : 287 if (length == 2) { 292 if (children[offset].rawname != fFirstChild.rawname) { 293 return 0; 294 } 295 if (children[offset + 1].rawname != fSecondChild.rawname) { 296 return 1; 297 } 298 } 299 else { 300 if (length > 2) { 301 return 2; 302 } 303 304 return length; 305 } 306 307 break; 308 309 default : 310 throw new RuntimeException ("ImplementationMessages.VAL_CST"); 311 } 312 313 return -1; 315 } 317 } | Popular Tags |