sandygao 2003/03/11 07:48:33 Modified: java/src/org/apache/xerces/impl/xs/models XSAllCM.java XSCMValidator.java XSDFACM.java XSEmptyCM.java Log: Implemented whatCanGoHere in the schema content models. For now it's only used internally. If we ever want to expose such functionality, we might want to revisit the method signature. Revision Changes Path 1.8 +24 -2 xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSAllCM.java Index: XSAllCM.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSAllCM.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- XSAllCM.java 8 Nov 2002 15:55:31 -0000 1.7 +++ XSAllCM.java 11 Mar 2003 15:48:33 -0000 1.8 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -63,6 +63,8 @@ import org.apache.xerces.impl.xs.XMLSchemaException; import org.apache.xerces.impl.xs.XSConstraints; +import java.util.Vector; + /** * XSAllCM implements XSCMValidator and handles <all> * @@ -227,6 +229,26 @@ } return false; + } + + /** + * Check which elements are valid to appear at this point. This method also + * works if the state is in error, in which case it returns what should + * have been seen. + * + * @param state the current state + * @return a Vector whose entries are instances of + * either XSWildcardDecl or XSElementDecl. + */ + public Vector whatCanGoHere(int[] state) { + Vector ret = new Vector(); + for (int i = 0; i < fNumElements; i++) { + // we only try to look for a matching decl if we have not seen + // this element yet. + if (state[i+1] == STATE_START) + ret.addElement(fAllElements[i]); + } + return ret; } } // class XSAllCM 1.5 +15 -3 xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSCMValidator.java Index: XSCMValidator.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSCMValidator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- XSCMValidator.java 9 Aug 2002 15:36:04 -0000 1.4 +++ XSCMValidator.java 11 Mar 2003 15:48:33 -0000 1.5 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -61,6 +61,8 @@ import org.apache.xerces.impl.xs.SubstitutionGroupHandler; import org.apache.xerces.impl.xs.XMLSchemaException; +import java.util.Vector; + /** * Note: State of the content model is stored in the validator * @@ -114,5 +116,15 @@ */ public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException; + /** + * Check which elements are valid to appear at this point. This method also + * works if the state is in error, in which case it returns what should + * have been seen. + * + * @param state the current state + * @return a Vector whose entries are instances of + * either XSWildcardDecl or XSElementDecl. + */ + public Vector whatCanGoHere(int[] state); + } // XSCMValidator - 1.9 +29 -4 xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSDFACM.java Index: XSDFACM.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSDFACM.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XSDFACM.java 20 Nov 2002 00:49:47 -0000 1.8 +++ XSDFACM.java 11 Mar 2003 15:48:33 -0000 1.9 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -68,6 +68,8 @@ import org.apache.xerces.impl.xs.XMLSchemaException; import org.apache.xerces.impl.xs.XSConstraints; +import java.util.Vector; + /** * DFAContentModel is the implementation of XSCMValidator that does * all of the non-trivial element content validation. This class does @@ -311,6 +313,7 @@ // if we still can't find a match, set the state to first_error // and return null if (elemIndex == fElemMapSize) { + state[1] = state[0]; state[0] = XSCMValidator.FIRST_ERROR; return findMatchingDecl(curElem, subGroupHandler); } @@ -341,8 +344,8 @@ // This method returns the start states of the content model. public int[] startContentModel() { - int[] val = new int[1]; - val[0]=0; + int[] val = new int[2]; + val[0] = 0; return val; } // startContentModel():int[] @@ -974,4 +977,26 @@ return false; } + /** + * Check which elements are valid to appear at this point. This method also + * works if the state is in error, in which case it returns what should + * have been seen. + * + * @param state the current state + * @return a Vector whose entries are instances of + * either XSWildcardDecl or XSElementDecl. + */ + public Vector whatCanGoHere(int[] state) { + int curState = state[0]; + if (curState < 0) + curState = state[1]; + + Vector ret = new Vector(); + for (int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) { + if (fTransTable[curState][elemIndex] != -1) + ret.addElement(fElemMap[elemIndex]); + } + return ret; + } + } // class DFAContentModel 1.6 +19 -2 xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java Index: XSEmptyCM.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSEmptyCM.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XSEmptyCM.java 27 Aug 2002 05:34:09 -0000 1.5 +++ XSEmptyCM.java 11 Mar 2003 15:48:33 -0000 1.6 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -61,6 +61,8 @@ import org.apache.xerces.impl.xs.SubstitutionGroupHandler; import org.apache.xerces.impl.xs.XMLSchemaException; +import java.util.Vector; + /** * XSEmptyCM is a derivative of the abstract content model base class that * handles a content model with no chilren (elements). @@ -79,6 +81,8 @@ // start the content model: did not see any children private static final short STATE_START = 0; + + private static final Vector EMPTY = new Vector(0); // // Data @@ -150,4 +154,17 @@ return false; } + /** + * Check which elements are valid to appear at this point. This method also + * works if the state is in error, in which case it returns what should + * have been seen. + * + * @param state the current state + * @return a Vector whose entries are instances of + * either XSWildcardDecl or XSElementDecl. + */ + public Vector whatCanGoHere(int[] state) { + return EMPTY; + } + } // class XSEmptyCM
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]