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 ClassImplementationGenerator 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 Class: " + input[0].name()); 66 classImpl(input[0]); 67 flushFile(); 68 } 69 70 public void constructeurClass(org.omg.mof.Model.Class _class) 71 throws org.omg.mof.Reflective.MofError, org.omg.mof.Reflective.NotSet , BadKind , Bounds { 72 73 String _nformat1 = javaHelper.format1Idl2JavaConflict(javaHelper.javaClassName(_class)); 74 String _cformat1 = javaHelper.javaQualifiedName(_class); 75 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 76 77 if (_class 78 .visibility() 79 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 80 output("public " + _nformat1 + "Impl("); 81 82 org.omg.mof.Model.MofAttribute[] attributesND = 84 mofHelper.allAttributesOfClass( 85 _class, 86 org.omg.mof.Model.ScopeKind.instance_level, 87 false); 88 89 for (int i = 0; i < attributesND.length; i++) { 90 String _type_format1 = javaHelper.javaType(attributesND[i].type()); 91 String _aformat2 = javaHelper.format2(attributesND[i].name()); 92 if ((attributesND[i].multiplicity().upper > 1) 93 || (attributesND[i].multiplicity().upper == -1)) 94 output(_type_format1 + "[] " + _aformat2 + "s"); 95 else 96 output(_type_format1 + " " + _aformat2); 97 output(", "); 98 } 99 outputln(_cformat1 + "Class _proxy){"); 100 for (int i = 0; i < attributesND.length; i++) { 101 String _aformat2 = javaHelper.format2(attributesND[i].name()); 102 int _lower = attributesND[i].multiplicity().lower; 103 int _upper = attributesND[i].multiplicity().upper; 104 if ((_upper > 1) || (_upper == -1)) { 105 output( 106 "for(int i=0;i<" + _aformat2 + "s.length; i++) "); 107 output( 108 " _" 109 + _aformat2 110 + "s.addElement(" 111 + _aformat2 112 + "s[i]);"); 113 } else { 114 outputln("_" + _aformat2 + " = " + _aformat2 + " ;"); 115 if ((_lower == 0) && (_upper == 1)) 116 outputln("_exist_" + _aformat2 + " = true;"); 117 } 118 } 119 outputln("_class_proxy = _proxy ;"); 120 outputln(" }"); 121 outputln("}"); 122 123 } 124 } 125 126 public void allOfType(org.omg.mof.Model.Class _class) 127 throws org.omg.mof.Reflective.MofError , NotSet{ 128 String _cformat1 = javaHelper.javaQualifiedName(_class); 129 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 130 outputln( 131 "public " + _cformat1 + "[] all_of_type_" + _cformat2 + "() {"); 132 outputln("return _class_proxy.all_of_type_" + _cformat2 + "();"); 133 outputln("}"); 134 } 135 136 public void allOfClasses(org.omg.mof.Model.Class _class) 137 throws org.omg.mof.Reflective.MofError , NotSet{ 138 String _cformat1 = javaHelper.javaQualifiedName(_class); 139 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 140 outputln( 141 "public " + _cformat1 + "[] all_of_class_" + _cformat2 + "() {"); 142 outputln( 143 "return _class_proxy.all_of_class_" + _cformat2 + "();"); 144 outputln("}"); 145 } 146 147 public void createClass(org.omg.mof.Model.Class _class) 148 throws org.omg.mof.Reflective.MofError , BadKind , Bounds , NotSet{ 149 String _cformat1 = javaHelper.javaQualifiedName(_class); 150 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 151 if (_class 152 .visibility() 153 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 154 output("public " + _cformat1 + " create_" + _cformat2 + "("); 155 org.omg.mof.Model.MofAttribute[] attributesND = 156 mofHelper.allAttributesOfClass( 157 _class, 158 org.omg.mof.Model.ScopeKind.instance_level, 159 false); 160 for (int i = 0; i < attributesND.length; i++) { 161 String _type_format1 = javaHelper.javaType(attributesND[i].type()); 162 String _aformat2 = javaHelper.format2(attributesND[i].name()); 163 if ((attributesND[i].multiplicity().upper > 1) 164 || (attributesND[i].multiplicity().upper == -1)) 165 output(_type_format1 + "[] " + _aformat2); 166 else 167 output(_type_format1 + " " + _aformat2); 168 if (i != (attributesND.length - 1)) 169 output(", "); 170 } 171 outputln(") throws org.omg.mof.Reflective.MofError {"); 172 output("return _class_proxy.create_" + _cformat2 + "("); 173 for (int i = 0; i < attributesND.length; i++) { 174 String _aformat2 = javaHelper.format2(attributesND[i].name()); 175 output(_aformat2); 176 if (i != (attributesND.length - 1)) 177 output(", "); 178 179 } 180 outputln(");"); 181 outputln("}"); 182 } 183 } 184 185 public void classImpl(org.omg.mof.Model.Class _class) 186 throws org.omg.mof.Reflective.NotSet, org.omg.mof.Reflective.MofError , BadKind , Bounds { 187 188 String _nformat1 = javaHelper.format1Idl2JavaConflict(javaHelper.javaClassName(_class)); 190 String _cformat1 = javaHelper.javaQualifiedName(_class); 191 String _cformat2 = javaHelper.format2(javaHelper.javaClassName(_class)); 192 193 output("package "); 195 196 outputln(javaHelper.javaPackage(PackageHelper.narrow(_class.container())) + " ;"); 198 199 outputln( 200 "public class " 201 + _nformat1 202 + "Impl extends " 203 + _cformat1 204 + "POA {"); 205 outputln(); 206 207 output(javaHelper.refBaseObjectTemplate()); 209 outputln(); 210 output(javaHelper.refObjectTemplate()); 211 212 outputln("private " + _cformat1 + "Class _class_proxy;"); 214 215 org.omg.mof.Model.MofAttribute[] attributesC = 217 mofHelper.allAttributesOfClass( 218 _class, 219 org.omg.mof.Model.ScopeKind.classifier_level, 220 true); 221 for (int i = 0; i < attributesC.length; i++) { 222 if (attributesC[i] 223 .visibility() 224 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 225 String _code_attribute = 226 javaHelper.attributeTemplate(attributesC[i]); 227 outputln(_code_attribute); 228 } 229 } 230 231 org.omg.mof.Model.Operation[] operationsC = 233 mofHelper.allOperationsOfClass( 234 _class, 235 org.omg.mof.Model.ScopeKind.classifier_level); 236 for (int i = 0; i < operationsC.length; i++) { 237 if (operationsC[i] 238 .visibility() 239 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 240 String _code_operation = 241 javaHelper.operationTemplate(operationsC[i]); 242 outputln(_code_operation); 243 } 244 } 245 246 java.util.Vector _sup_classes = mofHelper.superClassesOrdered(_class); 248 249 for (int i = 0; i < _sup_classes.size(); i++) { 251 org.omg.mof.Model.Class _current = 252 (org.omg.mof.Model.Class) _sup_classes.elementAt(i); 253 if (!_current.is_abstract()) { 254 createClass(_current); 255 allOfClasses(_current); 256 } 257 allOfType(_current); 258 } 259 260 org.omg.mof.Model.MofAttribute[] attributes = 262 mofHelper.allAttributesOfClass( 263 _class, 264 org.omg.mof.Model.ScopeKind.instance_level, 265 true); 266 for (int i = 0; i < attributes.length; i++) { 267 if (attributes[i] 268 .visibility() 269 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 270 String _code_attribute = 271 javaHelper.attributeTemplate(attributes[i]); 272 outputln(_code_attribute); 273 } 274 } 275 276 org.omg.mof.Model.Operation[] operations = 278 mofHelper.allOperationsOfClass( 279 _class, 280 org.omg.mof.Model.ScopeKind.instance_level); 281 for (int i = 0; i < operations.length; i++) { 282 if (operations[i] 283 .visibility() 284 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 285 String _code_operation = 286 javaHelper.operationTemplate(operations[i]); 287 outputln(_code_operation); 288 } 289 } 290 291 org.omg.mof.Model.Reference[] references = 293 mofHelper.allReferencesOfClass(_class); 294 for (int i = 0; i < references.length; i++) { 295 if (references[i] 296 .visibility() 297 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 298 String _code_reference = 299 javaHelper.referenceTemplate(references[i]); 300 outputln(_code_reference); 301 } 302 } 303 constructeurClass(_class); 304 } 305 306 310 public JavaCommon getJavaHelper() { 311 return javaHelper; 312 } 313 314 318 public MOFCommon getMofHelper() { 319 return mofHelper; 320 } 321 322 326 public void setJavaHelper(JavaCommon javaHelper) { 327 this.javaHelper = javaHelper; 328 } 329 330 334 public void setMofHelper(MOFCommon mofHelper) { 335 this.mofHelper = mofHelper; 336 } 337 338 } | Popular Tags |