View Javadoc

1   package org.dbe.studio.tools.ssl2sdl.util;
2   
3   import java.io.BufferedReader;
4   import java.io.BufferedWriter;
5   import java.io.ByteArrayOutputStream;
6   import java.io.File;
7   import java.io.FileInputStream;
8   import java.io.FileNotFoundException;
9   import java.io.FileWriter;
10  import java.io.IOException;
11  import java.io.InputStream;
12  import java.io.InputStreamReader;
13  import java.net.MalformedURLException;
14  import java.net.URL;
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import org.atl.eclipse.engine.*;
19  import org.atl.engine.vm.nativelib.ASMModel;
20  import org.eclipse.core.resources.IFile;
21  import org.eclipse.core.resources.IProject;
22  
23  public class SSL2SDLTransformation {
24  
25  	private static AtlModelHandler amh = AtlModelHandler.getDefault(AtlModelHandler.AMH_MDR);
26  	
27  	private static Map models = new HashMap();
28  	private URL ATLWFRurl = SSL2SDLTransformation.class.getResource("resources/SSL2SDL.asm");
29  	
30  	/***
31  	 * 
32  	 * @param in
33  	 * @return
34  	 */
35  	public Object executeTransformation(IProject project, IFile out, File inFile){
36  
37  		String ssl = "SSL";
38  		URL urlSSL = SSL2SDLTransformation.class.getResource("resources/SSL.xmi");
39  		InputStream inSSL = null;
40  		try {
41  			inSSL = urlSSL.openStream();
42  		} catch (IOException e1) {
43  			
44  			e1.printStackTrace();
45  		}
46  		
47  		ASMModel metaIn = amh.loadModel(ssl,amh.getMof(),inSSL);
48  		String inMod = "IN";
49  		URL urlIn = null; 
50  		//URL urlIn = SSL2SDL.class.getResource("resources/HotelWSIS.xmi");
51  		try {
52  			urlIn = inFile.toURL();
53  			
54  		} catch (MalformedURLException e) {
55  			
56  			e.printStackTrace();
57  		}
58  		InputStream inIn = null;
59  		try{
60  			inIn = urlIn.openStream();
61  		}catch (IOException e1) {
62  			
63  			e1.printStackTrace();
64  		}
65  		ASMModel modelIn = amh.loadModel(inMod,metaIn,inIn);
66  		
67  		String sdl = "SDL";
68  		URL urlSDL = SSL2SDLTransformation.class.getResource("resources/SDL.xmi");
69  		InputStream inSDL = null;
70  		try {
71  			inSDL = urlSDL.openStream();
72  		} catch (IOException e1) {
73  			
74  			e1.printStackTrace();
75  		}
76  		ASMModel metaOut = amh.loadModel(sdl,amh.getMof(),inSDL);
77  		
78  		ASMModel modelOut = amh.newModel("OUT",metaOut);
79  		
80  			models.put("MOF", amh.getMof());
81  			models.put(ssl,metaIn);
82  			models.put(inMod,modelIn);
83  			models.put(sdl,metaOut);
84  			models.put("OUT",modelOut);
85  			
86  			
87  			Map params = new HashMap();
88  			params.put("debug", "false");
89  			params.put("WriteTo", out.getLocation().toString());
90  			
91  			Map libs = new HashMap();			
92  			libs.put("strings",SSL2SDLTransformation.class.getResource("resources/strings.asm"));
93  
94  			Object result = AtlLauncher.getDefault().launch(ATLWFRurl, libs, models, params);
95  			
96  		return result;
97  	}
98  	
99  	/***
100 	 * constuctor
101 	 *
102 	 */
103 	public SSL2SDLTransformation(){
104 		
105 		super();
106 		
107 	} 
108 	
109 	/***
110 	 * 
111 	 * @param file
112 	 * @return
113 	 * @throws Exception
114 	 * 
115 	 */
116 	public static String loadFile(File file) throws Exception
117 	{
118 		FileInputStream fis = new FileInputStream(file);
119 		ByteArrayOutputStream baos = new ByteArrayOutputStream((int)file.length());
120 		
121 		byte[] b = new byte[4096];
122 		int nb;
123 		while ( (nb = fis.read(b)) != -1 ) {
124 			baos.write(b, 0, nb);
125 		}
126 		return baos.toString();
127 	}	
128 	
129 	
130 	/***
131 	 * 
132 	 * @param infile
133 	 * @param outfile
134 	 * @throws IOException
135 	 * @throws FileNotFoundException
136 	 */
137 	public static void copy(String infile, String outfile) throws IOException, FileNotFoundException{
138         BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(infile)));
139         BufferedWriter bw = new BufferedWriter(new FileWriter(outfile));
140         String s;
141         while ((s=br.readLine())!= null)
142             bw.write(s+"\n");
143         bw.close();
144         br.close();
145     }
146 	
147 	/***
148 	 * 
149 	 */
150 	public static void main (String[] args) {
151 		
152 		//SSL2SDL trans = new SSL2SDL();
153 		try {
154 			//String datas = OntologyDatas.getODMModel("http://147.27.3.141:2728","tourismOntologyID");
155 			//System.out.println(datas);
156 			
157 		} catch (Exception e) {
158 			
159 			e.printStackTrace();
160 		}
161     	
162 	}	
163 	
164 }