package de.renew.gui.pnml;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import de.renew.draw.storables.ontology.Drawing;
import de.renew.gui.CPNDrawing;
import de.renew.gui.XMLFormat;
import de.renew.gui.pnml.creator.PNMLCreator;
import de.renew.gui.pnml.parser.PNMLParser;


public class PNMLFormat implements XMLFormat {
    private PNMLCreator _creator;

    public PNMLFormat() {
        // leave _creator == null
    }

    public PNMLFormat(String netType, boolean toolInsc) {
        _creator = new PNMLCreator(netType, toolInsc);
    }

    @Override
    public boolean canExport() {
        return true;
    }

    @Override
    public boolean canImport() {
        return true;
    }

    @Override
    public List<Drawing> parse(InputStream stream) throws Exception {
        return PNMLParser.instance().parse(stream);
    }

    @Override
    public void write(OutputStream stream, CPNDrawing drawing) throws Exception {
        // throws NullPointerException if PNMLFormat() constructor was used
        _creator.write(stream, drawing);
    }

    @Override
    public void write(OutputStream stream, CPNDrawing[] drawings) throws Exception {
        // throws NullPointerException if PNMLFormat() constructor was used
        _creator.write(stream, drawings);
    }
}