/*
* Copyright (C) Chaperon. All rights reserved.
* -------------------------------------------------------------------------
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package net.sourceforge.chaperon.common;
import net.sourceforge.chaperon.model.extended.*;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.xml.Unmarshaller;
import org.xml.sax.InputSource;
import java.io.*;
public class DiagramGenerator
{
public static void main(String[] args) throws Exception
{
Mapping mapping = new Mapping();
mapping.loadMapping(new InputSource(ExtendedGrammar.class.getResource("mapping.xml").openStream()));
Unmarshaller unmarshaller = new Unmarshaller(ExtendedGrammar.class);
unmarshaller.setMapping(mapping);
ExtendedGrammar grammar =
(ExtendedGrammar)unmarshaller.unmarshal(new FileReader(new File(args[0])));
grammar.update();
System.err.println(grammar);
System.out.println("digraph automaton {");
System.out.println(" rankdir=LR ");
System.out.println();
for (PatternIterator i = grammar.getAllPattern().getPattern(); i.hasNext();)
{
Pattern pattern = i.next();
if ((pattern.getSuccessors().hasNext()) || (pattern.getAncestors().hasNext()) ||
(pattern.getAscendingSuccessors().hasNext()) ||
(pattern.getAscendingAncestors().hasNext()) ||
(pattern.getDescendingSuccessors().hasNext()) ||
(pattern.getDescendingAncestors().hasNext()))
System.out.println(" n"+pattern.index+" [ label = "+Decoder.toString(pattern.toString())+
" ]");
}
System.out.println();
for (PatternIterator i = grammar.getAllPattern().getPattern(); i.hasNext();)
{
Pattern pattern = i.next();
for (PatternIterator j = pattern.getSuccessors(); j.hasNext();)
System.out.println(" n"+pattern.index+" -> n"+j.next().index);
}
System.out.println();
for (PatternIterator i = grammar.getAllPattern().getPattern(); i.hasNext();)
{
Pattern pattern = i.next();
for (PatternIterator j = pattern.getAscendingSuccessors(); j.hasNext();)
System.out.println(" n"+pattern.index+" -> n"+j.next().index+" [ color=green ]");
}
System.out.println();
for (PatternIterator i = grammar.getAllPattern().getPattern(); i.hasNext();)
{
Pattern pattern = i.next();
for (PatternIterator j = pattern.getDescendingSuccessors(); j.hasNext();)
System.out.println(" n"+pattern.index+" -> n"+j.next().index+" [ color=red ]");
}
System.out.println("}");
}
}