No subject


Fri Aug 6 17:04:17 PDT 2004


and a new class added to org.jdom.

Phil.

>>>Method to add to AttributeList:

    final void fastAddAttribute(Attribute o) {
        o.parent = parent;
        ensureCapacity(size + 1);
        elementData[size++] = o;
        modCount++;
    }


>>>Methods to add to ContentList:

    final void fastAddContent(Element o) {
        o.parent = parent;
        ensureCapacity(size + 1);
        elementData[size++] = o;
        modCount++;
    }
    final void fastAddContent(Comment o) {
        o.parent = parent;
        ensureCapacity(size + 1);
        elementData[size++] = o;
        modCount++;
    }
    final void fastAddContent(ProcessingInstruction o) {
        o.parent = parent;
        ensureCapacity(size + 1);
        elementData[size++] = o;
        modCount++;
    }
    final void fastAddContent(CDATA o) {
        o.parent = parent;
        ensureCapacity(size + 1);
        elementData[size++] = o;
        modCount++;
    }
    final void fastAddContent(Text o) {
        o.parent = parent;
        ensureCapacity(size + 1);
        elementData[size++] = o;
        modCount++;
    }
    final void fastAddContent(EntityRef o) {
        o.parent = parent;
        ensureCapacity(size + 1);
        elementData[size++] = o;
        modCount++;
    }


>>>And the UnverifiedFactory, not yet completed:

package org.jdom;

import java.util.*;

public class UnverifiedFactory {

    // =====================================================================
    // Element Factory
    // =====================================================================

    public static Element createElement(String name, Namespace namespace) {
        Element e = new org.jdom.Element();
        e.name = name;
        e.namespace = namespace;
        return e;
    }
    public static Element createElement(String name) {
        return createElement(name, (Namespace) null);
    }
    public static Element createElement(String name, String uri) {
        return createElement(name, Namespace.getNamespace("", uri));
    }
    public static Element createElement(String name, String prefix, String uri) {
        return createElement(name, Namespace.getNamespace(prefix, uri));
    }


    // =====================================================================
    // Attribute Factory
    // =====================================================================

    public static Attribute createAttribute(String name, String value, Namespace namespace) {
        Attribute a = new Attribute();
        a.name = name;
        a.value = value;
        a.namespace = namespace;
        return a;
    }
    public static Attribute createAttribute(String name, String value, int type, Namespace namespace) {
        Attribute a = new Attribute();
        a.name = name;
        a.type = type;
        a.value = value;
        a.namespace = namespace;
        return a;
    }
    public static Attribute createAttribute(String name, String value) {
        return createAttribute(name, value, Attribute.UNDECLARED_ATTRIBUTE, Namespace.NO_NAMESPACE);
    }
    public static Attribute createAttribute(String name, String value, int type) {
        return createAttribute(name, value, type, Namespace.NO_NAMESPACE);
    }


    // =====================================================================
    // Text Factory
    // =====================================================================

    public static Text createText(String str) {
        Text t = new Text();
        t.value = str;
        return t;
    }


    // =====================================================================
    // CDATA Factory
    // =====================================================================

    public static CDATA createCDATA(String str) {
        CDATA c = new CDATA();
        c.value = str;
        return c;
    }


    // =====================================================================
    // Comment Factory
    // =====================================================================

    public static Comment createComment(String str) {
        Comment c = new Comment();
        c.text = str;
        return c;
    }


    // =====================================================================
    // Processing Instruction Factory
    // =====================================================================

    public static ProcessingInstruction createProcessingInstruction(String target, Map data) {
        // ProcessingInstruction currently has private methods!
        ProcessingInstruction p = new ProcessingInstruction(target,data);
        return p;
    }

    public static ProcessingInstruction createProcessingInstruction(String target, String data) {
        // ProcessingInstruction currently has private methods!
        ProcessingInstruction p = new ProcessingInstruction(target,data);
        return p;
    }



    // =====================================================================
    // DocType Factory
    // =====================================================================

    public static DocType createDocType(String elementName, String publicID, String systemID) {
        DocType d = new DocType();
        d.elementName = elementName;
        d.publicID = publicID;
        d.systemID = systemID;
        return d;
    }

    public static DocType createDocType(String elementName, String systemID) {
        return createDocType(elementName, null, systemID);
    }

    public static DocType createDocType(String elementName) {
        return createDocType(elementName, null, null);
    }


    // =====================================================================
    // List manipulation
    // =====================================================================

    public static void addContent(Document parent, Element o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Document parent, Comment o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Document parent, ProcessingInstruction o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Document parent, CDATA o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Document parent, Text o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Document parent, EntityRef o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }


    public static void addContent(Element parent, Element o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Element parent, Comment o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Element parent, ProcessingInstruction o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Element parent, CDATA o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Element parent, Text o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }
    public static void addContent(Element parent, String text) {
        ((ContentList)parent.getContent()).fastAddContent(createText(text));
    }
    public static void addContent(Element parent, EntityRef o) {
        ((ContentList)parent.getContent()).fastAddContent(o);
    }

    public static void addAttribute(Element parent, Attribute a) {
        ((AttributeList)parent.getAttributes()).fastAddAttribute(a);
    }

    public static void setDocType(Document parent, DocType docType) {
        parent.docType = docType;
    }

    public static void addNamespaceDeclaration(Element parent, Namespace additional) {
        if (parent.additionalNamespaces == null) {
            parent.additionalNamespaces = new ArrayList(5); //Element.INITIAL_ARRAY_SIZE is protected!
        }
        parent.additionalNamespaces.add(additional);
    }

}






More information about the jdom-interest mailing list