KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > qvt > service > LocalClient


1 package org.objectweb.modfact.qvt.service;
2
3 import java.io.*;
4 import java.net.URL JavaDoc;
5
6 public abstract class LocalClient {
7
8   static String JavaDoc getSimpleTrlUrl() {
9     
10     String JavaDoc resourceURL = System.getProperty("org.objectweb.modfact.resourceURL");
11     if(resourceURL!=null) {
12       return resourceURL +"/metamodel_SimpleTRL.xml";
13     }
14     try {
15       return ClassLoader.getSystemResource("org/objectweb/modfact/qvt/metamodel_SimpleTRL.xml").toString();
16     } catch(Exception JavaDoc e) {
17       throw new RuntimeException JavaDoc("Please set system property 'org.objectweb.modfact.resourceURL'");
18     }
19   }
20  
21   /* example
22     fr.lip6.qvt.service.LocalClient.run(
23       "dtd_xs/xmi/dtd_to_xs.xml",
24       "dtd_xs/xmi/dtd_mm.xml", "dtd_xs/xmi/dtd_instance.xml",
25       "dtd_xs/xmi/xs_mm.xml", "dtd_xs/xmi"
26     );
27   */

28   public static void run(
29     String JavaDoc rulePath,
30     String JavaDoc srcMmPath, String JavaDoc srcPath,
31     String JavaDoc targetMmPath, String JavaDoc outputPath
32   ) throws Exception JavaDoc {
33       
34     Model rules, src, target;
35     
36     rules = new ModelImpl(
37         getSimpleTrlUrl()
38         ,ClassLoader.getSystemResource(rulePath).toString()
39     );
40     src = new ModelImpl(
41          ClassLoader.getSystemResource(srcMmPath).toString()
42         ,ClassLoader.getSystemResource(srcPath).toString()
43     );
44     target = new ModelImpl(
45          ClassLoader.getSystemResource(targetMmPath).toString()
46     );
47     
48     System.setProperty("fr.lip6.modfact.qvt.engine.verbose", "true");
49     
50     TransformationService service = new TransformationService();
51     
52     service.transform( rules, src, target );
53     System.err.println("---------- Transformation finished -----------");
54
55     File f = new File(
56       ClassLoader.getSystemResource(outputPath).getPath()
57       +"/" +"_instance.xml"
58     );
59     FileOutputStream out = new FileOutputStream(f);
60     target.writeModelTo(out);
61     out.close();
62     System.err.println("Result written to "
63        +f.getAbsolutePath()
64     );
65   }
66   
67   // use Simple TRL parser
68
public static void runFromTextFormat(
69     InputStream ruleStream,
70     String JavaDoc srcPackageName, InputStream srcMmStream, InputStream srcStream,
71     String JavaDoc targetPackageName, InputStream targetMmStream, OutputStream output
72   ) throws Exception JavaDoc {
73     Model rules, src, target;
74     
75     rules = new ModelImpl(new java.net.URL JavaDoc(getSimpleTrlUrl()).openStream());
76     
77     //rules.getModel().
78

79     src = new ModelImpl( srcMmStream
80         ,srcStream
81     );
82     target = new ModelImpl( targetMmStream );
83     
84     System.setProperty("fr.lip6.modfact.qvt.engine.verbose", "true");
85     
86     TransformationService service = new TransformationService();
87     
88     service.transform( rules, src, target );
89
90     target.writeModelTo(output);
91       
92   }
93
94
95   public static void run(
96     InputStream ruleStream,
97     InputStream srcMmStream, InputStream srcStream,
98     InputStream targetMmStream, OutputStream output
99   ) throws Exception JavaDoc {
100   
101     Model rules, src, target;
102     
103     rules = new ModelImpl(
104          new java.net.URL JavaDoc(getSimpleTrlUrl()).openStream()
105         ,ruleStream
106     );
107
108     src = new ModelImpl(
109          srcMmStream
110         ,srcStream
111     );
112     target = new ModelImpl(
113          targetMmStream
114     );
115     
116     System.setProperty("fr.lip6.modfact.qvt.engine.verbose", "true");
117     
118     TransformationService service = new TransformationService();
119     
120     service.transform( rules, src, target );
121
122     target.writeModelTo(output);
123   }
124   
125   public static void main(String JavaDoc[] args) throws Exception JavaDoc {
126     FileOutputStream out = new FileOutputStream(args[4]);
127     run(
128          new URL JavaDoc(args[0]).openStream() // rules
129
,new URL JavaDoc(args[1]).openStream() // source MM
130
,new URL JavaDoc(args[2]).openStream() // source M
131
,new URL JavaDoc(args[3]).openStream() // target MM
132
,out
133     );
134     out.close();
135   }
136 }
Popular Tags