public XmlWriter endEntity() throws IOException {
        if (this.stack.empty()) {
            throw new InvalidObjectException("Called endEntity too many times. ");
        }
        String name = this.stack.pop();
        if (name != null) {
            if (this.empty) {
                writeAttributes();
                this.writer.write("/>\n");
            } else {
                if (!this.justWroteText)
                {
                    for (int tabIndex = 0; tabIndex < stack.size() + indentingOffset; tabIndex++)
                        this.writer.write(INDENT_STRING);
                }
                this.writer.write("</");
                this.writer.write(name);
                this.writer.write(">\n");
            }
            this.empty = false;
            this.closed = true;
            this.justWroteText = false;
        }
        return this;
    }