1 20 package org.objectweb.modfact.corba.idl2java; 21 22 import org.omg.CORBA.TypeCodePackage.BadKind ; 23 import org.omg.CORBA.TypeCodePackage.Bounds ; 24 import org.omg.mof.Model.PackageHelper; 25 import org.omg.mof.Reflective.NotSet; 26 27 import org.objectweb.modfact.corba.generator.BracketGenerator; 28 import org.objectweb.modfact.corba.helper.JavaCommon; 29 import org.objectweb.modfact.corba.helper.MOFCommon; 30 import org.objectweb.modfact.corba.logging.ModFactLogger; 31 32 public class ClassProxyImplementationGenerator extends BracketGenerator { 33 34 ModFactLogger logger = null; 35 36 org.omg.mof.Model.Class[] input; 37 38 41 public void setInput(org.omg.mof.Model.ModelElement[] elt) { 42 input = new org.omg.mof.Model.Class[elt.length]; 43 for (int i = 0; i < input.length; i++) { 44 input[i] = (org.omg.mof.Model.Class) elt[i]; 45 } 46 } 47 48 51 public void setLogger(ModFactLogger log) { 52 logger = log; 53 } 54 55 JavaCommon javaHelper; 57 MOFCommon mofHelper; 58 59 public void generate() 60 throws 61 org.omg.mof.Reflective.NotSet, 62 org.omg.mof.Reflective.MofError, 63 org.omg.CORBA.TypeCodePackage.BadKind , 64 org.omg.CORBA.TypeCodePackage.Bounds { 65 outputln("// le Code généré de la ProxyClass: " + input[0].name()); 66 classProxyImpl(input[0]); 67 flushFile(); 68 } 69 70 public void allOfType(org.omg.mof.Model.Class _class) 72 throws org.omg.mof.Reflective.MofError, org.omg.mof.Reflective.NotSet { 73 74 String _cformat1 = javaHelper.javaQualifiedName(_class); 75 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 76 77 outputln( 78 "public " + _cformat1 + "[] all_of_type_" + _cformat2 + "() {"); 79 80 outputln( 82 "java.util.Vector all_type_vector = new java.util.Vector();"); 83 org.omg.mof.Model.Class[] _sub_classes = 84 mofHelper.subClassesOfClass(_class); 85 86 for (int i = 0; i < _sub_classes.length; i++) { 87 org.omg.mof.Model.Class _class_temp = _sub_classes[i]; 88 if (!_class_temp.is_abstract() 90 && mofHelper.isInSameExtent(_class_temp, _class)) { 91 String _sformat1 = javaHelper.javaQualifiedName(_class_temp); 92 String _sformat2 = javaHelper.format2(javaHelper.javaClassName(_class_temp)); 93 94 String _sformat2_ref = getRefMethod(_class_temp, _class.container()); 95 96 outputln( 98 _sformat1 99 + "[] " 100 + "_" 101 + _sformat2 102 + " =_model_package." 103 + _sformat2_ref 104 + ".all_of_class_" 105 + _sformat2 106 + "();"); 107 outputln( 108 "for(int i=0; i<" 109 + "_" 110 + _sformat2 111 + ".length ; i++) all_type_vector.addElement(" 112 + "_" 113 + _sformat2 114 + "[i]);"); 115 } 116 } 117 if (!_class.is_abstract()) 118 outputln( 119 "for(int i=0; i< all_class_vector_" 120 + _cformat2 121 + ".size() ; i++) all_type_vector.addElement((" 122 + _cformat1 123 + ")all_class_vector_" 124 + _cformat2 125 + ".elementAt(i));"); 126 outputln( 127 _cformat1 128 + "[] all_type = new " 129 + _cformat1 130 + "[all_type_vector.size()];"); 131 outputln( 132 "for (int i=0; i< all_type_vector.size(); i++) all_type[i]= (" 133 + _cformat1 134 + ")all_type_vector.elementAt(i);"); 135 outputln("return all_type; "); 136 outputln("} "); 137 138 } 139 140 public void allOfClasses(org.omg.mof.Model.Class _class) 141 throws org.omg.mof.Reflective.MofError , NotSet{ 142 String _cformat1 = javaHelper.javaQualifiedName(_class); 143 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 144 outputln( 145 "java.util.Vector all_class_vector_" 146 + _cformat2 147 + " = new java.util.Vector();"); 148 outputln( 149 "public " + _cformat1 + "[] all_of_class_" + _cformat2 + "() {"); 150 outputln( 151 _cformat1 152 + "[] _" 153 + _cformat2 154 + " = new " 155 + _cformat1 156 + "[all_class_vector_" 157 + _cformat2 158 + ".size()];"); 159 outputln( 160 "for (int i=0; i< all_class_vector_" 161 + _cformat2 162 + ".size(); i++) _" 163 + _cformat2 164 + "[i]= (" 165 + _cformat1 166 + ")all_class_vector_" 167 + _cformat2 168 + ".elementAt(i);"); 169 outputln("return _" + _cformat2 + "; "); 170 outputln("} "); 171 } 172 173 public void createClass(org.omg.mof.Model.Class _class) 174 throws org.omg.mof.Reflective.MofError, BadKind , Bounds , NotSet{ 175 String _cformat1 = javaHelper.javaQualifiedName(_class); 176 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 177 178 output("public " + _cformat1 + " create_" + _cformat2 + "("); 180 181 org.omg.mof.Model.MofAttribute[] attributesND = 183 mofHelper.allAttributesOfClass( 184 _class, 185 org.omg.mof.Model.ScopeKind.instance_level, 186 false); 187 for (int i = 0; i < attributesND.length; i++) { 188 String _type_format1 = javaHelper.javaType(attributesND[i].type()); 189 String _aformat2 = javaHelper.format2(attributesND[i].name()); 190 if ((attributesND[i].multiplicity().upper > 1) 191 || (attributesND[i].multiplicity().upper == -1)) { 192 output(_type_format1 + "[] " + _aformat2); 193 } else 194 output(_type_format1 + " " + _aformat2); 195 if (i != (attributesND.length - 1)) 196 output(", "); 197 } 198 outputln(") throws org.omg.mof.Reflective.MofError {"); 199 output( 200 _cformat1 201 + "Impl _" 202 + _cformat2 203 + " = new " 204 + _cformat1 205 + "Impl("); 206 for (int i = 0; i < attributesND.length; i++) { 207 String _aformat2 = javaHelper.format2(attributesND[i].name()); 208 output(_aformat2); 209 output(", "); 210 } 211 outputln("_this());"); 212 outputln("try {"); 213 outputln("_poa().activate_object(_" + _cformat2 + ");"); 214 outputln( 215 "org.omg.CORBA.Object obj = _poa().servant_to_reference(_" 216 + _cformat2 217 + ");"); 218 outputln( 219 _cformat1 220 + " _ref = " 221 + _cformat1 222 + "Helper.narrow(obj);"); 223 outputln("all_class_vector_" + _cformat2 + ".addElement(_ref);"); 224 outputln("return _ref;"); 225 outputln("}"); 226 outputln("catch(java.lang.Exception ex){"); 227 outputln("ex.printStackTrace();"); 228 outputln("System.exit(0);"); 229 outputln("}"); 230 outputln("return null;"); 231 outputln("}"); 232 } 233 234 public void constructeurClass(org.omg.mof.Model.Class _class) 235 throws 236 org.omg.mof.Reflective.MofError, 237 org.omg.mof.Reflective.NotSet, 238 BadKind , 239 Bounds , 240 Bounds { 241 242 String _nformat1 = javaHelper.javaClassName(_class); 244 String _cformat1 = javaHelper.javaQualifiedName(_class); 245 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 246 247 if (_class 248 .visibility() 249 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 250 output("public " + _nformat1 + "ClassImpl("); 251 252 org.omg.mof.Model.MofAttribute[] attributesND = 254 mofHelper.allAttributesOfClass( 255 _class, 256 org.omg.mof.Model.ScopeKind.classifier_level, 257 true); 258 259 for (int i = 0; i < attributesND.length; i++) { 260 String _type_format1 = 261 javaHelper.javaType(attributesND[i].type()); 262 String _aformat2 = javaHelper.format2(attributesND[i].name()); 263 if ((attributesND[i].multiplicity().upper > 1) 264 || (attributesND[i].multiplicity().upper == -1)) 265 output(_type_format1 + "[] " + _aformat2 + "s"); 266 else 267 output(_type_format1 + " " + _aformat2); 268 output(", "); 269 } 270 outputln( 271 javaHelper.format1Idl2JavaConflict( 272 _class.container().name() + "Package") 273 + " _model_package) {"); 274 for (int i = 0; i < attributesND.length; i++) { 275 String _aformat2 = javaHelper.format2(attributesND[i].name()); 276 int _lower = attributesND[i].multiplicity().lower; 277 int _upper = attributesND[i].multiplicity().upper; 278 if ((_upper > 1) || (_upper == -1)) { 279 output( 280 "for(int i=0;i<" + _aformat2 + "s.length; i++) "); 281 output( 282 " _" 283 + _aformat2 284 + "s.addElement(" 285 + _aformat2 286 + "s[i]);"); 287 } else { 288 outputln("_" + _aformat2 + " = " + _aformat2 + " ;"); 289 if ((_lower == 0) && (_upper == 1)) 290 outputln("_exist_" + _aformat2 + " = true;"); 291 } 292 } 293 outputln("this._model_package = _model_package ;"); 294 outputln("}"); 295 outputln("}"); 296 297 } 298 } 299 300 public void classProxyImpl(org.omg.mof.Model.Class _class) 301 throws 302 org.omg.mof.Reflective.NotSet, 303 org.omg.mof.Reflective.MofError, 304 BadKind , 305 Bounds { 306 307 String _nformat1 = javaHelper.javaClassName(_class); 310 String _cformat1 = javaHelper.javaQualifiedName(_class); 311 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 312 313 output("package "); 315 316 outputln( 318 javaHelper.javaPackage(PackageHelper.narrow(_class.container())) 319 + ";"); 320 321 outputln( 322 "public class " 323 + _nformat1 324 + "ClassImpl extends " 325 + _cformat1 326 + "ClassPOA {"); 327 outputln( 328 javaHelper.format1Idl2JavaConflict( 329 _class.container().name() + "Package") 330 + " _model_package;"); 331 332 output(javaHelper.refBaseObjectTemplate()); 334 outputln(); 335 output(javaHelper.refObjectTemplate()); 336 337 org.omg.mof.Model.MofAttribute[] attributes = 339 mofHelper.allAttributesOfClass( 340 _class, 341 org.omg.mof.Model.ScopeKind.classifier_level, 342 false); 343 for (int i = 0; i < attributes.length; i++) { 344 if (attributes[i] 345 .visibility() 346 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 347 String _code_attribute = 348 javaHelper.attributeTemplate(attributes[i]); 349 outputln(_code_attribute); 350 } 351 } 352 353 org.omg.mof.Model.Operation[] operations = 355 mofHelper.allOperationsOfClass( 356 _class, 357 org.omg.mof.Model.ScopeKind.classifier_level); 358 for (int i = 0; i < operations.length; i++) { 359 if (operations[i] 360 .visibility() 361 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 362 String _code_operation = 363 javaHelper.operationTemplate(operations[i]); 364 outputln(_code_operation); 365 } 366 } 367 368 java.util.Vector _sup_classes = mofHelper.superClassesOrdered(_class); 376 java.util.Iterator it = _sup_classes.iterator(); 377 while (it.hasNext()) { 378 org.omg.CORBA.Object obj = (org.omg.CORBA.Object )it.next(); 379 if (obj._is_equivalent(_class)) 380 it.remove(); 381 } 382 383 for (int i = 0; i < _sup_classes.size(); i++) { 384 org.omg.mof.Model.Class _current = 385 (org.omg.mof.Model.Class) _sup_classes.elementAt(i); 386 if (_current 387 .visibility() 388 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 389 String _cu_format1 = javaHelper.javaQualifiedName(_current); 390 String _cu_format2 = javaHelper.format2(javaHelper.className(_current)); 391 392 String _cu_format2_ref = getRefMethod(_current, _class.container()); 393 394 if (!_current.is_abstract()) { 396 397 output( 399 "public " 400 + _cu_format1 401 + " create_" 402 + _cu_format2 403 + "("); 404 405 org.omg.mof.Model.MofAttribute attributesND[] = 407 mofHelper.allAttributesOfClass( 408 _current, 409 org.omg.mof.Model.ScopeKind.instance_level, 410 false); 411 for (int j = 0; j < attributesND.length; j++) { 412 String _type_format1 = 413 javaHelper.javaType(attributesND[j].type()); 414 String _aformat2 = 415 javaHelper.format2(attributesND[j].name()); 416 if ((attributesND[j].multiplicity().upper > 1) 417 || (attributesND[j].multiplicity().upper == -1)) { 418 output(_type_format1 + "[] " + _aformat2); 419 } else 420 output(_type_format1 + " " + _aformat2); 421 if (j != (attributesND.length - 1)) 422 output(", "); 423 } 424 outputln(") throws org.omg.mof.Reflective.MofError {"); 425 if (mofHelper.isInSameExtent(_current, _class)) { 426 output( 428 _cu_format1 429 + " _" 430 + _cu_format2 431 + " = _model_package." 432 + _cu_format2_ref 433 + ".create_" 434 + _cu_format2 435 + "("); 436 for (int j = 0; j < attributesND.length; j++) { 437 String _aformat2 = 438 javaHelper.format2(attributesND[j].name()); 439 output(_aformat2); 440 if (j != (attributesND.length - 1)) 441 output(", "); 442 } 443 outputln(");"); 444 outputln("return _" + _cu_format2 + "; "); 445 } else { 446 outputln( 447 "throw new org.omg.mof.Reflective.MofError();"); 448 } 449 outputln("} "); 450 451 outputln( 453 "public " 454 + _cu_format1 455 + "[] all_of_class_" 456 + _cu_format2 457 + "() {"); 458 outputln( 459 _cu_format1 + "[] _" + _cu_format2 + ";"); 460 if (mofHelper.isInSameExtent(_current, _class)) { 461 outputln( 462 "_" 463 + _cu_format2 464 + " = _model_package." 465 + _cu_format2_ref 466 + ".all_of_class_" 467 + _cu_format2 468 + "();"); 469 } else { 470 outputln( 471 "_" 472 + _cu_format2 473 + " = new " 474 + _cu_format1 475 + "[0];"); 476 } 477 outputln("return _" + _cu_format2 + "; "); 478 outputln("} "); 479 } 481 482 outputln( 484 "public " 485 + _cu_format1 486 + "[] all_of_type_" 487 + _cu_format2 488 + "() {"); 489 outputln(_cu_format1 + "[] _" + _cu_format2 + ";"); 490 if (mofHelper.isInSameExtent(_current, _class)) { 491 outputln( 492 "_" 493 + _cu_format2 494 + " = _model_package." 495 + _cu_format2_ref 496 + ".all_of_type_" 497 + _cu_format2 498 + "();"); 499 } else { 500 outputln( 501 "_" 502 + _cu_format2 503 + " = new " 504 + _cu_format1 505 + "[0];"); 506 } 507 outputln("return _" + _cu_format2 + "; "); 508 outputln("} "); 509 } 511 } 512 513 if (!_class.is_abstract()) { 515 createClass(_class); 516 allOfClasses(_class); 517 } 518 519 allOfType(_class); 520 521 constructeurClass(_class); 522 } 523 524 531 private String getRefMethod(org.omg.mof.Model.Class clazz, org.omg.mof.Model.Namespace parent) 532 throws org.omg.mof.Reflective.MofError, org.omg.mof.Reflective.NotSet { 533 String _format2_ref = javaHelper.format2(javaHelper.javaClassName(clazz)) + "_ref()"; 534 try { 535 if (!clazz.container()._is_equivalent(parent)) { 536 _format2_ref = javaHelper.format2(clazz.container().name()) + "_ref()." + _format2_ref; 537 } 538 } catch (org.omg.mof.Reflective.NotSet notSet) { 539 } 541 return _format2_ref; 542 } 543 544 548 public JavaCommon getJavaHelper() { 549 return javaHelper; 550 } 551 552 556 public MOFCommon getMofHelper() { 557 return mofHelper; 558 } 559 560 564 public void setJavaHelper(JavaCommon javaHelper) { 565 this.javaHelper = javaHelper; 566 } 567 568 572 public void setMofHelper(MOFCommon mofHelper) { 573 this.mofHelper = mofHelper; 574 } 575 576 } 577 | Popular Tags |