01: /*
02: * Copyright (C) Chaperon. All rights reserved.
03: * -------------------------------------------------------------------------
04: * This software is published under the terms of the Apache Software License
05: * version 1.1, a copy of which has been included with this distribution in
06: * the LICENSE file.
07: */
08:
09: 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;
17:
18: import java.io.*;
19:
20: public class DiagramGenerator {
21: public static void main(String[] args) throws Exception {
22: Mapping mapping = new Mapping();
23: mapping.loadMapping(new InputSource(ExtendedGrammar.class
24: .getResource("mapping.xml").openStream()));
25:
26: Unmarshaller unmarshaller = new Unmarshaller(
27: ExtendedGrammar.class);
28: unmarshaller.setMapping(mapping);
29:
30: ExtendedGrammar grammar = (ExtendedGrammar) unmarshaller
31: .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
42: .hasNext();) {
43: Pattern pattern = i.next();
44:
45: if ((pattern.getSuccessors().hasNext())
46: || (pattern.getAncestors().hasNext())
47: || (pattern.getAscendingSuccessors().hasNext())
48: || (pattern.getAscendingAncestors().hasNext())
49: || (pattern.getDescendingSuccessors().hasNext())
50: || (pattern.getDescendingAncestors().hasNext()))
51: System.out.println(" n" + pattern.index
52: + " [ label = "
53: + Decoder.toString(pattern.toString()) + " ]");
54: }
55:
56: System.out.println();
57:
58: for (PatternIterator i = grammar.getAllPattern().getPattern(); i
59: .hasNext();) {
60: Pattern pattern = i.next();
61: for (PatternIterator j = pattern.getSuccessors(); j
62: .hasNext();)
63: System.out.println(" n" + pattern.index + " -> n"
64: + j.next().index);
65: }
66:
67: System.out.println();
68:
69: for (PatternIterator i = grammar.getAllPattern().getPattern(); i
70: .hasNext();) {
71: Pattern pattern = i.next();
72: for (PatternIterator j = pattern.getAscendingSuccessors(); j
73: .hasNext();)
74: System.out.println(" n" + pattern.index + " -> n"
75: + j.next().index + " [ color=green ]");
76: }
77:
78: System.out.println();
79:
80: for (PatternIterator i = grammar.getAllPattern().getPattern(); i
81: .hasNext();) {
82: Pattern pattern = i.next();
83: for (PatternIterator j = pattern.getDescendingSuccessors(); j
84: .hasNext();)
85: System.out.println(" n" + pattern.index + " -> n"
86: + j.next().index + " [ color=red ]");
87: }
88:
89: System.out.println("}");
90: }
91: }
|