1 20 package org.objectweb.modfact.corba.xmiio.importer; 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 26 27 31 public class GenerationXMIImport extends AbstractXMIIOGenerator { 32 33 34 ModFactLogger _logger = ModFactLogger.getLogger("fr.lip6.src.mdafactory.generation.xmiimport.GenerationXMIImport"); 35 36 39 public GenerationXMIImport() { 40 super(); 41 ModFactLogger logger = ModFactLogger.getLogger("fr.lip6.src.mdafactory.generation.xmiimport.GenerationXMIImportApplication"); 42 } 43 44 48 public void generateXMIImport(org.omg.mof.Model.Package package_) throws org.omg.mof.Reflective.MofError, org.omg.CORBA.TypeCodePackage.BadKind , org.omg.CORBA.TypeCodePackage.Bounds , java.io.IOException { 49 _logger.log(Level.FINE, "XMIImport beginning of the generation"); 50 String className = getClassName(package_.name()); 51 _logger.log(Level.INFO, className + " generation ..."); 52 packageModuleTemplate(package_); 53 flushFile(); 54 } 55 56 61 protected String getClassName(String package_name_) { 62 return super.getClassName(package_name_, "XMIImport"); 63 } 64 65 69 public void constructor(String class_name, String package_name) { 70 _logger.log(Level.FINE, "XMIImport constructor(" + class_name + ")"); 71 outputln("/** The XMIImportAssociations class. */"); 72 outputln(package_name + "XMIImportAssociations _xmi_import_associations;"); 73 outputln(); 74 outputln("/** The XMIImportAttributes class. */"); 75 outputln(package_name + "XMIImportAttributes _xmi_import_attributes;"); 76 outputln(); 77 outputln("/** The XMIImportClasses class. */"); 78 outputln(package_name + "XMIImportClasses _xmi_import_classes;"); 79 outputln(); 80 outputln("/** The logger. */"); 81 outputln("org.objectweb.modfact.corba.logging.ModFactLogger _logger;"); 82 outputln(); 83 outputln("/**"); 84 outputln(" * Default " + class_name + " Constructor"); 85 outputln(" */"); 86 outputln("public " + class_name + "() {"); 87 outputln("this(org.objectweb.modfact.corba.logging.ModFactLogger.getLogger(\"" + package_name + "XMIImport\"));"); 88 outputln("}"); 89 outputln(); 90 outputln("/**"); 91 outputln(" * " + class_name + " Constructor with quiet flag"); 92 outputln(" */"); 93 outputln("public " + class_name + "(boolean quiet) {"); 94 outputln("this(org.objectweb.modfact.corba.logging.ModFactLogger.getLogger(\"" + package_name + "XMIImport\"));"); 95 outputln("if (quiet)"); 96 outputln(TABULATION + "_logger = org.objectweb.modfact.corba.logging.ModFactLogger.getLogger(\"" + package_name + "XMIImport\");"); 97 outputln("}"); 98 outputln(); 99 outputln("/**"); 100 outputln(" * " + class_name + " Constructor"); 101 outputln(" * @param logger The logger."); 102 outputln(" */"); 103 outputln("public " + class_name + "(org.objectweb.modfact.corba.logging.ModFactLogger logger) {"); 104 outputln("_logger = logger;"); 105 outputln("_xmi_import_associations = new " + package_name + "XMIImportAssociations (logger, _types);"); 106 outputln("_xmi_import_attributes = new " + package_name + "XMIImportAttributes (logger, _types);"); 107 outputln("_xmi_import_classes = new " + package_name + "XMIImportClasses (logger, _types);"); 108 outputln("_xmi_import_classes.setXMIImportAttributes(_xmi_import_attributes);"); 109 outputln("_xmi_import_associations.setXMIImportClasses(_xmi_import_classes);"); 110 outputln("_xmi_import_attributes.setXMIImportClasses(_xmi_import_classes);"); 111 outputln("}"); 112 outputln(); 113 } 114 115 119 public void packageModuleTemplate(org.omg.mof.Model.Package package_) throws org.omg.mof.Reflective.MofError, org.omg.CORBA.TypeCodePackage.BadKind , org.omg.CORBA.TypeCodePackage.Bounds { 120 _logger.log(Level.FINE, "XMIImport packageModuleTemplate(" + package_.name() + ")"); 121 if (package_.visibility().equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 122 org.omg.mof.Model.Association associations[] = mofHelper.allAssociationsOfPackage(package_); 123 org.omg.mof.Model.Class classes_ordered[] = mofHelper.allClassesOfPackageOrderedByInheritance(package_); 124 _logger.log(Level.FINE, "XMIImport produce"); 125 126 String className = getClassName(package_.name()); 127 outputln("package " + javaHelper.javaPackage(package_) + ".xmi;"); 128 outputln(); 129 annotationTemplate(package_.annotation()); 130 outputln("public class " + className + " extends org.objectweb.modfact.corba.xmiio.importer.XMIImportParser {"); 131 classAttributes(package_); 132 constructor(className, package_.name()); 133 associationAttributes(package_.name()); 134 initiateMethod(package_, classes_ordered); 135 rootPackage(package_.name(), classes_ordered, associations); 136 completeImportMethod(associations); 137 outputln("} // end of class " + className); 138 outputln(); 139 } 140 } 141 142 147 public void classAttributes(org.omg.mof.Model.Package package_) throws org.omg.mof.Reflective.MofError { 148 String package_name = package_.name(); 149 _logger.log(Level.FINE, "XMIImport classAttributes(" + package_name + ")"); 150 outputln("// Factories Declaration"); 151 String model_package_type; 152 if (mappingValid) { 153 model_package_type = javaHelper.javaPackage(package_) + "._" + idlHelper.format1(package_name) + "Package"; 154 } else { 155 model_package_type = javaHelper.javaPackage(package_) + "." + idlHelper.format1(package_name) + "Package"; 156 } 157 outputln("private " + model_package_type + " _" + idlHelper.format2(package_name) + "_package = null;"); 158 outputln(); 159 } 160 161 166 public void associationAttributes(String package_name_) throws org.omg.mof.Reflective.MofError { 167 _logger.log(Level.FINE, "XMIImport associationAttributes(" + package_name_ + ")"); 168 outputln("// Hashtables for associations (Model / Key Vector)"); 169 outputln(); 170 outputln("/** Hashtables for types (Key / Model) */"); 171 outputln("private java.util.Hashtable _types = new java.util.Hashtable();"); 172 outputln(); 173 } 174 175 181 public void initiateMethod(org.omg.mof.Model.Package package_, org.omg.mof.Model.Class classes_ []) throws org.omg.mof.Reflective.MofError { 182 String package_name = package_.name(); 183 _logger.log(Level.FINE, "XMIImport initiateMethod(" + package_name + ", " + classes_.length + ")"); 184 String model_package_type; 185 if (mappingValid) { 186 model_package_type = javaHelper.javaPackage(package_) + "._" + idlHelper.format1(package_name) + "Package"; 187 } else { 188 model_package_type = javaHelper.javaPackage(package_) + "." + idlHelper.format1(package_name) + "Package"; 189 } 190 outputln("public void initiate(" + model_package_type + " _model_package, org.omg.CORBA.ORB orb)"); 191 outputln(" throws org.omg.mof.Reflective.MofError {"); 192 outputln("super.setORB(orb);"); 193 outputln("// Factories creation"); 194 outputln("_logger.log(org.objectweb.modfact.corba.logging.Level.FINE, \"initiate(\" + _model_package + \")\");"); 195 outputln("this._" + idlHelper.format2(package_name) + "_package = _model_package;"); 196 outputln("_xmi_import_classes.initiate(_model_package);"); 197 outputln("_xmi_import_associations.initiate(_model_package);"); 198 outputln("_xmi_import_attributes.initiate(_model_package);"); 199 outputln("}"); 200 outputln(); 201 } 202 203 209 public void rootPackage(String package_name_, org.omg.mof.Model.Class classes_ [], org.omg.mof.Model.Association associations_ []) throws org.omg.mof.Reflective.MofError { 210 _logger.log(Level.FINE, "XMIImport rootTemplate(" + package_name_ + ", " + classes_.length + ", " + associations_.length + ")"); 211 annotationTemplate(" The root package processing"); 212 outputln("public org.omg.CORBA.portable.IDLEntity rootPackageTemplate(org.w3c.dom.Element _root_package_element)"); 213 outputln(" throws org.omg.mof.Reflective.MofError {"); 214 outputln("_logger.log(org.objectweb.modfact.corba.logging.Level.FINE, \"rootPackageTemplate(\" + _root_package_element + \")\");"); 215 outputln("java.lang.String prefix_element = new java.lang.String();"); 216 outputln("java.lang.String namespace = _root_package_element.getNamespaceURI();"); 217 outputln("if (namespace != null && namespace.length() > 0)"); 218 outputln(" prefix_element = _root_package_element.getPrefix() + \":\";"); 219 outputln("org.w3c.dom.Element _current = _root_package_element;"); 220 outputln("String _current_name = _root_package_element.getNodeName().trim();"); 221 222 for (int i = 0; i < classes_.length; i++) { 223 org.omg.mof.Model.Class cls = (org.omg.mof.Model.Class) classes_[i]; 224 outputln("if (_current_name.endsWith(prefix_element + \"" + idlHelper.format1(cls.name()) + "\")) {"); 225 outputln("_xmi_import_classes." + idlHelper.format1FirstMin(cls.name()) + "Template(_current);"); 226 if (i == classes_.length - 1 && associations_.length == 0) 227 outputln("}"); 228 else 229 output("} else "); 230 } 231 for (int i = 0; i < associations_.length; i++) { 232 org.omg.mof.Model.Association asso = (org.omg.mof.Model.Association) associations_[i]; 233 outputln("if (_current_name.endsWith(prefix_element + \"" + asso.name() + "\")) {"); 234 outputln("_xmi_import_associations." + idlHelper.format1FirstMin(asso.name()) + "Template(_current);"); 235 if (i == associations_.length - 1) 236 outputln("}"); 237 else 238 output("} else "); 239 } 240 outputln("return (org.omg.CORBA.portable.IDLEntity) _" + idlHelper.format2(package_name_) + "_package;"); 241 outputln("}"); 242 outputln(); 243 } 244 245 249 public void completeImportMethod(org.omg.mof.Model.Association associations_ []) throws org.omg.mof.Reflective.MofError { 250 outputln("public void completeImport () throws org.omg.mof.Reflective.MofError {"); 251 for (int i = 0; i < associations_.length; i++) { 252 org.omg.mof.Model.Association asso = (org.omg.mof.Model.Association) associations_[i]; 253 try { 254 org.omg.mof.Model.Reference[] refs = mofHelper.referencesOfAssociation(asso); 255 for (int j = 0; j < refs.length; j++) { 256 org.omg.mof.Model.AssociationEnd assoEnd = refs[j].referenced_end(); 257 if (assoEnd.aggregation().value() == org.omg.mof.Model.AggregationKind._none && assoEnd.is_changeable()) 258 outputln("_xmi_import_attributes.put" + idlHelper.format1(refs[j].container().name()) + idlHelper.format1(refs[j].name()) + "();"); 259 } 260 } catch (org.omg.mof.Reflective.NotSet notSet) { 261 } 263 } 264 outputln("}"); 265 outputln(); 266 } 267 268 } 269 | Popular Tags |