public void endElement(String uri, String localName, String name) throws SAXException {

    if (collectText) {
      if (NAMESPACE_API.equals(uri) && localName.equals(collectTextElement)) {
        switch (this.currentState) {
          case STATE_DESCRIPTION:
            {
              if (this.currentObject instanceof DocumentedElement) {
                DocumentedElement documentedElement = ((DocumentedElement) this.currentObject);
                documentedElement.description = localizedString(this.text.toString());
                documentedElement.isHTMLDescription = this.collectHTML;
              }
              break;
            }
          case STATE_DEPRECIATED:
          case STATE_AVAILABLE:
            {
              if (this.currentObject instanceof DepreciatedOrAvailable) {
                ((DepreciatedOrAvailable) this.currentObject).text =
                    localizedString(this.text.toString());
              }
              break;
            }

          case STATE_ABOUTME:
          case STATE_QOUTE:
            {
              if (this.currentObject instanceof Author) {
                String text = localizedString(this.text.toString());
                Author author = (Author) this.currentObject;
                if (this.currentState == STATE_ABOUTME) author.aboutMe = text;
                else author.quote = text;
              }
              break;
            }
        }
        popState();
        this.collectText = false;
        this.collectHTML = false;
        this.collectTextElement = null;
        this.text = new StringBuffer();
      } else {
        if (pendingEndElement) text.append("/>");
        else text.append("</").append(localName).append(">");
      }
      pendingEndElement = false;
    } else {

      switch (this.currentState) {
        case STATE_API:
          {
            ArrayList collection = getCollection(TAG_CLASS);
            this.apis.classes = (ClassData[]) collection.toArray(new ClassData[collection.size()]);
            collection = getCollection(TAG_METHOD);
            this.apis.globalMethods = (Method[]) collection.toArray(new Method[collection.size()]);
            collection = getCollection(TAG_PROPERTY);
            this.apis.globalVars = (Property[]) collection.toArray(new Property[collection.size()]);
            collection = getCollection(TAG_AUTHOR);
            this.apis.authors = (Author[]) collection.toArray(new Author[collection.size()]);
            collection = getCollection(TAG_ENUM);
            this.apis.enums = (Enum[]) collection.toArray(new Enum[collection.size()]);
            collection = getCollection(TAG_ALIAS);
            this.apis.aliases = (Alias[]) collection.toArray(new Alias[collection.size()]);
            collection = getCollection(TAG_MIXIN);
            this.apis.mixins = (Mixin[]) collection.toArray(new Mixin[collection.size()]);
            collection = getCollection(TAG_NAMESPACE);
            this.apis.namespaces =
                (Namespace[]) collection.toArray(new Namespace[collection.size()]);
            break;
          }
        case STATE_CLASS:
        case STATE_INTERFACE:
          {
            ClassData clazz = (ClassData) this.currentObject;
            ArrayList collection = getCollection(TAG_ANCESTOR);
            clazz.ancestors = (Ancestor[]) collection.toArray(new Ancestor[collection.size()]);
            collection = getCollection(TAG_CONSTRUCTOR);
            clazz.constructors = (Method[]) collection.toArray(new Method[collection.size()]);
            collection = getCollection(TAG_EVENT);
            clazz.events = (Event[]) collection.toArray(new Event[collection.size()]);
            collection = getCollection(TAG_PROPERTY);
            clazz.properties = (Property[]) collection.toArray(new Property[collection.size()]);
            collection = getCollection(TAG_FIELD);
            clazz.fields = (Property[]) collection.toArray(new Property[collection.size()]);
            collection = getCollection(TAG_METHOD);
            clazz.methods = (Method[]) collection.toArray(new Method[collection.size()]);
            collection = getCollection(TAG_AUTHOR);
            clazz.mixins = (Mix[]) collection.toArray(new Mix[collection.size()]);
            collection = getCollection(TAG_ALIAS);
            clazz.aliases = (Alias[]) collection.toArray(new Alias[collection.size()]);
            break;
          }

        case STATE_CONSTRUCTOR:
        case STATE_METHOD:
          {
            Method method = (Method) this.currentObject;
            ArrayList collection = getCollection(TAG_EXCEPTION);
            method.exceptions = (Exception[]) collection.toArray(new Exception[collection.size()]);
            collection = getCollection(TAG_PARAMETER);
            method.parameters = (Parameter[]) collection.toArray(new Parameter[collection.size()]);

            break;
          }

        case STATE_ENUM:
          {
            Enum enumData = (Enum) this.currentObject;
            ArrayList collection = getCollection(TAG_OPTION);
            enumData.options = (Option[]) collection.toArray(new Option[collection.size()]);
            break;
          }

        case STATE_EVENT:
          {
            Event event = (Event) this.currentObject;
            ArrayList collection = getCollection(TAG_PARAMETER);
            event.parameters = (Parameter[]) collection.toArray(new Parameter[collection.size()]);
            break;
          }

        case STATE_EXCEPTION:
          {
            Exception exception = (Exception) this.currentObject;
            ArrayList collection = getCollection(TAG_PARAMETER);
            exception.parameters =
                (Parameter[]) collection.toArray(new Parameter[collection.size()]);
            break;
          }
      }
      popState();
    }
  }