1 20 package org.objectweb.modfact.corba.xmiio.importer; 21 22 import org.objectweb.modfact.corba.logging.Level; 23 import org.objectweb.modfact.corba.xmiio.common.AbstractXMIIOGenerator; 24 import org.omg.mof.Reflective.MofError; 25 26 27 31 public class GenerationXMIImportApplication extends AbstractXMIIOGenerator { 32 33 34 private String _ior_filename = new String (""); 35 36 42 public void generateXMIImportApplication(org.omg.mof.Model.Package package_, String class_name_, String class_name_application_) throws MofError, org.omg.CORBA.TypeCodePackage.BadKind , org.omg.CORBA.TypeCodePackage.Bounds { 43 _logger.log(Level.FINE, "XMIImport beginning of the generation"); 44 _logger.log(Level.INFO, class_name_application_ + " generation ..."); 45 String package_name = package_.name(); 46 head(package_, class_name_application_); 47 constructors(package_name, class_name_application_); 48 startMethod(package_, package_name, class_name_); 49 mainMethod(class_name_application_); 50 outputln("} // end class " + class_name_); 51 flushFile(); 52 } 53 54 59 public void head(org.omg.mof.Model.Package package_, String class_name_application_) throws MofError { 60 outputln("package " + javaHelper.javaPackage(package_) + ".xmi;"); 61 outputln(); 62 outputln("public class " + class_name_application_); 63 outputln(" extends org.objectweb.modfact.corba.xmiio.importer.AbstractXMIImportApplication {"); 64 outputln(); 65 outputln("/** The CORBA Helper. */"); 66 outputln("org.objectweb.modfact.corba.helper.CORBACommon corbaHelper;"); 67 outputln(); 68 } 69 70 75 public void constructors(String package_name_, String class_name_application_) { 76 outputln("public " + class_name_application_ + "() {"); 77 outputln("super(\"" + package_name_ + "\", \"" + class_name_application_ + "\", \"" + idlHelper.format1(package_name_) + "Package.ior\");"); 78 outputln("corbaHelper = new org.objectweb.modfact.corba.provider.CORBAProvider();"); 79 outputln("}"); 80 outputln(); 81 } 82 83 87 public void mainMethod(String class_name_application_) throws org.omg.mof.Reflective.MofError { 88 outputln("/**"); 89 outputln(" * The main method"); 90 outputln(" */"); 91 outputln("public static void main (java.lang.String [] args) {"); 92 outputln(class_name_application_ + " application = new " + class_name_application_ + "();"); 93 outputln("application.runMain(args);"); 94 outputln("}"); 95 outputln(); 96 } 97 98 104 public void startMethod(org.omg.mof.Model.Package package_, String package_name_, String class_name_) 105 throws MofError { 106 outputln("/**"); 107 outputln(" * Starts the main function"); 108 outputln(" */"); 109 outputln("public int start(java.lang.String[] args) {"); 110 outputln("try {"); 111 outputln("// Get the root naming context"); 112 outputln("org.omg.CORBA.Object objRef = orb_.resolve_initial_references(\"NameService\");"); 113 outputln("// Use NamingContextExt instead of NamingContext. This is part of the Interoperable naming Service."); 114 outputln("org.omg.CosNaming.NamingContextExt ncRef = org.omg.CosNaming.NamingContextExtHelper.narrow(objRef);"); 115 outputln(); 116 outputln("// Resolve the Object Reference in Naming"); 117 outputln("java.lang.String name = \"" + idlHelper.format1(package_name_) + "FactoryServer\";"); 118 String package_type = javaHelper.javaPackage(package_) + "." + idlHelper.format1(package_name_); 119 outputln(package_type + "PackageFactory _reference = " + package_type + "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("_logger = org.objectweb.modfact.corba.logging.ModFactLogger.getLogger(\""+ package_name_ + "XMIImport\");"); 132 outputln(class_name_ + " xmiImport = new " + class_name_ + "(_logger);"); 133 outputln("xmiImport.initiate(_model_package, orb_);"); 134 outputln(model_package_type + " _package = " + "(" + model_package_type + ") " + "xmiImport.parse(inputFile_);"); 135 outputln("if (nameService_.length() > 0) {"); 137 outputln("org.omg.CosNaming.NameComponent path[] = ncRef.to_name(nameService_);"); 138 outputln("ncRef.rebind(path, _package);"); 139 outputln("}"); 140 outputln("if (printIOR_)"); 142 outputln(" corbaHelper.printIOR(orb_, _package, System.out);"); 143 outputln("corbaHelper.writeIOR(orb_, _package, iorFile_);"); 145 outputln("_logger.log(org.objectweb.modfact.corba.logging.Level.INFO, \"Package is in the repository\");"); 146 output("} "); 147 outputCatchException("org.omg.CORBA.ORBPackage.InvalidName"); 148 outputCatchException("org.omg.CosNaming.NamingContextPackage.InvalidName"); 149 outputCatchException("org.omg.CosNaming.NamingContextPackage.NotFound"); 150 outputCatchException("org.omg.CosNaming.NamingContextPackage.CannotProceed"); 151 outputCatchException("org.omg.mof.Reflective.MofError"); 152 outputCatchException("org.xml.sax.SAXException"); 153 outputCatchException("javax.xml.parsers.ParserConfigurationException"); 154 outputCatchException("java.io.FileNotFoundException"); 155 outputCatchException("java.io.IOException"); 156 outputln(); 157 outputln("return 0;"); 158 outputln("}"); 159 outputln(); 160 } 161 162 166 public void outputCatchException(String exception_) { 167 String exception_name; 168 if (exception_.indexOf(".") != -1) 169 exception_name = exception_.substring(exception_.lastIndexOf(".") + 1); 170 else 171 exception_name = exception_; 172 outputln("catch (" + exception_ + " " + idlHelper.format1FirstMin(exception_name) + ") {"); 173 outputln("System.err.println(\"" + idlHelper.format1(exception_name) + " : \" + " + idlHelper.format1FirstMin(exception_name) + ".getMessage());"); 174 output("} "); 175 } 176 177 } 178 | Popular Tags |