final SymbolTable stable = parser.getSymbolTable();
// Handle the 'name' attribute
String name = getAttribute("name");
if (name == EMPTYSTRING) {
ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ELEM_NAME_ERR,
name, this);
parser.reportError(WARNING, msg);
parseChildren(parser);
_ignore = true; // Ignore the element if the QName is invalid
return;
}
// Get namespace attribute
String namespace = getAttribute("namespace");
// Optimize compilation when name is known at compile time
_isLiteralName = Util.isLiteral(name);
if (_isLiteralName) {
if (!XML11Char.isXML11ValidQName(name)) {
ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_ELEM_NAME_ERR,
name, this);
parser.reportError(WARNING, msg);
parseChildren(parser);
_ignore = true; // Ignore the element if the QName is invalid
return;
}
final QName qname = parser.getQNameSafe(name);
String prefix = qname.getPrefix();
String local = qname.getLocalPart();
if (prefix == null) {
prefix = EMPTYSTRING;
}
if (!hasAttribute("namespace")) {
namespace = lookupNamespace(prefix);
if (namespace == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.NAMESPACE_UNDEF_ERR,
prefix, this);
parser.reportError(WARNING, err);
parseChildren(parser);
_ignore = true; // Ignore the element if prefix is undeclared
return;
}
_prefix = prefix;
_namespace = new AttributeValueTemplate(namespace, parser, this);
}
else {
if (prefix == EMPTYSTRING) {
if (Util.isLiteral(namespace)) {
prefix = lookupPrefix(namespace);
if (prefix == null) {
prefix = stable.generateNamespacePrefix();
}
}
// Prepend prefix to local name
final StringBuffer newName = new StringBuffer(prefix);
if (prefix != EMPTYSTRING) {
newName.append(':');
}
name = newName.append(local).toString();
}
_prefix = prefix;
_namespace = new AttributeValueTemplate(namespace, parser, this);
}
}
else {
_namespace = (namespace == EMPTYSTRING) ? null :
new AttributeValueTemplate(namespace, parser, this);
}
_name = new AttributeValueTemplate(name, parser, this);
final String useSets = getAttribute("use-attribute-sets");
if (useSets.length() > 0) {
if (!Util.isValidQNames(useSets)) {
ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, useSets, this);
parser.reportError(Constants.ERROR, err);
}
setFirstElement(new UseAttributeSets(useSets, parser));
}