1 16 17 package org.apache.xerces.impl.dtd.models; 18 19 import org.apache.xerces.xni.QName; 20 21 import org.apache.xerces.impl.dtd.XMLContentSpec; 22 23 47 public class SimpleContentModel 48 implements ContentModelValidator { 49 50 54 55 public static final short CHOICE = -1; 56 57 58 public static final short SEQUENCE = -1; 59 60 64 65 70 private QName fFirstChild = new QName(); 71 72 77 private QName fSecondChild = new QName(); 78 79 85 private int fOperator; 86 87 88 90 91 95 103 public SimpleContentModel(short operator, QName firstChild, QName secondChild) { 104 fFirstChild.setValues(firstChild); 111 if (secondChild != null) { 112 fSecondChild.setValues(secondChild); 113 } 114 else { 115 fSecondChild.clear(); 116 } 117 fOperator = operator; 118 } 119 120 124 147 public int validate(QName[] children, int offset, int length) { 148 149 switch(fOperator) 154 { 155 case XMLContentSpec.CONTENTSPECNODE_LEAF : 156 if (length == 0) 158 return 0; 159 160 if (children[offset].rawname != fFirstChild.rawname) { 162 return 0; 163 } 164 165 if (length > 1) 167 return 1; 168 break; 169 170 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE : 171 if (length == 1) { 176 if (children[offset].rawname != fFirstChild.rawname) { 177 return 0; 178 } 179 } 180 181 if (length > 1) 186 return 1; 187 break; 188 189 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE : 190 if (length > 0) 197 { 198 for (int index = 0; index < length; index++) { 199 if (children[offset + index].rawname != fFirstChild.rawname) { 200 return index; 201 } 202 } 203 } 204 break; 205 206 case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE : 207 if (length == 0) 212 return 0; 213 214 for (int index = 0; index < length; index++) { 220 if (children[offset + index].rawname != fFirstChild.rawname) { 221 return index; 222 } 223 } 224 break; 225 226 case XMLContentSpec.CONTENTSPECNODE_CHOICE : 227 if (length == 0) 232 return 0; 233 234 if ((children[offset].rawname != fFirstChild.rawname) && 236 (children[offset].rawname != fSecondChild.rawname)) { 237 return 0; 238 } 239 240 if (length > 1) 242 return 1; 243 break; 244 245 case XMLContentSpec.CONTENTSPECNODE_SEQ : 246 if (length == 2) { 251 if (children[offset].rawname != fFirstChild.rawname) { 252 return 0; 253 } 254 if (children[offset + 1].rawname != fSecondChild.rawname) { 255 return 1; 256 } 257 } 258 else { 259 if (length > 2) { 260 return 2; 261 } 262 263 return length; 264 } 265 266 break; 267 268 default : 269 throw new RuntimeException ("ImplementationMessages.VAL_CST"); 270 } 271 272 return -1; 274 } 276 } | Popular Tags |