KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > qvt > syntaxe > TranslationService


1 /**
2  * copyright 2002 2003 Laboratoire d'Informatique Paris 6 (LIP6)
3  *
4  * This file is part of ModFact.
5  *
6  * ModFact is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * at your option) any later version.
10  *
11  * ModFact is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with ModFact; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package org.objectweb.modfact.qvt.syntaxe;
21
22 /**
23  *
24  * @author Reda Bendraou
25  */

26
27 import java.io.*;
28 import java.util.logging.ConsoleHandler JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import java.util.logging.Logger JavaDoc;
31
32 import javax.jmi.reflect.RefObject;
33 import javax.jmi.xmi.XmiWriter;
34
35 import org.objectweb.modfact.jmi.repository.simpletrl.SimpleTRLPackageImpl;
36 import org.objectweb.modfact.jmi.xmi.XmiWriterImpl;
37 import org.objectweb.modfact.qvt.util.RulePrinter;
38
39 import simpletrl.SimpleTRLPackage;
40
41 class TranslationService {
42     public static void main(String JavaDoc[] args) {
43
44         FileInputStream fileInput = null;
45
46         try {
47             fileInput = new FileInputStream(args[0]);
48             DataInputStream input = new DataInputStream(fileInput);
49             STRLLexer lexer = new STRLLexer(input);
50             STRLParser parser = new STRLParser(lexer);
51             
52             SimpleTRLPackage p =
53                 SimpleTRLPackageImpl.create(
54                     ClassLoader
55                         .getSystemResource("simpletrl/metamodel_SimpleTRL.xml")
56                         .toString());
57             
58             
59             //Set a Logger
60
Logger JavaDoc log = Logger.getLogger("org.objectweb.modfact.qvt.syntaxe.TranslationService");
61             parser.setLogger(log);
62             
63             ConsoleHandler JavaDoc chJmi = new ConsoleHandler JavaDoc();
64             chJmi.setLevel(Level.INFO);
65             log.addHandler(chJmi);
66
67             parser.setRuleModel(p);
68             parser.file();
69
70             /*
71              * CommonAST parseTree = (CommonAST)parser.getAST(); ASTFrame frame =
72              * new ASTFrame("The Tree", parseTree);
73              */

74
75             XmiWriter w = new XmiWriterImpl();
76             FileOutputStream out = new FileOutputStream(args[1]);
77             w.write(out, p, "1.2");
78             out.close();
79
80             out = new FileOutputStream(args[2]);
81             RulePrinter.printer.printRules(
82                 (RefObject) p.getRulesUnit().refAllOfClass().toArray()[0],
83                 new PrintWriter(out));
84             out.close();
85
86         } catch (Exception JavaDoc e) {
87             System.err.println("exception REDA: " + e);
88             e.printStackTrace();
89         }
90     }
91 }
92
Popular Tags