src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/models/XSDFACM.java
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
equal deleted inserted replaced
47358:d07d5f7cab35 47359:e1a6c0168741
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * @LastModified: Oct 2017
     3  */
     4  */
     4 /*
     5 /*
     5  * Licensed to the Apache Software Foundation (ASF) under one or more
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     6  * contributor license agreements.  See the NOTICE file distributed with
     7  * contributor license agreements.  See the NOTICE file distributed with
     7  * this work for additional information regarding copyright ownership.
     8  * this work for additional information regarding copyright ownership.
    18  * limitations under the License.
    19  * limitations under the License.
    19  */
    20  */
    20 
    21 
    21 package com.sun.org.apache.xerces.internal.impl.xs.models;
    22 package com.sun.org.apache.xerces.internal.impl.xs.models;
    22 
    23 
    23 import com.sun.org.apache.xerces.internal.xni.QName;
       
    24 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMNode;
    24 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMNode;
    25 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMStateSet;
    25 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMStateSet;
    26 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;
    26 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;
    27 import com.sun.org.apache.xerces.internal.impl.xs.SubstitutionGroupHandler;
    27 import com.sun.org.apache.xerces.internal.impl.xs.SubstitutionGroupHandler;
    28 import com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl;
       
    29 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl;
       
    30 import com.sun.org.apache.xerces.internal.impl.xs.XSModelGroupImpl;
       
    31 import com.sun.org.apache.xerces.internal.impl.xs.XSWildcardDecl;
       
    32 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaException;
    28 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaException;
    33 import com.sun.org.apache.xerces.internal.impl.xs.XSConstraints;
    29 import com.sun.org.apache.xerces.internal.impl.xs.XSConstraints;
       
    30 import com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl;
       
    31 import com.sun.org.apache.xerces.internal.impl.xs.XSModelGroupImpl;
       
    32 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl;
       
    33 import com.sun.org.apache.xerces.internal.impl.xs.XSWildcardDecl;
       
    34 import com.sun.org.apache.xerces.internal.xni.QName;
    34 import java.util.ArrayList;
    35 import java.util.ArrayList;
    35 import java.util.HashMap;
    36 import java.util.HashMap;
       
    37 import java.util.List;
       
    38 import java.util.Map;
    36 
    39 
    37 /**
    40 /**
    38  * DFAContentModel is the implementation of XSCMValidator that does
    41  * DFAContentModel is the implementation of XSCMValidator that does
    39  * all of the non-trivial element content validation. This class does
    42  * all of the non-trivial element content validation. This class does
    40  * the conversion from the regular expression to the DFA that
    43  * the conversion from the regular expression to the DFA that
   718 
   721 
   719         /* Optimization(Jan, 2001); This is faster for
   722         /* Optimization(Jan, 2001); This is faster for
   720          * a large content model such as, "(t001+|t002+|.... |t500+)".
   723          * a large content model such as, "(t001+|t002+|.... |t500+)".
   721          */
   724          */
   722 
   725 
   723         HashMap stateTable = new HashMap();
   726         Map<CMStateSet, Integer> stateTable = new HashMap<>();
   724 
   727 
   725         /* Optimization(Jan, 2001) */
   728         /* Optimization(Jan, 2001) */
   726 
   729 
   727         //
   730         //
   728         //  Ok, almost done with the algorithm... We now enter the
   731         //  Ok, almost done with the algorithm... We now enter the
   787                     //  Search the 'states to do' list to see if this new
   790                     //  Search the 'states to do' list to see if this new
   788                     //  state set is already in there.
   791                     //  state set is already in there.
   789                     //
   792                     //
   790 
   793 
   791                     /* Optimization(Jan, 2001) */
   794                     /* Optimization(Jan, 2001) */
   792                     Integer stateObj = (Integer)stateTable.get(newSet);
   795                     Integer stateObj = stateTable.get(newSet);
   793                     int stateIndex = (stateObj == null ? curState : stateObj.intValue());
   796                     int stateIndex = (stateObj == null ? curState : stateObj);
   794                     /* Optimization(Jan, 2001) */
   797                     /* Optimization(Jan, 2001) */
   795 
   798 
   796                     // If we did not find it, then add it
   799                     // If we did not find it, then add it
   797                     if (stateIndex == curState) {
   800                     if (stateIndex == curState) {
   798                         //
   801                         //
  1168      *
  1171      *
  1169      * @param state  the current state
  1172      * @param state  the current state
  1170      * @return       a list whose entries are instances of
  1173      * @return       a list whose entries are instances of
  1171      *               either XSWildcardDecl or XSElementDecl.
  1174      *               either XSWildcardDecl or XSElementDecl.
  1172      */
  1175      */
  1173     public ArrayList whatCanGoHere(int[] state) {
  1176     public List<Object> whatCanGoHere(int[] state) {
  1174         int curState = state[0];
  1177         int curState = state[0];
  1175         if (curState < 0)
  1178         if (curState < 0)
  1176             curState = state[1];
  1179             curState = state[1];
  1177         Occurence o = (fCountingStates != null) ?
  1180         Occurence o = (fCountingStates != null) ?
  1178                 fCountingStates[curState] : null;
  1181                 fCountingStates[curState] : null;
  1179         int count = state[2];
  1182         int count = state[2];
  1180 
  1183 
  1181         ArrayList ret = new ArrayList();
  1184         // Can be XSElementDecl or XSWildcardDecl, but eventually the content is
       
  1185         // only used to evaluate toString
       
  1186         List<Object> ret = new ArrayList<>();
  1182         for (int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) {
  1187         for (int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) {
  1183             int nextState = fTransTable[curState][elemIndex];
  1188             int nextState = fTransTable[curState][elemIndex];
  1184             if (nextState != -1) {
  1189             if (nextState != -1) {
  1185                 if (o != null) {
  1190                 if (o != null) {
  1186                     if (curState == nextState) {
  1191                     if (curState == nextState) {
  1215      * (used to look up properties) and odd entries are parameters
  1220      * (used to look up properties) and odd entries are parameters
  1216      * to be passed when formatting error message. Each parameter
  1221      * to be passed when formatting error message. Each parameter
  1217      * is associated with the error code that preceeds it in
  1222      * is associated with the error code that preceeds it in
  1218      * the list.
  1223      * the list.
  1219      */
  1224      */
  1220     public ArrayList checkMinMaxBounds() {
  1225     public List<String> checkMinMaxBounds() {
  1221         ArrayList result = null;
  1226         List<String> result = null;
  1222         for (int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) {
  1227         for (int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) {
  1223             int count = fElemMapCounter[elemIndex];
  1228             int count = fElemMapCounter[elemIndex];
  1224             if (count == -1) {
  1229             if (count == -1) {
  1225                 continue;
  1230                 continue;
  1226             }
  1231             }
  1227             final int minOccurs = fElemMapCounterLowerBound[elemIndex];
  1232             final int minOccurs = fElemMapCounterLowerBound[elemIndex];
  1228             final int maxOccurs = fElemMapCounterUpperBound[elemIndex];
  1233             final int maxOccurs = fElemMapCounterUpperBound[elemIndex];
  1229             if (count < minOccurs) {
  1234             if (count < minOccurs) {
  1230                 if (result == null) result = new ArrayList();
  1235                 if (result == null) result = new ArrayList<>();
  1231                 result.add("cvc-complex-type.2.4.b");
  1236                 result.add("cvc-complex-type.2.4.b");
  1232                 result.add("{" + fElemMap[elemIndex] + "}");
  1237                 result.add("{" + fElemMap[elemIndex] + "}");
  1233             }
  1238             }
  1234             if (maxOccurs != -1 && count > maxOccurs) {
  1239             if (maxOccurs != -1 && count > maxOccurs) {
  1235                 if (result == null) result = new ArrayList();
  1240                 if (result == null) result = new ArrayList<>();
  1236                 result.add("cvc-complex-type.2.4.d.1");
  1241                 result.add("cvc-complex-type.2.4.d.1");
  1237                 result.add("{" + fElemMap[elemIndex] + "}");
  1242                 result.add("{" + fElemMap[elemIndex] + "}");
  1238             }
  1243             }
  1239         }
  1244         }
  1240         return result;
  1245         return result;