1 20 package org.objectweb.modfact.corba.xmiio.exporter; 21 22 import org.objectweb.modfact.corba.logging.Level; 23 import org.objectweb.modfact.corba.logging.ModFactLogger; 24 import org.objectweb.modfact.corba.xmiio.common.AbstractXMIIOGenerator; 25 import org.omg.mof.Reflective.MofError; 26 27 31 public class GenerationXMIExportApplication extends AbstractXMIIOGenerator { 32 33 34 protected ModFactLogger _logger = ModFactLogger.getLogger("fr.lip6.src.mdafactory.generation.xmiio.exporter.GenerationXMIExportApplication"); 35 36 42 public void generateXMIExportApplication(org.omg.mof.Model.Package package_, String class_name_, String class_name_application_) 43 throws org.omg.mof.Reflective.MofError, org.omg.CORBA.TypeCodePackage.BadKind , org.omg.CORBA.TypeCodePackage.Bounds { 44 _logger.log(Level.FINE, "XMIExport beginning of the generation"); 45 _logger.log(Level.INFO, class_name_application_ + " generation ..."); 46 String package_name = package_.name(); 47 head(package_, class_name_application_); 48 constructors(package_name, class_name_application_); 49 startMethod(package_, class_name_); 50 mainMethod(class_name_application_); 51 outputln("} // end class " + class_name_); 52 flushFile(); 53 } 54 55 60 public void head(org.omg.mof.Model.Package package_, String class_name_application_) 61 throws MofError { 62 outputln("package " + javaHelper.javaPackage(package_) + ".xmi;"); 63 outputln(); 64 outputln("public class " + class_name_application_); 65 outputln(" extends org.objectweb.modfact.corba.xmiio.exporter.XMIExportApplication {"); 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_ + "\");"); 77 outputln("}"); 78 outputln(); 79 } 80 81 85 public void mainMethod(String class_name_application_) throws org.omg.mof.Reflective.MofError { 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(org.omg.mof.Model.Package package_, String class_name_) 102 throws MofError { 103 String package_name = package_.name(); 104 String package_qualified_name = javaHelper.javaPackage(package_); 105 outputln("/**"); 106 outputln(" * Starts the main function"); 107 outputln(" */"); 108 outputln("public int start(java.lang.String[] args) {"); 109 outputln("try {"); 110 outputln("// Get the root naming context"); 111 outputln("org.omg.CORBA.Object objRef = orb_.resolve_initial_references(\"NameService\");"); 112 outputln("// Use NamingContextExt instead of NamingContext. This is part of the Interoperable naming Service."); 113 outputln("org.omg.CosNaming.NamingContextExt ncRef = org.omg.CosNaming.NamingContextExtHelper.narrow(objRef);"); 114 outputln(); 115 outputln("// Resolve the Object Reference in Naming"); 116 outputln("java.lang.String name = \"" + idlHelper.format1(package_name) + "FactoryServer\";"); 117 outputln(package_qualified_name + "." + idlHelper.format1(package_name) + "PackageFactory _reference = " 118 + package_qualified_name + "." + idlHelper.format1(package_name) 119 + "PackageFactoryHelper.narrow(ncRef.resolve_str(name));"); 120 outputln(); 121 outputln("// Creation of Model "); 122 String model_package_type; 123 if (mappingValid) { 124 model_package_type = javaHelper.javaPackage(package_) + "._" + idlHelper.format1(package_name) + "Package"; 125 } else { 126 model_package_type = javaHelper.javaPackage(package_) + "." + idlHelper.format1(package_name) + "Package"; 127 } 128 outputln(model_package_type + " _model_package = " + "_reference.create_" + idlHelper.format2(package_name) + "_package();"); 129 outputln(); 130 outputln("org.objectweb.modfact.corba.logging.ModFactLogger _logger;"); 131 outputln(TABULATION 132 + "_logger = org.objectweb.modfact.corba.logging.ModFactLogger.getLogger(\"" 133 + package_name + "XMIExport\");"); 134 outputln(class_name_ + " xmiExport = new " + class_name_ + "(dtdFile_, \"\", _logger);"); 135 outputln("xmiExport.setORB(orb_);"); 136 outputln("java.io.FileOutputStream fileOutput = new java.io.FileOutputStream(new java.io.File(outputFile_));"); 137 outputln("xmiExport.setOutput(fileOutput);"); 138 outputln("if (iorFile_.length() > 0)"); 139 outputln(" xmiExport.parseIOR(iorFile_, printIOR_);"); 140 outputln("else if (nameService_.length() > 0)"); 141 outputln(" xmiExport.parseName(nameService_, printIOR_);"); 142 output("} "); 143 outputCatchException("org.omg.CORBA.ORBPackage.InvalidName"); 144 outputCatchException("org.omg.CosNaming.NamingContextPackage.InvalidName"); 145 outputCatchException("org.omg.CosNaming.NamingContextPackage.NotFound"); 146 outputCatchException("org.omg.CosNaming.NamingContextPackage.CannotProceed"); 147 outputCatchException("org.omg.mof.Reflective.MofError"); 148 outputCatchException("java.io.FileNotFoundException"); 149 outputCatchException("java.io.IOException"); 150 outputln(); 151 outputln("return 0;"); 152 outputln("}"); 153 outputln(); 154 } 155 156 160 public void outputCatchException(String exception_) { 161 String exception_name; 162 if (exception_.indexOf(".") != -1) 163 exception_name = exception_.substring(exception_.lastIndexOf(".") + 1); 164 else 165 exception_name = exception_; 166 outputln("catch (" + exception_ + " " + idlHelper.format1FirstMin(exception_name) + ") {"); 167 outputln( 168 "System.err.println(\"" 169 + idlHelper.format1(exception_name) 170 + " : \" + " 171 + idlHelper.format1FirstMin(exception_name) 172 + ".getMessage());"); 173 output("} "); 174 } 175 176 } 177 | Popular Tags |