1 16 17 package org.apache.xerces.impl.xs.models; 18 19 import org.apache.xerces.xni.QName; 20 import org.apache.xerces.impl.xs.XSElementDecl; 21 import org.apache.xerces.impl.xs.SubstitutionGroupHandler; 22 import org.apache.xerces.impl.xs.XMLSchemaException; 23 import org.apache.xerces.impl.xs.XSConstraints; 24 25 import java.util.Vector ; 26 27 35 public class XSAllCM implements XSCMValidator { 36 37 41 private static final short STATE_START = 0; 43 private static final short STATE_VALID = 1; 44 private static final short STATE_CHILD = 1; 45 46 47 51 private XSElementDecl fAllElements[]; 52 private boolean fIsOptionalElement[]; 53 private boolean fHasOptionalContent = false; 54 private int fNumElements = 0; 55 56 60 public XSAllCM (boolean hasOptionalContent, int size) { 61 fHasOptionalContent = hasOptionalContent; 62 fAllElements = new XSElementDecl[size]; 63 fIsOptionalElement = new boolean[size]; 64 } 65 66 public void addElement (XSElementDecl element, boolean isOptional) { 67 fAllElements[fNumElements] = element; 68 fIsOptionalElement[fNumElements] = isOptional; 69 fNumElements++; 70 } 71 72 73 77 84 public int[] startContentModel() { 85 86 int[] state = new int[fNumElements + 1]; 87 88 for (int i = 0; i <= fNumElements; i++) { 89 state[i] = STATE_START; 90 } 91 return state; 92 } 93 94 Object findMatchingDecl(QName elementName, SubstitutionGroupHandler subGroupHandler) { 97 Object matchingDecl = null; 98 for (int i = 0; i < fNumElements; i++) { 99 matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, fAllElements[i]); 100 if (matchingDecl != null) 101 break; 102 } 103 return matchingDecl; 104 } 105 106 113 public Object oneTransition (QName elementName, int[] currentState, SubstitutionGroupHandler subGroupHandler) { 114 115 if (currentState[0] < 0) { 117 currentState[0] = XSCMValidator.SUBSEQUENT_ERROR; 118 return findMatchingDecl(elementName, subGroupHandler); 119 } 120 121 currentState[0] = STATE_CHILD; 123 124 Object matchingDecl = null; 125 126 for (int i = 0; i < fNumElements; i++) { 127 if (currentState[i+1] != STATE_START) 130 continue; 131 matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, fAllElements[i]); 132 if (matchingDecl != null) { 133 currentState[i+1] = STATE_VALID; 135 return matchingDecl; 136 } 137 } 138 139 currentState[0] = XSCMValidator.FIRST_ERROR; 141 return findMatchingDecl(elementName, subGroupHandler); 142 } 143 144 145 151 public boolean endContentModel (int[] currentState) { 152 153 int state = currentState[0]; 154 155 if (state == XSCMValidator.FIRST_ERROR || state == XSCMValidator.SUBSEQUENT_ERROR) { 156 return false; 157 } 158 159 if (fHasOptionalContent && state == STATE_START) { 162 return true; 163 } 164 165 for (int i = 0; i < fNumElements; i++) { 166 if (!fIsOptionalElement[i] && currentState[i+1] == STATE_START) 168 return false; 169 } 170 171 return true; 172 } 173 174 180 public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException { 181 for (int i = 0; i < fNumElements; i++) { 183 for (int j = i+1; j < fNumElements; j++) { 184 if (XSConstraints.overlapUPA(fAllElements[i], fAllElements[j], subGroupHandler)) { 185 throw new XMLSchemaException("cos-nonambig", new Object []{fAllElements[i].toString(), 187 fAllElements[j].toString()}); 188 } 189 } 190 } 191 192 return false; 193 } 194 195 204 public Vector whatCanGoHere(int[] state) { 205 Vector ret = new Vector (); 206 for (int i = 0; i < fNumElements; i++) { 207 if (state[i+1] == STATE_START) 210 ret.addElement(fAllElements[i]); 211 } 212 return ret; 213 } 214 215 } 217 | Popular Tags |