// Make sure that the matcher is prepared for the cascade.
MatcherContext matcherContext = stylerContext.getMatcherContext();
matcherContext.prepareForCascade(attributes);
if (iterator instanceof IndexableStylerList) {
IndexableStylerList styler = (IndexableStylerList) iterator;
BitSet indexRef = styler.createIndexRef();
styler.lookupElement(indexRef, matcherContext.getLocalName());
String classes = attributes.getAttributeValue(null, "class");
if (classes != null) {
if (classes.indexOf(' ') > -1) {
// TODO later - this can probably be more efficient
StringTokenizer tokenizer = new StringTokenizer(classes, " ");
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
styler.lookupClass(indexRef, token);
}
} else {
styler.lookupClass(indexRef, classes);
}
}
// Exclude stylers which require state that isn't present
BitSet requiresState = styler.stateRequired();
Iterator it = matcherContext.stateMarkers();
if (it != null && it.hasNext()) {
BitSet stateActive = new BitSet();
while (it.hasNext()) {
StateMarker marker = (StateMarker) it.next();
if (marker.isActive()) {
styler.lookupState(stateActive, marker.getState());
}
}
requiresState.andNot(stateActive);
}
indexRef.andNot(requiresState);
styler.iterateIndexed(this, indexRef);
} else {
// Iterate over the stylers asking them to match.
iterator.iterate(this);
}