1 28 29 package org.objectweb.openccm.uml.transformation.ast; 30 31 import ispuml.mdaTransformation.model.jmi.JmiModelCreateUtils; 32 33 import java.io.InputStream ; 34 import java.io.FileInputStream ; 35 import java.io.File ; 36 import java.util.Collection ; 37 38 import javax.jmi.reflect.RefPackage; 39 import org.objectweb.openccm.ast.api.FileScope; 40 import org.objectweb.openccm.ast.api.Scope; 41 42 43 44 48 49 public class CCMASTModelCreateUtils extends JmiModelCreateUtils { 50 51 52 private static org.objectweb.openccm.ast.lib.Repository ast; 53 54 58 public static org.objectweb.openccm.ast.lib.Repository getAst() { 59 return ast; 60 } 61 62 63 67 public static Scope createModel() { 68 org.omg.CORBA.ComponentIR.Repository ir = org.objectweb.openccm.corba.TheInterfaceRepository.getRepository(); 69 ast = new org.objectweb.openccm.ast.lib.Repository(org.objectweb.openccm.ir3.api.ComponentRepositoryHelper.narrow(ir)); 70 71 FileScope scope = ast.startFileScope(""); 72 scope.create(); 73 74 return scope; 75 } 76 77 82 public static RefPackage getModelImpl(RefPackage extent) { 83 return extent.refOutermostPackage(); 84 } 85 86 92 public static void readModel(String filename, RefPackage extent, String importer) { 93 try { 94 readModel(new FileInputStream (new File (filename)), extent, importer); 95 } catch (java.lang.Exception ex) { 96 ex.printStackTrace(); 97 } 98 } 99 100 106 public static void readModel(InputStream input, RefPackage extent, String importer) { 107 try { 108 Class importerClass = Class.forName(importer); 110 Object importerInstance = importerClass.newInstance(); 111 java.lang.reflect.Method [] methods = importerClass.getMethods(); 112 java.lang.reflect.Method initiateMethod = null; 113 for (int i=0 ; i<methods.length ; i++) { 114 if (methods[i].getName().equals("initiate")) { 115 initiateMethod = methods[i]; 116 } 117 } 118 if (initiateMethod == null) 119 throw new Exception ("Method initiate not found in " + importer + " class."); 120 121 Object initParam [] = { extent }; 122 initiateMethod.invoke(importerInstance, initParam); 123 Class parseParamType [] = { InputStream .class }; 124 java.lang.reflect.Method parseMethod = importerClass.getMethod("parse", parseParamType); 125 Object parseParam [] = { input }; 126 parseMethod.invoke(importerInstance, parseParam); 127 } catch (java.lang.Exception ex) { 128 ex.printStackTrace(); 129 } 130 } 131 132 138 public static void writeModel(String filename, RefPackage extent, String exporter) { 139 throw new UnsupportedOperationException ("Write model not implemented"); 140 } 141 142 147 public static Collection getRoots(RefPackage extent) { 148 Collection roots = new java.util.ArrayList (); 149 addRoots(roots, extent); 150 return roots; 151 } 152 153 } | Popular Tags |