Serializing Petri Nets
To store Petri nets and make them available for other users and tools, the SEPIA frame- work comes with a serialization functionality. It supports the file formats PNML and Petrify. To launch the serialization process, an instance of a graphical Petri net, the declaration of the output file format, and the path to the target file are needed.
PNSerialization.serialize(gIFNet, PNSerializationFormat.PNML, "/arbitrary/path/ifnet.pnml");
Parsing Petri Nets
Petri nets can also be parsed using SEPIA’s built-in parser. It supports the PNML and the Petrify file formats and recognizes the file type by the file extension. After parsing it returns an instance of AbstractGraphicalPN.
AbstractGraphicalPN gNet = PNParsing.parse( new File("/arbitrary/path/ifnet.pnml"));
To determine the type of the parsed Petri net, the class type must be checked top-down.
if (gNet instanceof GraphicalIFNet) System.out.println("IF-Net"); else if (gNet instanceof GraphicalCPN) System.out.println("CPN"); else if (gNet instanceof GraphicalPTNet) System.out.println("P/T-Net"); else System.out.println("unknown net type");
If the input file type is already known an appropriate parser can be called manually. Thus a user can specify if a Petri net should be validated against its net type definition or if an exception should be thrown if the net type is not known.
PNMLParser p = new PNMLParser(); AbstractGraphicalPN gNet = p.parse( new File("/arbitrary/path/ifnet.pnml"), true, // require net type true // validate );