/** Creates a new attribute.
*/
protected void createAttribute(XsGAttrDecls pAttrDecls, DTDAttribute pAttribute)
throws SAXException {
XsTAttribute attr = pAttrDecls.createAttribute();
attr.setName(new XsNCName(getLocalPart(pAttribute.getName())));
String type = pAttribute.getType();
XsQName qName;
if ("CDATA".equals(type)) {
qName = XSString.getInstance().getName();
} else if ("ID".equals(type)) {
qName = XSID.getInstance().getName();
} else if ("IDREF".equals(type)) {
qName = XSIDREF.getInstance().getName();
} else if ("IDREFS".equals(type)) {
qName = XSIDREFs.getInstance().getName();
} else if ("ENTITY".equals(type)) {
qName = XSEntity.getInstance().getName();
} else if ("ENTITIES".equals(type)) {
qName = XSEntities.getInstance().getName();
} else if ("NMTOKEN".equals(type)) {
qName = XSNMToken.getInstance().getName();
} else if ("NMTOKENS".equals(type)) {
qName = XSNMTokens.getInstance().getName();
} else {
if (type.startsWith("NOTATION") &&
Character.isWhitespace(type.charAt("NOTATION".length()))) {
qName = XSNotation.getInstance().getName();
} else {
qName = XSNMToken.getInstance().getName();
}
XsTLocalSimpleType simpleType = attr.createSimpleType();
XsERestriction restriction = simpleType.createRestriction();
restriction.setBase(new XsQName(qName.getNamespaceURI(), qName.getLocalName(), "xs"));
if (type.startsWith("(")) {
type = type.substring(1).trim();
} else {
throw new SAXParseException("The enumeration in the type of attribute "
+ pAttribute.getName()
+ " must begin with an '('.",
pAttribute.getLocator());
}
if (type.endsWith(")")) {
type = type.substring(0, type.length()-1).trim();
} else {
throw new SAXParseException("The enumeration in the type of attribute "
+ pAttribute.getName()
+ " must begin with an '('.",
pAttribute.getLocator());
}
StringTokenizer st = new StringTokenizer(type, "|");
if (!st.hasMoreTokens()) {
throw new SAXParseException("The enumeration in the type of attribute "
+ pAttribute.getName()
+ " contains no tokens.",
pAttribute.getLocator());
}
while (st.hasMoreTokens()) {
String token = st.nextToken().trim();
if ("".equals(token)) {
throw new SAXParseException("The enumeration in the type of attribute "
+ pAttribute.getName()
+ " contains an empty token.",
pAttribute.getLocator());
}
XsEEnumeration enumeration = restriction.createEnumeration();
enumeration.setValue(token);
}
qName = null;
}
if (qName != null) {
attr.setType(new XsQName(qName.getNamespaceURI(), qName.getLocalName(), "xs"));
}
}