1 20 package org.objectweb.modfact.jmi.xmiio.importer; 21 22 import javax.jmi.model.MofPackage; 23 24 import org.objectweb.modfact.jmi.helper.JMIProvider; 25 import org.objectweb.modfact.jmi.helper.XMIIOHelper; 26 import org.objectweb.modfact.jmi.xmiio.common.AbstractXMIIOGenerator; 27 28 29 33 public class GenerationXMIImportApplication extends AbstractXMIIOGenerator { 34 35 36 37 private String _ior_filename = new String (""); 38 39 45 public void generateXMIImportApplication(MofPackage package_, String class_name_, String class_name_application_) { 46 String package_name_ = JMIProvider.jmiPackageExtentName(package_); 47 head(package_, class_name_application_); 48 constructors(package_name_, class_name_application_); 49 startMethod(package_name_, package_, class_name_); 50 mainMethod(class_name_application_); 51 outputln("} // end class " + class_name_); 52 out.flush(); 53 } 54 55 60 public void head(MofPackage package_, String class_name_application_) { 61 String packageQualifiedName = JMIProvider.qualifierOf(package_); 62 outputln("package " + packageQualifiedName + ".xmi;"); 63 outputln(); 64 outputln("public class " + class_name_application_); 65 outputln(" extends org.objectweb.modfact.jmi.service.cmdline.xmiio.XMIImportApplication {"); 66 outputln(); 67 } 68 69 74 public void constructors(String package_name_, String class_name_application_) { 75 outputln("public " + class_name_application_ + "() {"); 76 outputln("super(\"" + package_name_ + "\", \"" + class_name_application_ + "\", \"" + JMIProvider.jmiFormat1(package_name_) + "Package.ior\");"); 77 outputln("}"); 78 outputln(); 79 } 80 81 85 public void mainMethod(String class_name_application_) { 86 outputln("/**"); 87 outputln(" * The main method"); 88 outputln(" */"); 89 outputln("public static void main (java.lang.String [] args) {"); 90 outputln(class_name_application_ + " application = new " + class_name_application_ + "();"); 91 outputln("application.runMain(args);"); 92 outputln("}"); 93 outputln(); 94 } 95 96 101 public void startMethod(String package_name_, MofPackage package_, String class_name_) { 102 outputln("/**"); 103 outputln(" * Starts the main function"); 104 outputln(" */"); 105 outputln("public int start(java.lang.String[] args) {"); 106 outputln("try {"); 107 outputln(); 108 outputln("// Creation of Model "); 109 110 String model_package_type; 111 model_package_type = JMIProvider.jmiPackageQualifiedName(package_) + "Package"; 112 113 outputln(model_package_type + " pck = null;"); 114 outputln("try {"); 115 outputln("java.io.File metaModel = new java.io.File(metaModelFile);"); 116 String shortQualif = JMIProvider.shortQualifierOf(package_); 117 outputln("pck = org.objectweb.modfact.jmi.repository." + shortQualif + "." + JMIProvider.jmiFormat1(package_name_) + "PackageImpl.create(metaModel.toURL().toString());"); 118 outputln("} catch (Exception e) {"); 119 outputln("System.err.println(\"exception : \" + e.getMessage());"); 120 outputln("e.printStackTrace();"); 121 outputln("}"); 122 123 outputln(class_name_ + " xmiImport = new " + class_name_ + "();"); 124 outputln("xmiImport.initiate(pck);"); 125 outputln(model_package_type + " _package = " + "(" + model_package_type + ") " + "xmiImport.parse(modelFile_);"); 126 outputln("System.out.println(\"Package is in the repository\");"); 127 output("} "); 128 outputCatchException("org.xml.sax.SAXException"); 129 outputCatchException("javax.xml.parsers.ParserConfigurationException"); 130 outputCatchException("java.io.FileNotFoundException"); 131 outputCatchException("java.io.IOException"); 132 outputln(); 133 outputln("return 0;"); 134 outputln("}"); 135 outputln(); 136 } 137 138 142 public void outputCatchException(String exception_) { 143 String exception_name; 144 if (exception_.indexOf(".") != -1) 145 exception_name = exception_.substring(exception_.lastIndexOf(".") + 1); 146 else 147 exception_name = exception_; 148 outputln("catch (" + exception_ + " " + XMIIOHelper.format1FirstMin(exception_name) + ") {"); 149 outputln("System.err.println(\"" + JMIProvider.jmiFormat1(exception_name) + " : \" + " + XMIIOHelper.format1FirstMin(exception_name) + ".getMessage());"); 150 output("} "); 151 } 152 153 154 } 155 | Popular Tags |