1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.models; 59 60 import com.sun.org.apache.xerces.internal.xni.QName; 61 import com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl; 62 import com.sun.org.apache.xerces.internal.impl.xs.SubstitutionGroupHandler; 63 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaException; 64 import com.sun.org.apache.xerces.internal.impl.xs.XSConstraints; 65 66 import java.util.Vector ; 67 68 74 public class XSAllCM implements XSCMValidator { 75 76 80 private static final short STATE_START = 0; 82 private static final short STATE_VALID = 1; 83 private static final short STATE_CHILD = 1; 84 85 86 90 private XSElementDecl fAllElements[]; 91 private boolean fIsOptionalElement[]; 92 private boolean fHasOptionalContent = false; 93 private int fNumElements = 0; 94 95 99 public XSAllCM (boolean hasOptionalContent, int size) { 100 fHasOptionalContent = hasOptionalContent; 101 fAllElements = new XSElementDecl[size]; 102 fIsOptionalElement = new boolean[size]; 103 } 104 105 public void addElement (XSElementDecl element, boolean isOptional) { 106 fAllElements[fNumElements] = element; 107 fIsOptionalElement[fNumElements] = isOptional; 108 fNumElements++; 109 } 110 111 112 116 123 public int[] startContentModel() { 124 125 int[] state = new int[fNumElements + 1]; 126 127 for (int i = 0; i <= fNumElements; i++) { 128 state[i] = STATE_START; 129 } 130 return state; 131 } 132 133 Object findMatchingDecl(QName elementName, SubstitutionGroupHandler subGroupHandler) { 136 Object matchingDecl = null; 137 for (int i = 0; i < fNumElements; i++) { 138 matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, fAllElements[i]); 139 if (matchingDecl != null) 140 break; 141 } 142 return matchingDecl; 143 } 144 145 152 public Object oneTransition (QName elementName, int[] currentState, SubstitutionGroupHandler subGroupHandler) { 153 154 if (currentState[0] < 0) { 156 currentState[0] = XSCMValidator.SUBSEQUENT_ERROR; 157 return findMatchingDecl(elementName, subGroupHandler); 158 } 159 160 currentState[0] = STATE_CHILD; 162 163 Object matchingDecl = null; 164 165 for (int i = 0; i < fNumElements; i++) { 166 if (currentState[i+1] != STATE_START) 169 continue; 170 matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, fAllElements[i]); 171 if (matchingDecl != null) { 172 currentState[i+1] = STATE_VALID; 174 return matchingDecl; 175 } 176 } 177 178 currentState[0] = XSCMValidator.FIRST_ERROR; 180 return findMatchingDecl(elementName, subGroupHandler); 181 } 182 183 184 190 public boolean endContentModel (int[] currentState) { 191 192 int state = currentState[0]; 193 194 if (state == XSCMValidator.FIRST_ERROR || state == XSCMValidator.SUBSEQUENT_ERROR) { 195 return false; 196 } 197 198 if (fHasOptionalContent && state == STATE_START) { 201 return true; 202 } 203 204 for (int i = 0; i < fNumElements; i++) { 205 if (!fIsOptionalElement[i] && currentState[i+1] == STATE_START) 207 return false; 208 } 209 210 return true; 211 } 212 213 219 public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException { 220 for (int i = 0; i < fNumElements; i++) { 222 for (int j = i+1; j < fNumElements; j++) { 223 if (XSConstraints.overlapUPA(fAllElements[i], fAllElements[j], subGroupHandler)) { 224 throw new XMLSchemaException("cos-nonambig", new Object []{fAllElements[i].toString(), 226 fAllElements[j].toString()}); 227 } 228 } 229 } 230 231 return false; 232 } 233 234 243 public Vector whatCanGoHere(int[] state) { 244 Vector ret = new Vector (); 245 for (int i = 0; i < fNumElements; i++) { 246 if (state[i+1] == STATE_START) 249 ret.addElement(fAllElements[i]); 250 } 251 return ret; 252 } 253 254 } 256 | Popular Tags |