*/
if (r instanceof StreamReaderImpl) {
StreamReaderImpl sr = (StreamReaderImpl) r;
BaseStartElement be = (BaseStartElement) sr.withStartElement(this, loc);
if (be == null) { // incorrect state
throw new WstxException("Trying to create START_ELEMENT when current event is "
+ErrorConsts.tokenTypeDesc(sr.getEventType()),
loc);
}
return be;
}
/* Ok, not woodstox impl, will be bit more work (plus less
* efficient, and may miss some info)... but can be done.
*/
NamespaceContext nsCtxt = null;
if (r instanceof XMLStreamReader2) {
nsCtxt = ((XMLStreamReader2) r).getNonTransientNamespaceContext();
}
Map<QName,Attribute> attrs;
{
int attrCount = r.getAttributeCount();
if (attrCount < 1) {
attrs = null;
} else {
attrs = new LinkedHashMap<QName, Attribute>();
for (int i = 0; i < attrCount; ++i) {
QName aname = r.getAttributeName(i);
attrs.put(aname, new AttributeEventImpl(loc, aname, r.getAttributeValue(i), r.isAttributeSpecified(i)));
}
}
}
List<Namespace> ns;
{
int nsCount = r.getNamespaceCount();
if (nsCount < 1) {
ns = null;
} else {
ns = new ArrayList<Namespace>(nsCount);
for (int i = 0; i < nsCount; ++i) {
ns.add(NamespaceEventImpl.constructNamespace(loc, r.getNamespacePrefix(i), r.getNamespaceURI(i)));
}
}
}
return SimpleStartElement.construct(loc, r.getName(), attrs, ns, nsCtxt);
}
case ENTITY_REFERENCE:
{
/* 19-Jul-2006, TSa: Let's also allow other impls, although
* we can't get actual declaration if so...
*/
if (r instanceof StreamReaderImpl) {
EntityDecl ed = ((StreamReaderImpl) r).getCurrentEntityDecl();
if (ed == null) { // undefined?
// We'll still know the name though...
return new WEntityReference(loc, r.getLocalName());
}
return new WEntityReference(loc, ed);
}
return new WEntityReference(loc, r.getLocalName());
}
/* Following 2 types should never get in here; they are directly
* handled by DTDReader, and can only be accessed via DTD event
* element.
*/
case ENTITY_DECLARATION:
case NOTATION_DECLARATION:
/* Following 2 types should never get in here; they are directly
* handled by the reader, and can only be accessed via start
* element.
*/
case NAMESPACE:
case ATTRIBUTE:
throw new WstxException("Internal error: should not get "
+ErrorConsts.tokenTypeDesc(r.getEventType()));
default:
throw new IllegalStateException("Unrecognized event type "+r.getEventType()+".");
}
}