Package org.apache.openjpa.lib.xml

Examples of org.apache.openjpa.lib.xml.XMLWriter


                } else
                    writer = new StringWriter();

                Writer xml = writer;
                if ((flags & PRETTY) > 0)
                    xml = new XMLWriter(writer);
                trans.setResult(new StreamResult(xml));
                serialize(fileObjs, trans, flags);

                if (output != null)
                    output.put(file, ((StringWriter) writer).toString());
View Full Code Here


    }

    public void serialize(Writer out, int flags) throws IOException {
        try {
            if ((flags & PRETTY) > 0)
                serialize(new StreamResult(new XMLWriter(out)), flags);
            else
                serialize(new StreamResult(out), flags);
        } catch (SAXException se) {
            throw new IOException(se.toString());
        }
View Full Code Here

     * Write the given collection of {@link ObjectData}s to the given file.
     */
    private void write(Collection datas, FileWriter fw)
        throws Exception {
        // create an XML pretty printer to write out the objects
        Writer out = new XMLWriter(fw);

        // start the file; the root node is an "extent"
        out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        out.write("<extent>");

        // run through each object in the collection
        for (Iterator itr = datas.iterator(); itr.hasNext();) {
            ObjectData obj = (ObjectData) itr.next();
            ClassMetaData meta = obj.getMetaData();

            // write out the "object" element start
            out.write("<object class=\"");
            out.write(meta.getDescribedType().getName());
            out.write("\" oid=\"");
            out.write(obj.getId().toString());
            out.write("\" version=\"");
            out.write(obj.getVersion().toString());
            out.write("\">");

            // run through each field writing out the value
            FieldMetaData[] fmds = meta.getFields();
            for (int i = 0; i < fmds.length; i++) {
                if (fmds[i].getManagement() != fmds[i].MANAGE_PERSISTENT)
                    continue;

                out.write("<field name=\"");
                out.write(fmds[i].getName());
                out.write("\">");

                // write out the field data depending upon type
                switch (fmds[i].getTypeCode()) {
                    case JavaTypes.COLLECTION:
                    case JavaTypes.ARRAY:
                        Collection c = (Collection) obj.getField(i);
                        if (c == null)
                            break;

                        // write out each of the elements
                        int elemType = fmds[i].getElement().getTypeCode();
                        for (Iterator ci = c.iterator(); ci.hasNext();) {
                            out.write("<element>");
                            writeDataValue(out, elemType, ci.next());
                            out.write("</element>");
                        }
                        break;

                    case JavaTypes.MAP:
                        Map m = (Map) obj.getField(i);
                        if (m == null)
                            break;

                        // write out each of the map entries
                        Collection entries = m.entrySet();
                        int keyType = fmds[i].getKey().getTypeCode();
                        int valueType = fmds[i].getElement().getTypeCode();
                        for (Iterator ei = entries.iterator(); ei.hasNext();) {
                            Map.Entry e = (Map.Entry) ei.next();
                            out.write("<key>");
                            writeDataValue(out, keyType, e.getKey());
                            out.write("</key>");
                            out.write("<value>");
                            writeDataValue(out, valueType, e.getValue());
                            out.write("</value>");
                        }
                        break;

                    default:
                        writeDataValue(out, fmds[i].getTypeCode(),
                            obj.getField(i));
                }
                out.write("</field>");
            }
            out.write("</object>");
        }
        out.write("</extent>");
    }
View Full Code Here

                } else
                    writer = new StringWriter();

                Writer xml = writer;
                if ((flags & PRETTY) > 0)
                    xml = new XMLWriter(writer);
                trans.setResult(new StreamResult(xml));
                serialize(fileObjs, trans, flags);

                if (output != null)
                    output.put(file, ((StringWriter) writer).toString());
View Full Code Here

    }

    public void serialize(Writer out, int flags) throws IOException {
        try {
            if ((flags & PRETTY) > 0)
                serialize(new StreamResult(new XMLWriter(out)), flags);
            else
                serialize(new StreamResult(out), flags);
        } catch (SAXException se) {
            throw new IOException(se.toString());
        }
View Full Code Here

                } else
                    writer = new StringWriter();

                Writer xml = writer;
                if ((flags & PRETTY) > 0)
                    xml = new XMLWriter(writer);
                trans.setResult(new StreamResult(xml));
                serialize(fileObjs, trans, flags);

                if (output != null)
                    output.put(file, ((StringWriter) writer).toString());
View Full Code Here

    }

    public void serialize(Writer out, int flags) throws IOException {
        try {
            if ((flags & PRETTY) > 0)
                serialize(new StreamResult(new XMLWriter(out)), flags);
            else
                serialize(new StreamResult(out), flags);
        } catch (SAXException se) {
            throw new IOException(se.toString());
        }
View Full Code Here

     * Write the given collection of {@link ObjectData}s to the given file.
     */
    private void write(Collection datas, FileWriter fw)
        throws Exception {
        // create an XML pretty printer to write out the objects
        Writer out = new XMLWriter(fw);

        // start the file; the root node is an "extent"
        out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        out.write("<extent>");

        // run through each object in the collection
        for (Iterator itr = datas.iterator(); itr.hasNext();) {
            ObjectData obj = (ObjectData) itr.next();
            ClassMetaData meta = obj.getMetaData();

            // write out the "object" element start
            out.write("<object class=\"");
            out.write(meta.getDescribedType().getName());
            out.write("\" oid=\"");
            out.write(obj.getId().toString());
            out.write("\" version=\"");
            out.write(obj.getVersion().toString());
            out.write("\">");

            // run through each field writing out the value
            FieldMetaData[] fmds = meta.getFields();
            for (int i = 0; i < fmds.length; i++) {
                if (fmds[i].getManagement() != fmds[i].MANAGE_PERSISTENT)
                    continue;

                out.write("<field name=\"");
                out.write(fmds[i].getName());
                out.write("\">");

                // write out the field data depending upon type
                switch (fmds[i].getTypeCode()) {
                    case JavaTypes.COLLECTION:
                    case JavaTypes.ARRAY:
                        Collection c = (Collection) obj.getField(i);
                        if (c == null)
                            break;

                        // write out each of the elements
                        int elemType = fmds[i].getElement().getTypeCode();
                        for (Iterator ci = c.iterator(); ci.hasNext();) {
                            out.write("<element>");
                            writeDataValue(out, elemType, ci.next());
                            out.write("</element>");
                        }
                        break;

                    case JavaTypes.MAP:
                        Map m = (Map) obj.getField(i);
                        if (m == null)
                            break;

                        // write out each of the map entries
                        Collection entries = m.entrySet();
                        int keyType = fmds[i].getKey().getTypeCode();
                        int valueType = fmds[i].getElement().getTypeCode();
                        for (Iterator ei = entries.iterator(); ei.hasNext();) {
                            Map.Entry e = (Map.Entry) ei.next();
                            out.write("<key>");
                            writeDataValue(out, keyType, e.getKey());
                            out.write("</key>");
                            out.write("<value>");
                            writeDataValue(out, valueType, e.getValue());
                            out.write("</value>");
                        }
                        break;

                    default:
                        writeDataValue(out, fmds[i].getTypeCode(),
                            obj.getField(i));
                }
                out.write("</field>");
            }
            out.write("</object>");
        }
        out.write("</extent>");
    }
View Full Code Here

     * Write the given collection of {@link ObjectData}s to the given file.
     */
    private void write(Collection datas, FileWriter fw)
        throws Exception {
        // create an XML pretty printer to write out the objects
        Writer out = new XMLWriter(fw);

        // start the file; the root node is an "extent"
        out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        out.write("<extent>");

        // run through each object in the collection
        for (Iterator itr = datas.iterator(); itr.hasNext();) {
            ObjectData obj = (ObjectData) itr.next();
            ClassMetaData meta = obj.getMetaData();

            // write out the "object" element start
            out.write("<object class=\"");
            out.write(meta.getDescribedType().getName());
            out.write("\" oid=\"");
            out.write(obj.getId().toString());
            out.write("\" version=\"");
            out.write(obj.getVersion().toString());
            out.write("\">");

            // run through each field writing out the value
            FieldMetaData[] fmds = meta.getFields();
            for (int i = 0; i < fmds.length; i++) {
                if (fmds[i].getManagement() != fmds[i].MANAGE_PERSISTENT)
                    continue;

                out.write("<field name=\"");
                out.write(fmds[i].getName());
                out.write("\">");

                // write out the field data depending upon type
                switch (fmds[i].getTypeCode()) {
                    case JavaTypes.COLLECTION:
                    case JavaTypes.ARRAY:
                        Collection c = (Collection) obj.getField(i);
                        if (c == null)
                            break;

                        // write out each of the elements
                        int elemType = fmds[i].getElement().getTypeCode();
                        for (Iterator ci = c.iterator(); ci.hasNext();) {
                            out.write("<element>");
                            writeDataValue(out, elemType, ci.next());
                            out.write("</element>");
                        }
                        break;

                    case JavaTypes.MAP:
                        Map m = (Map) obj.getField(i);
                        if (m == null)
                            break;

                        // write out each of the map entries
                        Collection entries = m.entrySet();
                        int keyType = fmds[i].getKey().getTypeCode();
                        int valueType = fmds[i].getElement().getTypeCode();
                        for (Iterator ei = entries.iterator(); ei.hasNext();) {
                            Map.Entry e = (Map.Entry) ei.next();
                            out.write("<key>");
                            writeDataValue(out, keyType, e.getKey());
                            out.write("</key>");
                            out.write("<value>");
                            writeDataValue(out, valueType, e.getValue());
                            out.write("</value>");
                        }
                        break;

                    default:
                        writeDataValue(out, fmds[i].getTypeCode(),
                            obj.getField(i));
                }
                out.write("</field>");
            }
            out.write("</object>");
        }
        out.write("</extent>");
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.lib.xml.XMLWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.