1 package org.objectweb.modfact.qvt.service; 2 3 import java.io.*; 4 import java.net.URL ; 5 6 public abstract class LocalClient { 7 8 static String getSimpleTrlUrl() { 9 10 String 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 e) { 17 throw new RuntimeException ("Please set system property 'org.objectweb.modfact.resourceURL'"); 18 } 19 } 20 21 28 public static void run( 29 String rulePath, 30 String srcMmPath, String srcPath, 31 String targetMmPath, String outputPath 32 ) throws Exception { 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 public static void runFromTextFormat( 69 InputStream ruleStream, 70 String srcPackageName, InputStream srcMmStream, InputStream srcStream, 71 String targetPackageName, InputStream targetMmStream, OutputStream output 72 ) throws Exception { 73 Model rules, src, target; 74 75 rules = new ModelImpl(new java.net.URL (getSimpleTrlUrl()).openStream()); 76 77 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 { 100 101 Model rules, src, target; 102 103 rules = new ModelImpl( 104 new java.net.URL (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 [] args) throws Exception { 126 FileOutputStream out = new FileOutputStream(args[4]); 127 run( 128 new URL (args[0]).openStream() ,new URL (args[1]).openStream() ,new URL (args[2]).openStream() ,new URL (args[3]).openStream() ,out 133 ); 134 out.close(); 135 } 136 } | Popular Tags |