1 20 package org.objectweb.modfact.corba.idl2java; 21 22 import java.util.Vector ; 23 24 import org.omg.CORBA.TypeCodePackage.BadKind ; 25 import org.omg.CORBA.TypeCodePackage.Bounds ; 26 import org.omg.mof.Model.ScopeKind; 27 28 import org.objectweb.modfact.corba.generator.BracketGenerator; 29 import org.objectweb.modfact.corba.helper.JavaCommon; 30 import org.objectweb.modfact.corba.helper.MOFCommon; 31 import org.objectweb.modfact.corba.logging.ModFactLogger; 32 33 public class PackageFactoryImplementationGenerator extends BracketGenerator { 34 35 ModFactLogger logger = null; 36 37 org.omg.mof.Model.Package[] input; 38 39 42 public void setInput(org.omg.mof.Model.ModelElement[] elt) { 43 input = new org.omg.mof.Model.Package[elt.length]; 44 for (int i = 0; i < input.length; i++) { 45 input[i] = (org.omg.mof.Model.Package) elt[i]; 46 } 47 } 48 49 52 public void setLogger(ModFactLogger log) { 53 logger = log; 54 } 55 56 JavaCommon javaHelper; 58 MOFCommon mofHelper; 59 60 61 62 public void generate() 63 throws 64 org.omg.mof.Reflective.NotSet, 65 org.omg.mof.Reflective.MofError, 66 org.omg.CORBA.TypeCodePackage.BadKind , 67 org.omg.CORBA.TypeCodePackage.Bounds { 68 outputln( 69 "// le Code généré du PackageFactory: " 70 + input[0].name() 71 + "PackageFactory"); 72 packageFactoryImpl(input[0]); 73 flushFile(); 74 } 75 76 public void packageFactoryImpl(org.omg.mof.Model.Package _package) 77 throws org.omg.mof.Reflective.NotSet, org.omg.mof.Reflective.MofError , BadKind , Bounds { 78 output("package "); 80 81 String _nformat1 = javaHelper.format1Idl2JavaConflict(_package.name()); 83 String className = javaHelper.format1Idl2JavaConflict(_package.name()+"PackageFactory")+"Impl"; 84 String superClass = javaHelper.format1Idl2JavaConflict(_package.name()+"PackageFactory")+"POA"; 85 String itemType = javaHelper.format1Idl2JavaConflict(_package.name()+"Package"); 86 String itemClass = javaHelper.format1Idl2JavaConflict(_package.name()+"Package")+"Impl"; 87 String _pformat2 = javaHelper.format2(_package.name()); 88 89 outputln(javaHelper.javaPackage(_package) + " ;"); 91 92 outputln( 93 "public class " 94 + className 95 + " extends " 96 + superClass 97 + " {"); 98 99 Vector _attributes = new Vector (); 100 org.omg.mof.Model.Class[] classes = mofHelper.classesOfPackage(_package); 101 for (int i=0 ; i < classes.length ; i++) { 102 org.omg.mof.Model.MofAttribute[] attributes = mofHelper.attributesOfClass(classes[i] , ScopeKind.classifier_level , true); 103 for (int k=0 ; k<attributes.length ; k++) _attributes.addElement(attributes[k]); 104 105 } 106 107 java.util.Vector _attributes_name = 109 new java.util.Vector (_attributes.size()); 110 for (int i = 0; i < _attributes.size(); i++) { 111 org.omg.mof.Model.MofAttribute _current = 112 (org.omg.mof.Model.MofAttribute) _attributes.elementAt(i); 113 String _attributeqname = " "; 114 for (int j = 0; j < _current.qualified_name().length; j++) { 115 if (j > 0) 116 _attributeqname = 117 javaHelper.format2(_current.qualified_name()[j]) 118 + "_" 119 + _attributeqname; 120 else 121 _attributeqname = 122 javaHelper.format2(_current.qualified_name()[j]); 123 } 124 _attributes_name.addElement(_attributeqname); 125 } 126 127 output( 129 "public " 130 + itemType 131 + " create_" 132 + _pformat2 133 + "_package("); 134 for (int i = 0; i < _attributes.size(); i++) { 135 org.omg.mof.Model.MofAttribute _current = 136 (org.omg.mof.Model.MofAttribute) _attributes.elementAt(i); 137 String _current_type = javaHelper.javaType(_current.type()); 138 String _attributeqname = (String ) _attributes_name.elementAt(i); 139 140 if (!((i != 0) || (i != (_attributes.size() - 1)))) 141 output(", "); 142 143 if ((_current.multiplicity().upper > 1) 144 || (_current.multiplicity().upper == -1)) 145 output(_current_type + "[] " + _attributeqname); 146 else 147 output(_current_type + " " + _attributeqname); 148 } 149 outputln(") throws org.omg.mof.Reflective.MofError {"); 150 output( 151 itemClass 152 + " _" 153 + _pformat2 154 + "_package = new " 155 + itemClass 156 + "("); 157 for (int i = 0; i < _attributes_name.size(); i++) { 158 String _attributeqname = (String ) _attributes_name.elementAt(i); 159 if (!((i != 0) || (i != (_attributes.size() - 1)))) 160 output(", "); 161 output(_attributeqname); 162 } 163 outputln(");"); 164 165 outputln("try {"); 166 outputln("_poa().activate_object(_" + _pformat2 + "_package);"); 167 outputln( 168 "org.omg.CORBA.Object obj = _poa().servant_to_reference(_" 169 + _pformat2 170 + "_package);"); 171 outputln("return " + itemType + "Helper.narrow(obj);"); 172 outputln("}"); 173 outputln("catch (java.lang.Exception ex) {"); 174 outputln("ex.printStackTrace();"); 175 outputln("System.exit(0);"); 176 outputln("}"); 177 outputln("return null;"); 178 outputln("}"); 179 outputln("}"); 180 } 181 185 public JavaCommon getJavaHelper() { 186 return javaHelper; 187 } 188 189 193 public MOFCommon getMofHelper() { 194 return mofHelper; 195 } 196 197 201 public void setJavaHelper(JavaCommon javaHelper) { 202 this.javaHelper = javaHelper; 203 } 204 205 209 public void setMofHelper(MOFCommon mofHelper) { 210 this.mofHelper = mofHelper; 211 } 212 213 } | Popular Tags |