public int validate(QName[] children,
int offset,
int length) {
if (DEBUG_VALIDATE_CONTENT)
System.out.println("DFAContentModel#validateContent");
//
// A DFA content model must *always* have at least 1 child
// so a failure is given if no children present.
//
// Defect 782: This is an incorrect statement because a DFA
// content model is also used for constructions such as:
//
// (Optional*,NotRequired?)
//
// where a perfectly valid content would be NO CHILDREN.
// Therefore, if there are no children, we must check to
// see if the CMNODE_EOC marker is a valid start state! -Ac
//
if (length == 0) {
if (DEBUG_VALIDATE_CONTENT) {
System.out.println("!!! no children");
System.out.println("elemMap="+fElemMap);
for (int i = 0; i < fElemMap.length; i++) {
String uri = fElemMap[i].uri;
String localpart = fElemMap[i].localpart;
System.out.println("fElemMap["+i+"]="+uri+","+
localpart+" ("+
uri+", "+
localpart+
')");
}
System.out.println("EOCIndex="+fEOCString);
}
return fEmptyContentIsValid ? -1 : 0;
} // if child count == 0
//
// Lets loop through the children in the array and move our way
// through the states. Note that we use the fElemMap array to map
// an element index to a state index.
//
int curState = 0;
for (int childIndex = 0; childIndex < length; childIndex++)
{
// Get the current element index out
final QName curElem = children[offset + childIndex];
// ignore mixed text
if (fMixed && curElem.localpart == null) {
continue;
}
// Look up this child in our element map
int elemIndex = 0;
for (; elemIndex < fElemMapSize; elemIndex++)
{
int type = fElemMapType[elemIndex] & 0x0f ;
if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
//System.out.println("fElemMap["+elemIndex+"]: "+fElemMap[elemIndex]);
if (fElemMap[elemIndex].rawname == curElem.rawname) {
break;
}
}
else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) {
String uri = fElemMap[elemIndex].uri;
if (uri == null || uri == curElem.uri) {
break;
}
}
else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) {
if (curElem.uri == null) {
break;
}
}
else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) {
if (fElemMap[elemIndex].uri != curElem.uri) {
break;
}
}
}
// If we didn't find it, then obviously not valid
if (elemIndex == fElemMapSize) {
if (DEBUG_VALIDATE_CONTENT) {
System.out.println("!!! didn't find it");
System.out.println("curElem : " +curElem );
for (int i=0; i< fElemMapSize; i++) {
System.out.println("fElemMap["+i+"] = " +fElemMap[i] );
System.out.println("fElemMapType["+i+"] = " +fElemMapType[i] );
}
}
return childIndex;
}
//
// Look up the next state for this input symbol when in the
// current state.
//
curState = fTransTable[curState][elemIndex];
// If its not a legal transition, then invalid
if (curState == -1) {
if (DEBUG_VALIDATE_CONTENT)
System.out.println("!!! not a legal transition");
return childIndex;
}
}
//
// We transitioned all the way through the input list. However, that
// does not mean that we ended in a final state. So check whether
// our ending state is a final state.
//
if (DEBUG_VALIDATE_CONTENT)
System.out.println("curState="+curState+", childCount="+length);
if (!fFinalStateFlags[curState])
return length;
// success!
return -1;
}
Check that the specified content is valid according to this
content model. This method can also be called to do 'what if'
testing of content models just to see if they would be valid.
A value of -1 in the children array indicates a PCDATA node. All other
indexes will be positive and represent child elements. The count can be
zero, since some elements have the EMPTY content model and that must be
confirmed. |