KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > common > DiagramGenerator


1 /*
2  * Copyright (C) Chaperon. All rights reserved.
3  * -------------------------------------------------------------------------
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8
9 package net.sourceforge.chaperon.common;
10
11 import net.sourceforge.chaperon.model.extended.*;
12
13 import org.exolab.castor.mapping.Mapping;
14 import org.exolab.castor.xml.Unmarshaller;
15
16 import org.xml.sax.InputSource JavaDoc;
17
18 import java.io.*;
19
20 public class DiagramGenerator
21 {
22   public static void main(String JavaDoc[] args) throws Exception JavaDoc
23   {
24     Mapping mapping = new Mapping();
25     mapping.loadMapping(new InputSource JavaDoc(ExtendedGrammar.class.getResource("mapping.xml").openStream()));
26
27     Unmarshaller unmarshaller = new Unmarshaller(ExtendedGrammar.class);
28     unmarshaller.setMapping(mapping);
29
30     ExtendedGrammar grammar =
31       (ExtendedGrammar)unmarshaller.unmarshal(new FileReader(new File(args[0])));
32     grammar.update();
33
34     System.err.println(grammar);
35
36     System.out.println("digraph automaton {");
37     System.out.println(" rankdir=LR ");
38
39     System.out.println();
40
41     for (PatternIterator i = grammar.getAllPattern().getPattern(); i.hasNext();)
42     {
43       Pattern pattern = i.next();
44
45       if ((pattern.getSuccessors().hasNext()) || (pattern.getAncestors().hasNext()) ||
46           (pattern.getAscendingSuccessors().hasNext()) ||
47           (pattern.getAscendingAncestors().hasNext()) ||
48           (pattern.getDescendingSuccessors().hasNext()) ||
49           (pattern.getDescendingAncestors().hasNext()))
50         System.out.println(" n"+pattern.index+" [ label = "+Decoder.toString(pattern.toString())+
51                            " ]");
52     }
53
54     System.out.println();
55
56     for (PatternIterator i = grammar.getAllPattern().getPattern(); i.hasNext();)
57     {
58       Pattern pattern = i.next();
59       for (PatternIterator j = pattern.getSuccessors(); j.hasNext();)
60         System.out.println(" n"+pattern.index+" -> n"+j.next().index);
61     }
62
63     System.out.println();
64
65     for (PatternIterator i = grammar.getAllPattern().getPattern(); i.hasNext();)
66     {
67       Pattern pattern = i.next();
68       for (PatternIterator j = pattern.getAscendingSuccessors(); j.hasNext();)
69         System.out.println(" n"+pattern.index+" -> n"+j.next().index+" [ color=green ]");
70     }
71
72     System.out.println();
73
74     for (PatternIterator i = grammar.getAllPattern().getPattern(); i.hasNext();)
75     {
76       Pattern pattern = i.next();
77       for (PatternIterator j = pattern.getDescendingSuccessors(); j.hasNext();)
78         System.out.println(" n"+pattern.index+" -> n"+j.next().index+" [ color=red ]");
79     }
80
81     System.out.println("}");
82   }
83 }
84
Popular Tags