public void endElement(String name) throws org.xml.sax.SAXException { //-- strip namespace prefix int idx = name.indexOf(':'); if (idx >= 0) { name = name.substring(idx+1); } StateInfo sInfo = (StateInfo) _siStack.pop(); //-- if we don't have a type, it means there are no //-- children and therefore the type is a simpleType or //-- simpleContent if ((sInfo.element.getType() == null) && (sInfo.buffer != null)) { //-- create SimpleType (guess type) String typeName = _nsPrefix + ':' + DatatypeHandler.guessType(sInfo.buffer.toString()); sInfo.element.setTypeReference(typeName); //-- simpleContent if (sInfo.attributes.size() > 0) { ComplexType cType = new ComplexType(_schema); //-- SHOULD CHANGE THIS TO SIMPLE CONTENT WHEN //-- SCHEMA WRITER BUGS ARE FIXED cType.setContentType(ContentType.mixed); sInfo.element.setType(cType); Group group = new Group(); group.setOrder(_defaultGroupOrder); //-- add attributes try { cType.addGroup(group); for (int i = 0; i < sInfo.attributes.size(); i++) { AttributeDecl attDecl = (AttributeDecl)sInfo.attributes.elementAt(i); cType.addAttributeDecl(attDecl); } } catch(SchemaException sx) { throw new SAXException(sx); } } } else { ComplexType cType = (ComplexType)sInfo.element.getType(); if (cType != null) { //-- add attributes try { for (int i = 0; i < sInfo.attributes.size(); i++) { AttributeDecl attDecl = (AttributeDecl)sInfo.attributes.elementAt(i); cType.addAttributeDecl(attDecl); } } catch(SchemaException sx) { throw new SAXException(sx); } } } //-- put element into parent element or as top-level in schema if (!_siStack.isEmpty()) { StateInfo parentInfo = (StateInfo)_siStack.peek(); ComplexType type = (ComplexType) parentInfo.element.getType(); Group group = null; if (type == null) { parentInfo.complex = true; type = new ComplexType(_schema); parentInfo.element.setType(type); group = new Group(); group.setOrder(_defaultGroupOrder); try { type.addGroup(group); //-- add element group.addElementDecl(sInfo.element); } catch(SchemaException sx) { throw new SAXException(sx); } } else { group = (Group) type.getParticle(0); //-- check for another element declaration with //-- same name ... ElementDecl element = group.getElementDecl(name); boolean checkGroupType = false; if (element != null) { //-- if complex...merge definition if (sInfo.complex) { try { merge(element, sInfo.element); } catch(SchemaException sx) { throw new SAXException(sx); } } element.setMaxOccurs(Particle.UNBOUNDED); checkGroupType = true; } else { try { group.addElementDecl(sInfo.element); } catch(SchemaException sx) { throw new SAXException(sx); } } //-- change group type if necessary if (checkGroupType && (group.getOrder() == Order.seq)) { //-- make sure element is last item in group, //-- otherwise we need to switch to all boolean found = false; boolean changeType = false; for (int i = 0; i < group.getParticleCount(); i++) { if (found) { changeType = true; break; } if (element == group.getParticle(i)) found = true; } if (changeType) { group.setOrder(Order.all); } } } } else { try { _schema.addElementDecl(sInfo.element); //-- make complexType top-level also //XMLType type = sInfo.element.getType(); //if ((type != null) && (type.isComplexType())) { // if (type.getName() == null) { // type.setName(sInfo.element.getName() + "Type"); // _schema.addComplexType((ComplexType)type); // } //} } catch(SchemaException sx) { throw new SAXException(sx); } } } //-- endElement