You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Antonio Menchero Fernández <am...@aqs.es> on 2000/06/26 10:30:58 UTC

whatCanGoHere() method in XMLContentModel

I have a method that uses whatCanGoHere() in XMLContentModel interface to 
retrieve what are the
StringPool indexes of its children (source below).

Probably it is not the best way of doing that, but at the moment I cannot 
discover other.

Well, I initialize 'curChildren' array in an InsertableElementsInfo with 
just one element (the
empty slot). I'm supposing that currently there are no children in the 
corresponding xml element. Then I ask the content model whatCanGoHere() and 
finally make use of 'possibleChildren' array (which must have the indexes 
of all valid children for the element). It works only when the content 
model is a DFAContentModel, but not if the xml element is such that it is 
assigned a SimpleContentModel.

There are two lines in SimpleContentModel:whatCanGoHere() that cause 
ArrayIndexOfBoundsException to be thrown cause there are not enough 
elements in 'curChildren'.

//
// For this one, having the empty slot at the insertion point is
// a problem. So lets compress the array down. We know that it has
// to have at least the empty slot at the insertion point.
//

for (int index = info.insertAt; index < info.childCount; index++) {
info.curChildren[index].setValues(info.curChildren[index+1]);
}


Is there any other way to get the string pool indexes of the children of an 
element?
If not, should we modify whatCanGoHere() in SimpleContentModel to allow an 
empty 'curChildren' array?


Thank you all in advance,
Antonio



/**
* My source ...
*/
private int[] getPoolChildrenIndexes(int elementPoolIndex) throws 
SchemaException {

XMLContentModel xcm = null;
int[] indexes = null;
try {
if((xcm = getElementContentModel(elementPoolIndex)) != null) {


InsertableElementsInfo iei = new InsertableElementsInfo();
iei.childCount = 1;
iei.curChildren = new QName[iei.childCount];
iei.insertAt = 0;

int result = xcm.whatCanGoHere(true, iei);
if (result == -1) {
int[] auxIndexes = new int[iei.resultsCount];
int index;
int counter = 0;
while (
(counter <= iei.resultsCount) &&
((index = getPoolElementIndex(iei.possibleChildren[counter])) > 0))
auxIndexes[counter++] = index;
indexes = new int[counter];
System.arraycopy(auxIndexes, 0, indexes, 0, counter);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
throw new SchemaException(e.getMessage());
}

return indexes;
}