KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CodeGen > JavaGenerator


1 /* $Id: JavaGenerator.java,v 1.5 2004/05/20 14:23:51 bures Exp $ */
2 package SOFA.SOFAnode.Made.CodeGen;
3
4 import java.io.IOException JavaDoc;
5 import java.rmi.RemoteException JavaDoc;
6
7 import javax.xml.parsers.DocumentBuilder JavaDoc;
8 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
9 import javax.xml.parsers.ParserConfigurationException JavaDoc;
10 import javax.xml.transform.Transformer JavaDoc;
11 import javax.xml.transform.TransformerConfigurationException JavaDoc;
12 import javax.xml.transform.TransformerException JavaDoc;
13 import javax.xml.transform.TransformerFactory JavaDoc;
14 import javax.xml.transform.dom.DOMSource JavaDoc;
15 import javax.xml.transform.stream.StreamResult JavaDoc;
16
17 import org.w3c.dom.Document JavaDoc;
18 import org.w3c.dom.Element JavaDoc;
19 import org.w3c.dom.Text JavaDoc;
20
21 import SOFA.SOFAnode.Made.TIR.AbsoluteName;
22 import SOFA.SOFAnode.Made.TIR.ArchitectureDef;
23 import SOFA.SOFAnode.Made.TIR.ArrayDef;
24 import SOFA.SOFAnode.Made.TIR.AttrMode;
25 import SOFA.SOFAnode.Made.TIR.AttributeDef;
26 import SOFA.SOFAnode.Made.TIR.BindDef;
27 import SOFA.SOFAnode.Made.TIR.BindMode;
28 import SOFA.SOFAnode.Made.TIR.BindOperKind;
29 import SOFA.SOFAnode.Made.TIR.BindOperProvReq;
30 import SOFA.SOFAnode.Made.TIR.BindOperSub;
31 import SOFA.SOFAnode.Made.TIR.BindType;
32 import SOFA.SOFAnode.Made.TIR.BindTypeArray;
33 import SOFA.SOFAnode.Made.TIR.BindTypeKind;
34 import SOFA.SOFAnode.Made.TIR.BindTypeNormal;
35 import SOFA.SOFAnode.Made.TIR.CDLType;
36 import SOFA.SOFAnode.Made.TIR.ConstantDef;
37 import SOFA.SOFAnode.Made.TIR.Contained;
38 import SOFA.SOFAnode.Made.TIR.Container;
39 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
40 import SOFA.SOFAnode.Made.TIR.EnumDef;
41 import SOFA.SOFAnode.Made.TIR.EnumMember;
42 import SOFA.SOFAnode.Made.TIR.ExceptionDef;
43 import SOFA.SOFAnode.Made.TIR.ExprBinOperationDef;
44 import SOFA.SOFAnode.Made.TIR.ExprBoolean;
45 import SOFA.SOFAnode.Made.TIR.ExprChar;
46 import SOFA.SOFAnode.Made.TIR.ExprConstant;
47 import SOFA.SOFAnode.Made.TIR.ExprDouble;
48 import SOFA.SOFAnode.Made.TIR.ExprFixed;
49 import SOFA.SOFAnode.Made.TIR.ExprFloat;
50 import SOFA.SOFAnode.Made.TIR.ExprLong;
51 import SOFA.SOFAnode.Made.TIR.ExprLongDouble;
52 import SOFA.SOFAnode.Made.TIR.ExprLongLong;
53 import SOFA.SOFAnode.Made.TIR.ExprOctet;
54 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
55 import SOFA.SOFAnode.Made.TIR.ExprOperKind;
56 import SOFA.SOFAnode.Made.TIR.ExprProperty;
57 import SOFA.SOFAnode.Made.TIR.ExprShort;
58 import SOFA.SOFAnode.Made.TIR.ExprString;
59 import SOFA.SOFAnode.Made.TIR.ExprUnOperationDef;
60 import SOFA.SOFAnode.Made.TIR.ExprUnsigLong;
61 import SOFA.SOFAnode.Made.TIR.ExprUnsigLongLong;
62 import SOFA.SOFAnode.Made.TIR.ExprUnsigShort;
63 import SOFA.SOFAnode.Made.TIR.ExprWchar;
64 import SOFA.SOFAnode.Made.TIR.ExprWstring;
65 import SOFA.SOFAnode.Made.TIR.FrameDef;
66 import SOFA.SOFAnode.Made.TIR.Identification;
67 import SOFA.SOFAnode.Made.TIR.InstDef;
68 import SOFA.SOFAnode.Made.TIR.InterfaceDef;
69 import SOFA.SOFAnode.Made.TIR.OperationDef;
70 import SOFA.SOFAnode.Made.TIR.ParamDescr;
71 import SOFA.SOFAnode.Made.TIR.ParamMode;
72 import SOFA.SOFAnode.Made.TIR.PropertyDef;
73 import SOFA.SOFAnode.Made.TIR.ProvideDef;
74 import SOFA.SOFAnode.Made.TIR.Repository;
75 import SOFA.SOFAnode.Made.TIR.RequireDef;
76 import SOFA.SOFAnode.Made.TIR.SequenceDef;
77 import SOFA.SOFAnode.Made.TIR.StructDef;
78 import SOFA.SOFAnode.Made.TIR.StructMember;
79 import SOFA.SOFAnode.Made.TIR.TIRExceptCalculate;
80 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
81 import SOFA.SOFAnode.Made.TIR.TypedefDef;
82
83 /** Class containing methods for generating all "things" in repository to java.
84   *
85   * @author Petr Hnetynka
86   */

87 public class JavaGenerator {
88
89   ObjectList allObjects; // objects to generate
90
GenObjectList genObjects; // generated objects
91
CGFileAccess fs; // file manipulation
92
GenObjectList pregenIfaces; // pregenerated interface names
93
ArchitectureDef[] archToGen; // architectures to generate
94
/** Info about generated files. */
95   GenFileList genFiles;
96
97   boolean typesonly;
98
99   /** Constructor */
100   public JavaGenerator(ObjectList allObjects, ArchitectureDef[] archToGen) throws IOException JavaDoc {
101     this.allObjects = allObjects;
102     this.genObjects = new GenObjectList();
103     this.genFiles = new GenFileList();
104     this.archToGen = archToGen;
105
106     PrimitiveGeneratedObject.createPrimGenerObjects(genObjects);
107
108     String JavaDoc curDir = System.getProperty("codegen.dir", null);
109     boolean rewrite = Boolean.valueOf(System.getProperty("codegen.rewrite", "true")).booleanValue();
110     
111     if (curDir == null) { // use current dir
112
fs = new CGFileAccess(".", rewrite);
113     } else { // use dir specified in the property
114
fs = new CGFileAccess(curDir, rewrite);
115     }
116     typesonly = false;
117   }
118
119   /** Constructor
120     * @param typesonly typesonly property
121     */

122   public JavaGenerator(ObjectList allObjects, boolean typesonly) throws IOException JavaDoc {
123     this.allObjects = allObjects;
124     this.genObjects = new GenObjectList();
125     this.genFiles = new GenFileList();
126     this.typesonly = typesonly;
127
128     PrimitiveGeneratedObject.createPrimGenerObjects(genObjects);
129
130     String JavaDoc curDir = System.getProperty("codegen.dir", null);
131     boolean rewrite = Boolean.valueOf(System.getProperty("codegen.rewrite", "true")).booleanValue();
132     
133     if (curDir == null) { // use current dir
134
fs = new CGFileAccess(".", rewrite);
135     } else { // use dir specified in the property
136
fs = new CGFileAccess(curDir, rewrite);
137     }
138   }
139
140   /** Run generation of code.
141     *
142     * @exception GenerationException generation error (probably error in TIR)
143     * @exception IOException i/o exception
144     * @exception RemoteException remote exception
145     */

146   public void generate() throws RemoteException JavaDoc, GenerException, IOException JavaDoc {
147     pregenIfaces = pregenIfaceNames();
148     Debug.println("---- begin of pregenIfaces ----");
149     Debug.println(pregenIfaces);
150     Debug.println("---- end of pregenIfaces ----");
151     for (int i=allObjects.size()-1; i>=0 ; i--) {
152       Contained current = allObjects.getObject(i);
153       CGFileWriter out = null;
154       boolean closeOut = true;
155       String JavaDoc name = current.get_identification().name();
156       if (GeneratedObject.isReservedName(name))
157         name = "_"+name;
158       AbsoluteName absN = current.get_identification().absolute_name();
159       String JavaDoc pkg = CGFileAccess.absToPkg(absN);
160       Debug.println("Currently generated object: "+absN.name());
161  
162       switch (current.get_def_kind().value()) {
163         case DefinitionKind.dk_Constant:
164           out = fs.newCGWriter(CGFileAccess.absToPath(absN, name, true));
165           generateConstant((ConstantDef) current, out, name, pkg);
166           break;
167         case DefinitionKind.dk_Enum:
168           out = fs.newCGWriter(CGFileAccess.absToPath(absN, name, true));
169           generateEnum((EnumDef) current, out, name, CGFileAccess.absToPath(absN, name, false), pkg);
170           break;
171         case DefinitionKind.dk_Struct:
172           out = fs.newCGWriter(CGFileAccess.absToPath(absN, name, true));
173           generateStruct((StructDef) current, out, name, CGFileAccess.absToPath(absN, name, false), pkg);
174           break;
175         case DefinitionKind.dk_Exception:
176           out = fs.newCGWriter(CGFileAccess.absToPath(absN, name, true));
177           generateException((ExceptionDef) current, out, name, CGFileAccess.absToPath(absN, name, false), pkg);
178           break;
179         case DefinitionKind.dk_Typedef:
180           //out = fs.newCGWriter(CGFileAccess.absToPath(absN, name, true));
181
closeOut = false;
182           generateTypedef((TypedefDef) current, name, CGFileAccess.absToPath(absN, name, false), pkg);
183           break;
184         case DefinitionKind.dk_Interface:
185           out = fs.newCGWriter(CGFileAccess.absToPath(absN, name, true));
186           generateInterface((InterfaceDef) current, out, name, CGFileAccess.absToPath(absN, name, false), pkg);
187           break;
188         default:
189           out = fs.newCGWriter(CGFileAccess.absToPath(absN, name, true));
190           out.iwriteln("Currently, I don't know, how to generate this object.");
191       }
192       if (closeOut)
193         out.close();
194     }
195     
196     if (!typesonly) {
197       // generate component builders
198
for (int i=0;i<archToGen.length; i++) {
199         boolean isPrimitive = false;
200         try {
201           if (archToGen[i].contents(null).length == 0)
202             isPrimitive = true;
203         } catch (TIRExceptLock e) {
204           throw new GenerException(Res.res.getString("MSG_LockedTIR"));
205         }
206         CGFileWriter out = null;
207         String JavaDoc name = archToGen[i].get_identification().name();
208         if (GeneratedObject.isReservedName(name))
209           name = "_"+name;
210         AbsoluteName absN = archToGen[i].get_identification().absolute_name();
211         String JavaDoc pkg = CGFileAccess.archAbsToPkg(absN);
212         String JavaDoc provider = absN.elementAt(0);
213         out = fs.newCGWriter(CGFileAccess.archAbsToPath(absN, name+"Builder", true));
214         generateBuilder(archToGen[i], out, provider, name, pkg);
215         out.close();
216         if (isPrimitive) {
217           out = fs.newCGWriter(CGFileAccess.archAbsToPath(absN, "_Base"+name+"Impl", true));
218           generateBaseImpl(archToGen[i], out, provider, name, pkg);
219           out.close();
220           String JavaDoc implName = CGFileAccess.archAbsToPath(absN, name+"Impl", true);
221           if (!fs.exists(implName)) {
222             out = fs.newCGWriter(implName);
223             generateRealImplSkel(archToGen[i], out, provider, name, pkg);
224             out.close();
225           }
226         }
227         generateComponentInfoFile(archToGen[i], absN, name, pkg+"."+name+"Builder");
228       }
229     }
230
231   }
232
233   /** Pregenerate names of interfaces (neccessary for forward declaration of interfaces).
234     */

235   private GenObjectList pregenIfaceNames() throws RemoteException JavaDoc {
236     JavaMapping jm = new JavaMapping();
237     GenObjectList ret = new GenObjectList();
238     //System.out.println(allObjects.size());
239
for(int i=0; i<allObjects.size(); i++) {
240       Contained obj = allObjects.getObject(i);
241       if (obj instanceof CDLType) {
242         ret.add(new ContainedGeneratedObject(obj, jm.getImplTypeName((CDLType) obj)));
243       }
244     }
245     return ret;
246   }
247
248   /** Returns the object with specified key. It searchs in the generated objects and also in the pregenarated objest.
249     *
250     * @param key key of the searched object
251     * @return the searched object; returns <B>null</B> if the object is not found.
252     */

253   private GeneratedObject searchObject(String JavaDoc key) {
254     GeneratedObject ret = null;
255     if ((ret = genObjects.searchObject(key)) == null) {
256       ret = pregenIfaces.searchObject(key);
257     }
258     return ret;
259   }
260
261   /** Return string with concrete number.
262     */

263   private String JavaDoc getNumber(ExprOperDef expr) throws GenerException, RemoteException JavaDoc, PropException {
264     GeneratedObject genObj;
265     String JavaDoc key;
266     switch (expr.get_eok_kind().value()) {
267     case ExprOperKind.eok_boolean:
268       if ( ((ExprBoolean) expr).value() )
269         return ("true");
270       else
271         return ("false");
272     case ExprOperKind.eok_char:
273       return ( ((ExprChar) expr).toString() );
274     case ExprOperKind.eok_constant:
275       ExprConstant exprc = (ExprConstant) expr;
276       key = GeneratedObject.createKey(exprc.ref_const());
277       genObj = searchObject(key);
278       if (genObj == null)
279         throw new GenerException(Res.res.getString("MSG_TIRError")+"\n"+key+" "+Res.res.getString("MSG_CantBeGenerated"));
280       return genObj.genReference(GeneratedObject.INREF);
281     case ExprOperKind.eok_double:
282       return (Double.toString( ((ExprDouble) expr).value() ));
283     case ExprOperKind.eok_fixed:
284       ExprFixed exprf = (ExprFixed) expr;
285       return ("new java.math.BigDecimal("+exprf.value().toString()+")");
286     case ExprOperKind.eok_float:
287       return (Float.toString( ((ExprFloat) expr).value() ));
288     case ExprOperKind.eok_long:
289       return (Long.toString( ((ExprLong) expr).value() ));
290     case ExprOperKind.eok_longdouble:
291       return (Double.toString( ((ExprLongDouble) expr).value() ));
292     case ExprOperKind.eok_longlong:
293       return (Long.toString( ((ExprLongLong) expr).value() ));
294     case ExprOperKind.eok_octet:
295       return (Byte.toString( ((ExprOctet) expr).value() ));
296     case ExprOperKind.eok_short:
297       return (Short.toString( ((ExprShort) expr).value() ));
298     case ExprOperKind.eok_string:
299       return ( ((ExprString) expr).value() );
300     case ExprOperKind.eok_unsiglong:
301       return (Long.toString( ((ExprUnsigLong) expr).value() ));
302     case ExprOperKind.eok_unsiglonglong:
303       return (Long.toString( ((ExprUnsigLongLong) expr).value() ));
304     case ExprOperKind.eok_unsigshort:
305       return (Short.toString( ((ExprUnsigShort) expr).value() ));
306     case ExprOperKind.eok_wchar:
307       return ( ((ExprWchar) expr).toString() );
308     case ExprOperKind.eok_wstring:
309       return ( ((ExprWstring) expr).value() );
310     case ExprOperKind.eok_property:
311       throw new PropException(Res.res.getString("MSG_PropInExpr"));
312     }
313     return "";
314   }
315
316   /** Directly write concrete number to the out writer.
317     */

318   private void writeNumber(ExprOperDef expr, CGFileWriter out) throws GenerException, IOException JavaDoc, RemoteException JavaDoc, PropException {
319     GeneratedObject genObj;
320     String JavaDoc key;
321     switch (expr.get_eok_kind().value()) {
322     case ExprOperKind.eok_boolean:
323       if ( ((ExprBoolean) expr).value() )
324         out.iwrite("true");
325       else
326         out.iwrite("false");
327       break;
328     case ExprOperKind.eok_char:
329       out.iwrite( ((ExprChar) expr).value() );
330       break;
331     case ExprOperKind.eok_constant:
332       ExprConstant exprc = (ExprConstant) expr;
333       key = GeneratedObject.createKey(exprc.ref_const());
334       genObj = searchObject(key);
335       if (genObj == null)
336         throw new GenerException(Res.res.getString("MSG_TIRError")+"\n"+key+" "+Res.res.getString("MSG_CantBeGenerated"));
337       genObj.genReference(out, GeneratedObject.INREF);
338       break;
339     case ExprOperKind.eok_double:
340       out.iwrite(Double.toString( ((ExprDouble) expr).value() ));
341       break;
342     case ExprOperKind.eok_fixed:
343       ExprFixed exprf = (ExprFixed) expr;
344       out.iwrite("new java.math.BigDecimal("+exprf.value().toString()+")");
345       break;
346     case ExprOperKind.eok_float:
347       out.iwrite(Float.toString( ((ExprFloat) expr).value() ));
348       break;
349     case ExprOperKind.eok_long:
350       out.iwrite(Long.toString( ((ExprLong) expr).value() ));
351       break;
352     case ExprOperKind.eok_longdouble:
353       out.iwrite(Double.toString( ((ExprLongDouble) expr).value() ));
354       break;
355     case ExprOperKind.eok_longlong:
356       out.iwrite(Long.toString( ((ExprLongLong) expr).value() ));
357       break;
358     case ExprOperKind.eok_octet:
359       out.iwrite(Byte.toString( ((ExprOctet) expr).value() ));
360       break;
361     case ExprOperKind.eok_short:
362       out.iwrite(Short.toString( ((ExprShort) expr).value() ));
363       break;
364     case ExprOperKind.eok_string:
365       out.iwrite( ((ExprString) expr).value() );
366       break;
367     case ExprOperKind.eok_unsiglong:
368       out.iwrite(Long.toString( ((ExprUnsigLong) expr).value() ));
369       break;
370     case ExprOperKind.eok_unsiglonglong:
371       out.iwrite(Long.toString( ((ExprUnsigLongLong) expr).value() ));
372       break;
373     case ExprOperKind.eok_unsigshort:
374       out.iwrite(Short.toString( ((ExprUnsigShort) expr).value() ));
375       break;
376     case ExprOperKind.eok_wchar:
377       out.iwrite( ((ExprWchar) expr).value() );
378       break;
379     case ExprOperKind.eok_wstring:
380       out.iwrite( ((ExprWstring) expr).value() );
381       break;
382     case ExprOperKind.eok_property:
383       throw new PropException(Res.res.getString("MSG_PropInExpr"));
384     }
385   }
386
387   /** Directly write expression (can be with properties) to the out writer.
388     */

389   private String JavaDoc expressionWithPropertyToString(ExprOperDef expr) throws GenerException, IOException JavaDoc, RemoteException JavaDoc, PropException {
390     GeneratedObject genObj;
391     String JavaDoc key;
392     StringBuffer JavaDoc ret;
393     switch (expr.get_eok_kind().value()) {
394     case ExprOperKind.eok_boolean:
395       if ( ((ExprBoolean) expr).value() )
396         return "true";
397       else
398         return "false";
399     case ExprOperKind.eok_char:
400       return "" + ((ExprChar) expr).value() ;
401     case ExprOperKind.eok_constant:
402       ExprConstant exprc = (ExprConstant) expr;
403       key = GeneratedObject.createKey(exprc.ref_const());
404       genObj = searchObject(key);
405       if (genObj == null)
406         throw new GenerException(Res.res.getString("MSG_TIRError")+"\n"+key+" "+Res.res.getString("MSG_CantBeGenerated"));
407       return genObj.genReference(GeneratedObject.INREF);
408     case ExprOperKind.eok_double:
409       return (Double.toString( ((ExprDouble) expr).value() ));
410     case ExprOperKind.eok_fixed:
411       ExprFixed exprf = (ExprFixed) expr;
412       return ("new java.math.BigDecimal("+exprf.value().toString()+")");
413     case ExprOperKind.eok_float:
414       return (Float.toString( ((ExprFloat) expr).value() ));
415     case ExprOperKind.eok_long:
416       return (Long.toString( ((ExprLong) expr).value() ));
417     case ExprOperKind.eok_longdouble:
418       return (Double.toString( ((ExprLongDouble) expr).value() ));
419     case ExprOperKind.eok_longlong:
420       return (Long.toString( ((ExprLongLong) expr).value() ));
421     case ExprOperKind.eok_octet:
422       return (Byte.toString( ((ExprOctet) expr).value() ));
423     case ExprOperKind.eok_short:
424       return (Short.toString( ((ExprShort) expr).value() ));
425     case ExprOperKind.eok_string:
426       return ( ((ExprString) expr).value() );
427     case ExprOperKind.eok_unsiglong:
428       return (Long.toString( ((ExprUnsigLong) expr).value() ));
429     case ExprOperKind.eok_unsiglonglong:
430       return (Long.toString( ((ExprUnsigLongLong) expr).value() ));
431     case ExprOperKind.eok_unsigshort:
432       return (Short.toString( ((ExprUnsigShort) expr).value() ));
433     case ExprOperKind.eok_wchar:
434       return "" + ((ExprWchar) expr).value() ;
435     case ExprOperKind.eok_wstring:
436       return ( ((ExprWstring) expr).value() );
437     case ExprOperKind.eok_property:
438       return ( "_prop_"+((ExprProperty) expr).ref_prop() );
439     case ExprOperKind.eok_unminus:
440       ret = new StringBuffer JavaDoc("(-");
441       ret.append(expressionWithPropertyToString( ((ExprUnOperationDef) expr).operand() ));
442       ret.append(")");
443       return ret.toString();
444     case ExprOperKind.eok_unplus:
445       ret = new StringBuffer JavaDoc("(+");
446       ret.append(expressionWithPropertyToString( ((ExprUnOperationDef) expr).operand()));
447       return ret.append(")").toString();
448     case ExprOperKind.eok_or:
449       ret = new StringBuffer JavaDoc("(");
450       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
451       ret.append("||");
452       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
453       return ret.append(")").toString();
454     case ExprOperKind.eok_xor:
455       ret = new StringBuffer JavaDoc("(");
456       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
457       ret.append("^");
458       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
459       return ret.append(")").toString();
460     case ExprOperKind.eok_and:
461       ret = new StringBuffer JavaDoc("(");
462       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
463       ret.append("&&");
464       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
465       return ret.append(")").toString();
466     case ExprOperKind.eok_shr:
467       ret = new StringBuffer JavaDoc("(");
468       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
469       ret.append(">>");
470       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
471       return ret.append(")").toString();
472     case ExprOperKind.eok_shl:
473       ret = new StringBuffer JavaDoc("(");
474       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
475       ret.append(">>");
476       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
477       return ret.append(")").toString();
478     case ExprOperKind.eok_plus:
479       ret = new StringBuffer JavaDoc("(");
480       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
481       ret.append("+");
482       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
483       return ret.append(")").toString();
484     case ExprOperKind.eok_minus:
485       ret = new StringBuffer JavaDoc("(");
486       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
487       ret.append("-");
488       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
489       return ret.append(")").toString();
490     case ExprOperKind.eok_mul:
491       ret = new StringBuffer JavaDoc("(");
492       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
493       ret.append("*");
494       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
495       return ret.append(")").toString();
496     case ExprOperKind.eok_div:
497       ret = new StringBuffer JavaDoc("(");
498       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
499       ret.append("/");
500       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
501       return ret.append(")").toString();
502     case ExprOperKind.eok_mod:
503       ret = new StringBuffer JavaDoc("(");
504       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand1()));
505       ret.append("%");
506       ret.append(expressionWithPropertyToString( ((ExprBinOperationDef) expr).operand2()));
507       return ret.append(")").toString();
508     }
509     return "";
510   }
511   
512   /** Generates expression to the out writer.
513     *
514     * @param expr generated expresion
515     * @param out genrate to this writer
516     * @exception GenerationException generation error (probably error in TIR)
517     * @exception IOException i/o exception
518     * @exception RemoteException remote exception
519     */

520   public void generateExpression(ExprOperDef expr, CGFileWriter out) throws GenerException, IOException JavaDoc, RemoteException JavaDoc {
521     try {
522       ExprOperDef res = expr.calculate();
523       // expression can be generated as a one number
524
try {
525         writeNumber(res, out);
526       } catch (PropException pe) {
527         throw new GenerException(pe.getMessage());
528       }
529       return;
530     } catch (TIRExceptCalculate e) {
531       ; // it cannot be calculate (contains properties or enum members....)
532
}
533   }
534   
535   /** Genrates constant mapping to the out writer.
536     *
537     * @param obj generated constant
538     * @param out generate to this writer
539     * @param name short name of constanta
540     * @param pkg package name
541     * @exception GenerationException generation error (probably error in TIR)
542     * @exception IOException i/o exception
543     * @exception RemoteException remote exception
544     */

545   public void generateConstant(ConstantDef obj, CGFileWriter out, String JavaDoc name, String JavaDoc pkg) throws GenerException, IOException JavaDoc, RemoteException JavaDoc {
546     Container parent = obj.get_defined_in();
547     String JavaDoc key = GeneratedObject.createKey(obj.type());
548     GeneratedObject type = searchObject(key);
549     if (type == null) {
550       throw new GenerException(Res.res.getString("MSG_ReferenceTo")+" "+key+" "+Res.res.getString("MSG_CantBeGenerated"));
551     }
552      
553     if (parent instanceof InterfaceDef) { // constant within interface
554
type.genReference(out, GeneratedObject.INREF);
555       out.iwritespace(1);
556       out.iwrite(name);
557       out.iwrite(" = ");
558       generateExpression(obj.value(), out);
559       out.iwriteln(" ;"); out.iwriteln();
560       genObjects.add(new ContainedGeneratedObject(obj, pkg+"."+name)); //!!! konstanty uvnitr interfacu!!!
561
} else {
562       out.iwriteln("package "+pkg+";");
563       out.iwriteln();
564       printHeadComment(contained2string(obj), out);
565       out.iwrite("public interface ");
566       out.iwrite(name);
567       out.iwriteln(" {");
568       out.incIndent();
569       out.iwrite("public static ");
570       type.genReference(out, GeneratedObject.INREF);
571       out.iwrite(" value = ");
572       generateExpression(obj.value(), out);
573       out.iwriteln(" ;");
574       out.decIndent();
575       out.iwriteln("};");
576       genObjects.add(new ContainedGeneratedObject(obj, pkg+"."+name+".value"));
577       genFiles.addNewObject(pkg+"."+name,contained2string(obj));
578     }
579   }
580
581   /** Genrates enum mapping to the out writer.
582     *
583     * @param obj generated enum
584     * @param out generate to this writer
585     * @param absName absolute name of writer without ".java" extension
586     * @param shortName short name
587     * @param pkg package name
588     * @exception GenerationException generation error (probably error in TIR)
589     * @exception IOException i/o exception
590     * @exception RemoteException remote exception
591     */

592   public void generateEnum(EnumDef obj, CGFileWriter out, String JavaDoc shortName, String JavaDoc absName, String JavaDoc pkg) throws GenerException, IOException JavaDoc, RemoteException JavaDoc {
593     try {
594       EnumMember[] membs = obj.members();
595       out.iwriteln("package "+pkg+";");
596       out.iwriteln();
597       printHeadComment(contained2string(obj),out);
598       out.iwriteln("public class "+shortName+" implements "+GeneratedObject.stdPackage+"CDLEntity {");
599       out.incIndent();
600       printCDLIdField(obj, out, false);
601       out.iwriteln("private int __value;");
602       out.iwriteln("private static int __size = "+Integer.toString(membs.length)+";");
603       out.iwriteln("private static "+pkg+"."+shortName+"[] __array = new "+pkg+"."+shortName+"[__size];");
604       out.iwriteln();
605       for (int i=0;i<membs.length; i++) {
606         String JavaDoc mname = membs[i].name();
607         out.iwriteln("public static final int _"+mname+" = "+Integer.toString(i)+";");
608         out.iwriteln("public static final "+pkg+"."+shortName+" "+mname+" = new "+pkg+"."+shortName+"(_"+mname+");");
609       }
610       out.iwriteln();
611       out.iwriteln("public int value () {");
612       out.iwriteln(" return __value;");
613       out.iwriteln("}");
614       out.iwriteln();
615       out.iwriteln("public static "+pkg+"."+shortName+" from_int(int value) {");
616       out.iwriteln(" if (value >= 0 && value < __size)");
617       out.iwriteln(" return __array[value];");
618       out.iwriteln(" else");
619       out.iwriteln(" throw new "+GeneratedObject.stdPackage+"BAD_PARAM();");
620       out.iwriteln("}");
621       out.iwriteln();
622       out.iwriteln("protected Barvy (int value) {");
623       out.iwriteln(" __value = value;");
624       out.iwriteln(" __array[__value] = this;");
625       out.iwriteln("}");
626       out.decIndent();
627       out.iwriteln("}"); // end of generating of the enum
628

629 // if (!typesonly) {
630
createHolder( absName+"Holder.java", shortName,pkg);
631   
632         // create enum helper
633
CGFileWriter outHelp = fs.newCGWriter(absName+"Helper.java");
634         outHelp.iwriteln("package "+pkg+";");
635         outHelp.iwriteln();
636         printHeadComment(null, outHelp);
637         outHelp.iwriteln("abstract public class "+shortName+"Helper {");
638         outHelp.incIndent();
639         outHelp.iwriteln("public static "+pkg+"."+shortName+" read("+GeneratedObject.stdPackage+"InputStream istream) throws java.io.IOException {");
640         outHelp.iwriteln(" return "+pkg+"."+shortName+".from_int(istream.read_long ());");
641         outHelp.iwriteln("}");
642         outHelp.iwriteln();
643         outHelp.iwriteln("public static void write("+GeneratedObject.stdPackage+"OutputStream ostream, "+pkg+"."+shortName+" value) throws java.io.IOException {");
644         outHelp.iwriteln(" ostream.write_long (value.value ());");
645         outHelp.iwriteln("}");
646         outHelp.iwriteln();
647         
648         outHelp.decIndent();
649         outHelp.iwriteln("}");
650         outHelp.close();
651 // }
652

653       genObjects.add(new ContainedGeneratedObject(obj, pkg+"."+shortName));
654       genFiles.addNewObject(pkg+"."+shortName,contained2string(obj));
655       genFiles.addNewObject(pkg+"."+shortName+"Holder",contained2string(obj));
656       genFiles.addNewObject(pkg+"."+shortName+"Helper",contained2string(obj));
657     } catch (TIRExceptLock e) {
658       throw new GenerException(Res.res.getString("MSG_LockedTIR"));
659     }
660   }
661
662   private class StructMemberInfo {
663     String JavaDoc name;
664     GeneratedObject type;
665     public StructMemberInfo(String JavaDoc name, GeneratedObject type) {
666       this.name = name;
667       this.type = type;
668     }
669   }
670
671   /** Genrates struct mapping to the out writer.
672     *
673     * @param obj generated struct
674     * @param out generate to this writer
675     * @param absName absolute name of writer without ".java" extension
676     * @param shortName short name
677     * @param pkg package name
678     * @exception GenerationException generation error (probably error in TIR)
679     * @exception IOException i/o exception
680     * @exception RemoteException remote exception
681     */

682   public void generateStruct(StructDef obj, CGFileWriter out, String JavaDoc shortName, String JavaDoc absName, String JavaDoc pkg) throws GenerException, IOException JavaDoc, RemoteException JavaDoc {
683     try {
684       Contained[] cont = obj.contents(null);
685       out.iwriteln("package "+pkg+";");
686       out.iwriteln();
687       printHeadComment(contained2string(obj),out);
688       out.iwriteln("public final class "+shortName+" implements "+GeneratedObject.stdPackage+"CDLEntity {");
689       out.incIndent();
690       printCDLIdField(obj, out, false);
691       
692       String JavaDoc key;
693       GeneratedObject type;
694       StructMemberInfo smi;
695       // array for already generated struct members
696
java.util.ArrayList JavaDoc genContent = new java.util.ArrayList JavaDoc(cont.length);
697       CGFileWriter outInner;
698       Identification idInner;
699       String JavaDoc nameInner;
700       for (int i=0;i<cont.length;i++) { // go through all objects defined in the struct
701
switch (cont[i].get_def_kind().value()) {
702         case DefinitionKind.dk_StructMember:
703           StructMember sm = (StructMember) cont[i];
704           key = GeneratedObject.createKey(sm.type());
705           type = searchObject(key);
706           if (type == null) {
707             throw new GenerException(Res.res.getString("MSG_ReferenceTo")+" "+key+" "+Res.res.getString("MSG_CantBeGenerated"));
708           }
709           smi = new StructMemberInfo(sm.name(), type);
710           out.iwriteln("public "+smi.type.genReference(GeneratedObject.INREF)+" "+smi.name+" = "+smi.type.defaultValue()+";");
711           genContent.add(smi);
712           break;
713         case DefinitionKind.dk_Struct:
714           StructDef strd = (StructDef) cont[i];
715           idInner = strd.get_identification();
716           nameInner = idInner.name();
717           outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
718           generateStruct(strd, outInner, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
719           break;
720         case DefinitionKind.dk_Exception:
721           ExceptionDef excd = (ExceptionDef) cont[i];
722           idInner = excd.get_identification();
723           nameInner = idInner.name();
724           outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
725           generateException(excd, outInner, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
726           break;
727         case DefinitionKind.dk_Enum:
728           EnumDef enmd = (EnumDef) cont[i];
729           idInner = enmd.get_identification();
730           nameInner = idInner.name();
731           outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
732           generateEnum(enmd, outInner, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
733           break;
734         }
735       }
736
737       out.iwriteln();
738       out.iwriteln("public "+shortName+"() {}");
739       out.iwriteln();
740       out.iwrite("public "+shortName+"(");
741       for (int i=0;i<genContent.size();i++) {
742         smi = (StructMemberInfo) genContent.get(i);
743         out.iwrite(smi.type.genReference(GeneratedObject.INREF)+" _"+smi.name);
744         if (i!=genContent.size() - 1)
745           out.iwrite(", ");
746       }
747       out.iwriteln(") {");
748       out.incIndent();
749       for (int i=0;i<genContent.size();i++) {
750         smi = (StructMemberInfo) genContent.get(i);
751         out.iwriteln(smi.name+" = _"+smi.name+";");
752       }
753       out.decIndent();
754       out.iwriteln("}");
755       
756       out.decIndent();
757       out.iwriteln("}"); // end of generating of the struct
758

759 // if (!typesonly) {
760
createHolder( absName+"Holder.java", shortName,pkg);
761        
762         // create struct helper
763
CGFileWriter outHelp = fs.newCGWriter(absName+"Helper.java");
764         outHelp.iwriteln("package "+pkg+";");
765         outHelp.iwriteln();
766         printHeadComment(null, outHelp);
767         outHelp.iwriteln("abstract public class "+shortName+"Helper {");
768         outHelp.incIndent();
769         outHelp.iwriteln("public static "+pkg+"."+shortName+" read("+GeneratedObject.stdPackage+"InputStream istream) throws java.io.IOException {");
770         outHelp.iwriteln(" "+shortName+" value = new "+shortName+"();");
771         for (int i=0;i<genContent.size();i++) {
772           smi = (StructMemberInfo) genContent.get(i);
773           outHelp.iwriteln(" "+smi.type.genReadType("value."+smi.name)+";");
774         }
775         outHelp.iwriteln(" return value;");
776         outHelp.iwriteln("}");
777         outHelp.iwriteln();
778         outHelp.iwriteln("public static void write("+GeneratedObject.stdPackage+"OutputStream ostream, "+pkg+"."+shortName+" value) throws java.io.IOException {");
779         for (int i=0;i<genContent.size();i++) {
780           smi = (StructMemberInfo) genContent.get(i);
781           outHelp.iwriteln(" "+ smi.type.genWriteType("value."+smi.name) +";");
782         }
783         outHelp.iwriteln("}");
784         outHelp.iwriteln();
785         
786         outHelp.decIndent();
787         outHelp.iwriteln("}");
788         outHelp.close();
789 // }
790

791       genObjects.add(new ContainedGeneratedObject(obj, pkg+"."+shortName));
792       genFiles.addNewObject(pkg+"."+shortName,contained2string(obj));
793       genFiles.addNewObject(pkg+"."+shortName+"Holder",contained2string(obj));
794       genFiles.addNewObject(pkg+"."+shortName+"Helper",contained2string(obj));
795     } catch (TIRExceptLock e) {
796       throw new GenerException(Res.res.getString("MSG_LockedTIR"));
797     }
798   }
799   
800   /** Genrates exception mapping to the out writer.
801     *
802     * @param obj generated exception
803     * @param out generate to this writer
804     * @param absName absolute name of writer without ".java" extension
805     * @param shortName short name
806     * @param pkg package name
807     * @exception GenerationException generation error (probably error in TIR)
808     * @exception IOException i/o exception
809     * @exception RemoteException remote exception
810     */

811   public void generateException(ExceptionDef obj, CGFileWriter out, String JavaDoc shortName, String JavaDoc absName, String JavaDoc pkg) throws GenerException, IOException JavaDoc, RemoteException JavaDoc {
812     try {
813       Contained[] cont = obj.contents(null);
814       out.iwriteln("package "+pkg+";");
815       out.iwriteln();
816       printHeadComment(contained2string(obj),out);
817       out.iwriteln("public final class "+shortName+" extends "+GeneratedObject.stdPackage+"UserException {");
818       out.incIndent();
819       printCDLIdField(obj, out, false);
820       
821       String JavaDoc key;
822       GeneratedObject type;
823       StructMemberInfo smi;
824       // array for already generated struct members
825
java.util.ArrayList JavaDoc genContent = new java.util.ArrayList JavaDoc(cont.length);
826       CGFileWriter outInner;
827       Identification idInner;
828       String JavaDoc nameInner;
829       for (int i=0;i<cont.length;i++) { // go through all objects defined in the struct
830
switch (cont[i].get_def_kind().value()) {
831         case DefinitionKind.dk_StructMember:
832           StructMember sm = (StructMember) cont[i];
833           key = GeneratedObject.createKey(sm.type());
834           type = searchObject(key);
835           if (type == null) {
836             throw new GenerException(Res.res.getString("MSG_ReferenceTo")+" "+key+" "+Res.res.getString("MSG_CantBeGenerated"));
837           }
838           smi = new StructMemberInfo(sm.name(), type);
839           out.iwriteln("public "+smi.type.genReference(GeneratedObject.INREF)+" "+smi.name+" = "+smi.type.defaultValue()+";");
840           genContent.add(smi);
841           break;
842         case DefinitionKind.dk_Struct:
843           StructDef strd = (StructDef) cont[i];
844           idInner = strd.get_identification();
845           nameInner = idInner.name();
846           outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
847           generateStruct(strd, outInner, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
848           break;
849         case DefinitionKind.dk_Exception:
850           ExceptionDef excd = (ExceptionDef) cont[i];
851           idInner = excd.get_identification();
852           nameInner = idInner.name();
853           outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
854           generateException(excd, outInner, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
855           break;
856         case DefinitionKind.dk_Enum:
857           EnumDef enmd = (EnumDef) cont[i];
858           idInner = enmd.get_identification();
859           nameInner = idInner.name();
860           outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
861           generateEnum(enmd, outInner, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
862           break;
863         }
864       }
865
866       out.iwriteln();
867       out.iwriteln("public "+shortName+"() {"); // default constructor
868
out.iwriteln(" super();");
869       out.iwriteln("}"); // end of default constructor
870
out.iwriteln();
871       if (genContent.size()!=0) {
872         out.iwrite("public "+shortName+"("); // consructor
873
for (int i=0;i<genContent.size();i++) {
874           smi = (StructMemberInfo) genContent.get(i);
875           out.iwrite(smi.type.genReference(GeneratedObject.INREF)+" _"+smi.name);
876           if (i!=genContent.size() - 1)
877             out.iwrite(", ");
878         }
879         out.iwriteln(") {");
880         out.incIndent();
881         out.iwriteln("super();");
882         for (int i=0;i<genContent.size();i++) {
883           smi = (StructMemberInfo) genContent.get(i);
884           out.iwriteln(smi.name+" = _"+smi.name+";");
885         }
886         out.decIndent();
887         out.iwriteln("}"); //end of constructor
888
out.iwriteln();
889       }
890       out.iwrite("public "+shortName+"(String __reason"); // full consructor
891
for (int i=0;i<genContent.size();i++) {
892         out.iwrite(", ");
893         smi = (StructMemberInfo) genContent.get(i);
894         out.iwrite(smi.type.genReference(GeneratedObject.INREF)+" _"+smi.name);
895       }
896       out.iwriteln(") {");
897       out.incIndent();
898       out.iwriteln("super(__reason);");
899       for (int i=0;i<genContent.size();i++) {
900         smi = (StructMemberInfo) genContent.get(i);
901         out.iwriteln(smi.name+" = _"+smi.name+";");
902       }
903       out.decIndent();
904       out.iwriteln("}\n"); //end of full constructor
905

906       out.iwrite("public "+shortName+"(String __reason, Throwable __cause"); // full consructor with cause
907
for (int i=0;i<genContent.size();i++) {
908         out.iwrite(", ");
909         smi = (StructMemberInfo) genContent.get(i);
910         out.iwrite(smi.type.genReference(GeneratedObject.INREF)+" _"+smi.name);
911       }
912       out.iwriteln(") {");
913       out.incIndent();
914       out.iwriteln("super(__reason, __cause);");
915       for (int i=0;i<genContent.size();i++) {
916         smi = (StructMemberInfo) genContent.get(i);
917         out.iwriteln(smi.name+" = _"+smi.name+";");
918       }
919       out.decIndent();
920       out.iwriteln("}"); //end of full constructor with cause
921

922       out.decIndent();
923       
924       out.decIndent();
925       out.iwriteln("}"); // end of generating of the exception
926

927 // if (!typesonly) {
928
createHolder( absName+"Holder.java", shortName,pkg);
929        
930         // create exception helper
931
CGFileWriter outHelp = fs.newCGWriter(absName+"Helper.java");
932         outHelp.iwriteln("package "+pkg+";");
933         outHelp.iwriteln();
934         printHeadComment(null, outHelp);
935         outHelp.iwriteln("abstract public class "+shortName+"Helper {");
936         outHelp.incIndent();
937         outHelp.iwriteln("public static "+pkg+"."+shortName+" read("+GeneratedObject.stdPackage+"InputStream istream) throws java.io.IOException {");
938         outHelp.iwriteln(" "+shortName+" value = new "+shortName+"();");
939         for (int i=0;i<genContent.size();i++) {
940           smi = (StructMemberInfo) genContent.get(i);
941           outHelp.iwriteln(" "+smi.type.genReadType("value."+smi.name)+";");
942         }
943         outHelp.iwriteln(" return value;");
944         outHelp.iwriteln("}");
945         outHelp.iwriteln();
946         outHelp.iwriteln("public static void write("+GeneratedObject.stdPackage+"OutputStream ostream, "+pkg+"."+shortName+" value) throws java.io.IOException {");
947         for (int i=0;i<genContent.size();i++) {
948           smi = (StructMemberInfo) genContent.get(i);
949           outHelp.iwriteln(" "+ smi.type.genWriteType("value."+smi.name) +";");
950         }
951         outHelp.iwriteln("}");
952         outHelp.iwriteln();
953         
954         outHelp.decIndent();
955         outHelp.iwriteln("}");
956         outHelp.close();
957 // }
958

959       genObjects.add(new ContainedGeneratedObject(obj, pkg+"."+shortName));
960       genFiles.addNewObject(pkg+"."+shortName,contained2string(obj));
961       genFiles.addNewObject(pkg+"."+shortName+"Holder",contained2string(obj));
962       genFiles.addNewObject(pkg+"."+shortName+"Helper",contained2string(obj));
963     } catch (TIRExceptLock e) {
964       throw new GenerException(Res.res.getString("MSG_LockedTIR"));
965     }
966   }
967
968
969   /** Genrates interface mapping to the out writer.
970     *
971     * @param obj generated interface
972     * @param out generate to this writer
973     * @param absName absolute name of writer without ".java" extension
974     * @param shortName short name
975     * @param pkg package name
976     * @exception GenerationException generation error (probably error in TIR)
977     * @exception IOException i/o exception
978     * @exception RemoteException remote exception
979     */

980   public void generateInterface(InterfaceDef obj, CGFileWriter out, String JavaDoc shortName, String JavaDoc absName, String JavaDoc pkg) throws GenerException, IOException JavaDoc, RemoteException JavaDoc {
981     try {
982       out.iwriteln("package "+pkg+";");
983       out.iwriteln();
984       printHeadComment(contained2string(obj),out);
985       InterfaceDef[] base = obj.base_interfaces();
986       // begin of head of interface
987
out.iwrite("public interface "+shortName+" extends "+shortName+"Operations, ");
988       for (int i=0; i< base.length; i++) {
989         GeneratedObject bitem = searchObject(GeneratedObject.createKey(base[i]));
990         out.iwrite(bitem.genReference(GeneratedObject.INREF));
991         out.iwrite(", ");
992       }
993       out.iwriteln(GeneratedObject.stdPackage+"CDLEntity, org.objectweb.fractal.api.Interface {");
994       // end of head of interface
995
printCDLIdField(obj, out, true);
996       out.iwriteln("}");
997
998       // begin of ...Operation genration inteface
999
Contained[] cont = obj.contents(null);
1000      CGFileWriter outOp = fs.newCGWriter(absName+"Operations.java");
1001      outOp.iwriteln("package "+pkg+";");
1002      outOp.iwriteln();
1003      outOp.iwriteln();
1004      printHeadComment(contained2string(obj), outOp);
1005      outOp.iwrite("public interface "+shortName+"Operations ");
1006      outOp.iwrite("extends ");
1007      if (base.length != 0) {
1008        for(int i=0; i<base.length;i++) {
1009          GeneratedObject bitem = searchObject(GeneratedObject.createKey(base[i]));
1010          outOp.iwrite(bitem.genReference(GeneratedObject.INREF));
1011          outOp.iwrite("Operations");
1012// if (i != base.length-1) {
1013
outOp.iwrite(", ");
1014// }
1015
}
1016      }
1017      outOp.iwriteln("org.objectweb.fractal.api.InterfaceOperations {");
1018      outOp.incIndent();
1019      CGFileWriter outInner;
1020      Identification idInner;
1021      String JavaDoc nameInner;
1022      GeneratedObject genObj;
1023      String JavaDoc key;
1024      for(int i=0; i< cont.length; i++) {
1025        switch (cont[i].get_def_kind().value()) {
1026        case DefinitionKind.dk_Struct:
1027          StructDef strd = (StructDef) cont[i];
1028          idInner = strd.get_identification();
1029          nameInner = idInner.name();
1030          outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
1031          generateStruct(strd, outInner, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
1032          break;
1033       case DefinitionKind.dk_Exception:
1034          ExceptionDef excd = (ExceptionDef) cont[i];
1035          idInner = excd.get_identification();
1036          nameInner = idInner.name();
1037          outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
1038          generateException(excd, outInner, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
1039          break;
1040        case DefinitionKind.dk_Typedef:
1041          TypedefDef typd = (TypedefDef) cont[i];
1042          idInner = typd.get_identification();
1043          nameInner = idInner.name();
1044          generateTypedef(typd, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
1045          break;
1046        case DefinitionKind.dk_Constant:
1047          ConstantDef cnstd = (ConstantDef) cont[i];
1048          idInner = cnstd.get_identification();
1049          nameInner = idInner.name();
1050          outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
1051          generateConstant(cnstd, outInner, nameInner, pkg+"."+shortName+"Package");
1052          break;
1053        case DefinitionKind.dk_Enum:
1054          EnumDef enmd = (EnumDef) cont[i];
1055          idInner = enmd.get_identification();
1056          nameInner = idInner.name();
1057          outInner = fs.newCGWriter(absName+"Package"+java.io.File.separator+nameInner+".java");
1058          generateEnum(enmd, outInner, nameInner, absName+"Package"+java.io.File.separator+nameInner, pkg+"."+shortName+"Package");
1059          break;
1060        case DefinitionKind.dk_Attribute:
1061          AttributeDef attrd = (AttributeDef) cont[i];
1062          idInner = attrd.get_identification();
1063          nameInner = idInner.name();
1064          if (GeneratedObject.isReservedName(nameInner)) {
1065            nameInner = "_"+nameInner;
1066          }
1067          key = GeneratedObject.createKey(attrd.type());
1068          genObj = searchObject(key);
1069          if (genObj == null) {
1070            throw new GenerException(Res.res.getString("MSG_TIRError")+"\n"+key+" "+Res.res.getString("MSG_CantBeGenerated"));
1071          }
1072          String JavaDoc inRef = genObj.genReference(GeneratedObject.INREF);
1073          outOp.iwriteln(inRef+" "+nameInner+"();");
1074          if (attrd.mode().value() == AttrMode.ATTR_NORMAL) {
1075            outOp.iwriteln("void "+nameInner+"("+inRef+" new"+nameInner+");");
1076          }
1077          break;
1078        case DefinitionKind.dk_Operation:
1079          OperationDef opd = (OperationDef) cont[i];
1080          idInner = opd.get_identification();
1081          nameInner = idInner.name();
1082          if (GeneratedObject.isReservedName(nameInner)) {
1083            nameInner = "_"+nameInner;
1084          }
1085          key = GeneratedObject.createKey(opd.result());
1086          genObj = searchObject(key);
1087          if (genObj == null) {
1088            throw new GenerException(Res.res.getString("MSG_TIRError")+"\n"+key+" "+Res.res.getString("MSG_CantBeGenerated"));
1089          }
1090          outOp.iwrite(genObj.genReference(GeneratedObject.INREF)+" "+nameInner+"(");
1091          ParamDescr[] params = opd.params();
1092          for (int j=0; j<params.length ;j++ ) {
1093            String JavaDoc pName = params[j].name();
1094            if (GeneratedObject.isReservedName(pName)) {
1095              pName = "_"+pName;
1096            }
1097            key = GeneratedObject.createKey(params[j].type());
1098            genObj = searchObject(key);
1099            if (genObj == null) {
1100              throw new GenerException(Res.res.getString("MSG_TIRError")+"\n"+key+" "+Res.res.getString("MSG_CantBeGenerated"));
1101            }
1102            if (params[j].mode().value() != ParamMode.PARAM_IN ) {
1103              outOp.iwrite(genObj.genReference(GeneratedObject.OUTREF)+" ");
1104            } else {
1105              outOp.iwrite(genObj.genReference(GeneratedObject.INREF)+" ");
1106            }
1107            outOp.iwrite(pName);
1108            if (j!=params.length-1) {
1109              outOp.iwrite(", ");
1110            }
1111          }
1112          outOp.iwrite(") ");
1113          ExceptionDef[] excs = opd.exceptions();
1114          if (excs.length != 0) {
1115            outOp.iwrite("throws ");
1116            for (int j=0; j<excs.length; j++) {
1117              key = GeneratedObject.createKey(excs[j]);
1118              genObj = searchObject(key);
1119              if (genObj == null) {
1120                throw new GenerException(Res.res.getString("MSG_TIRError")+"\n"+key+" "+Res.res.getString("MSG_CantBeGenerated"));
1121              }
1122              outOp.iwrite(genObj.genReference(GeneratedObject.INREF));
1123              if (j != excs.length-1 ) {
1124                outOp.iwrite(", ");
1125              }
1126            }
1127          }
1128          outOp.iwriteln(";");
1129          break;
1130        }
1131      }
1132      outOp.decIndent();
1133      outOp.iwriteln("}");
1134      outOp.close();
1135
1136      // end of ...Operation generation
1137

1138// if (!typesonly) {
1139
createHolder( absName+"Holder.java", shortName,pkg);
1140        
1141        // create interface helper
1142
CGFileWriter outHelp = fs.newCGWriter(absName+"Helper.java");
1143        outHelp.iwriteln("package "+pkg+";");
1144        outHelp.iwriteln();
1145        printHeadComment(null, outHelp);
1146        outHelp.iwriteln("abstract public class "+shortName+"Helper {");
1147        outHelp.incIndent();
1148        outHelp.iwriteln("public static "+pkg+"."+shortName+" read("+GeneratedObject.stdPackage+"InputStream istream) throws java.io.IOException {");
1149        // !!! doplnit telo metody read
1150
outHelp.iwriteln(" return null;");
1151        outHelp.iwriteln("}");
1152        outHelp.iwriteln();
1153        outHelp.iwriteln("public static void write("+GeneratedObject.stdPackage+"OutputStream ostream, "+pkg+"."+shortName+" value) throws java.io.IOException {");
1154        // !!! doplnit telo metody write
1155
outHelp.iwriteln("}");
1156        outHelp.iwriteln();
1157  
1158        outHelp.decIndent();
1159        outHelp.iwriteln("}");
1160        outHelp.close();
1161// }
1162

1163      genObjects.add(new ContainedGeneratedObject(obj, pkg+"."+shortName));
1164      genFiles.addNewObject(pkg+"."+shortName,contained2string(obj));
1165      genFiles.addNewObject(pkg+"."+shortName+"Operations",contained2string(obj));
1166      genFiles.addNewObject(pkg+"."+shortName+"Holder",contained2string(obj));
1167      genFiles.addNewObject(pkg+"."+shortName+"Helper",contained2string(obj));
1168    } catch (TIRExceptLock e) {
1169      throw new GenerException(Res.res.getString("MSG_LockedTIR"));
1170    }
1171  }
1172
1173
1174
1175  private class TypedefArrayInfo {
1176    String JavaDoc length;
1177    public TypedefArrayInfo(String JavaDoc l) {
1178      length = l;
1179    }
1180  }
1181
1182  /** generates brackets
1183    * @param number number of brackets
1184    */

1185  static String JavaDoc genBrackets(int number) {
1186    StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1187    for (int i =0; i<number;i++) {
1188      sb.append("[]");
1189    }
1190    return sb.toString();
1191  }
1192
1193  /** generates for cycle. i.e. "for(index=0; index &grth; max; index++) {"
1194    */

1195  private String JavaDoc generateFor(String JavaDoc index, String JavaDoc max) {
1196    return "for (int "+index+" = 0; "+index+" < ("+max+"); "+index+"++) {";
1197  }
1198
1199  /** generates array filled brackets. i.e. name[indexPrefix0][indexPrefix1]...
1200    */

1201  private String JavaDoc generateArray(String JavaDoc name, String JavaDoc indexPrefix, int number) {
1202    StringBuffer JavaDoc sb = new StringBuffer JavaDoc(name);
1203    for (int i=0; i<number; i++) {
1204      sb.append("[");
1205      sb.append(indexPrefix);
1206      sb.append(Integer.toString(i));
1207      sb.append("]");
1208    }
1209    return sb.toString();
1210  }
1211
1212  /** Genrates typedef mapping (only helper and holder).
1213    *
1214    * @param obj generated typedef
1215    * @param absName absolute name of writer without ".java" extension
1216    * @param shortName short name
1217    * @param pkg package name
1218    * @exception GenerationException generation error (probably error in TIR)
1219    * @exception IOException i/o exception
1220    * @exception RemoteException remote exception
1221    */

1222  public void generateTypedef(TypedefDef obj, String JavaDoc shortName, String JavaDoc absName, String JavaDoc pkg) throws GenerException, IOException JavaDoc, RemoteException JavaDoc {
1223// try {
1224

1225      java.util.ArrayList JavaDoc arrInfo = new java.util.ArrayList JavaDoc();
1226      java.util.ArrayList JavaDoc seqInfo = new java.util.ArrayList JavaDoc();
1227      boolean ok = false;
1228      CDLType lastType = obj.original_type();
1229      
1230      TypedefArrayInfo tdi = null;
1231      while (!ok) {
1232        switch (lastType.get_def_kind().value()) {
1233          case DefinitionKind.dk_Array:
1234            String JavaDoc len;
1235            try {
1236              len = getNumber(((ArrayDef) lastType).length());
1237            } catch (PropException pe) {
1238              len = null;
1239            }
1240            tdi = new TypedefArrayInfo(len);
1241            arrInfo.add(tdi);
1242            lastType = ((ArrayDef) lastType).element_type();
1243            break;
1244          case DefinitionKind.dk_Sequence:
1245            try {
1246              tdi = new TypedefArrayInfo(getNumber(((SequenceDef) lastType).bound()));
1247            } catch (PropException pe) {
1248              ; // cannot be here
1249
}
1250            seqInfo.add(tdi);
1251            lastType = ((SequenceDef) lastType).element_type();
1252            break;
1253          default:
1254            ok = true;
1255            break;
1256        }
1257      }
1258
1259      String JavaDoc origKey = GeneratedObject.createKey(lastType);
1260      GeneratedObject generObj = searchObject(origKey);
1261      String JavaDoc inRef = generObj.genReference(GeneratedObject.INREF);
1262
1263      if (arrInfo.size() == 0 && seqInfo.size()==0) { //there is no array or sequence in this typedef
1264
switch (lastType.get_def_kind().value()) {
1265        case DefinitionKind.dk_Primitive:
1266        case DefinitionKind.dk_String:
1267        case DefinitionKind.dk_Wstring:
1268        case DefinitionKind.dk_Typedef: // generate nothing, use original types
1269
genObjects.add(new ContainedGeneratedObject(obj, inRef, generObj.genReference(GeneratedObject.OUTREF)));
1270          return;
1271        default: // use original types, generate Helper only
1272
genObjects.add(new ContainedGeneratedObject(obj, inRef, generObj.genReference(GeneratedObject.OUTREF)));
1273// if (!typesonly) {
1274
// generate helper
1275
CGFileWriter outHelp = fs.newCGWriter(absName+"Helper.java");
1276            outHelp.iwriteln("package "+pkg+";");
1277            outHelp.iwriteln();
1278            printHeadComment(null, outHelp);
1279            outHelp.iwriteln("abstract public class "+shortName+"Helper {");
1280            outHelp.incIndent();
1281            outHelp.iwriteln("public static "+inRef+" read("+GeneratedObject.stdPackage+"InputStream istream) {");
1282            outHelp.iwriteln(" "+inRef+" value = null;");
1283            outHelp.iwriteln(" "+generObj.genReadType("value")+";");
1284            outHelp.iwriteln(" return value;");
1285            outHelp.iwriteln("}");
1286            outHelp.iwriteln();
1287            outHelp.iwriteln("public static void write("+GeneratedObject.stdPackage+"OutputStream ostream, "+inRef+" value) {");
1288            outHelp.iwriteln(" "+ generObj.genWriteType("value") +";");
1289            outHelp.iwriteln("}");
1290            outHelp.iwriteln();
1291      
1292            outHelp.decIndent();
1293            outHelp.iwriteln("}");
1294            outHelp.close();
1295// }
1296
return;
1297        }
1298      }
1299    
1300      int bracketNum = arrInfo.size() + seqInfo.size();
1301// if (!typesonly) {
1302
createTypedefHolder( absName+"Holder.java", shortName,pkg, inRef+genBrackets(bracketNum));
1303        // create helper
1304
CGFileWriter outHelp = fs.newCGWriter(absName+"Helper.java");
1305        outHelp.iwriteln("package "+pkg+";");
1306        outHelp.iwriteln();
1307        printHeadComment(null, outHelp);
1308        outHelp.iwriteln("abstract public class "+shortName+"Helper {");
1309        outHelp.incIndent();
1310        outHelp.iwriteln("public static "+inRef+genBrackets(bracketNum)+" read("+GeneratedObject.stdPackage+"InputStream istream) throws java.io.IOException {");
1311        outHelp.incIndent();
1312        //begin of read method body
1313
outHelp.iwriteln(inRef+" value"+genBrackets(bracketNum)+" = null;");
1314        for(int i=0; i<arrInfo.size(); i++) {
1315          if (((TypedefArrayInfo)arrInfo.get(i)).length == null) {
1316            outHelp.iwriteln("int _len"+Integer.toString(i)+" = istream.read_long();");
1317            outHelp.iwriteln(generateArray("value","_o",i)+" = new "+inRef+"[_len"+Integer.toString(i)+"]"+genBrackets(bracketNum-i-1)+";");
1318            outHelp.iwriteln(generateFor("_o"+Integer.toString(i), generateArray("value","_o",i)+".length"));
1319          } else {
1320            outHelp.iwriteln(generateArray("value","_o",i)+" = new "+inRef+"["+((TypedefArrayInfo)arrInfo.get(i)).length+"]"+genBrackets(bracketNum-i-1)+";");
1321            outHelp.iwriteln(generateFor("_o"+Integer.toString(i), ((TypedefArrayInfo)arrInfo.get(i)).length));
1322          }
1323          outHelp.incIndent();
1324        }
1325        for(int i=arrInfo.size(); i<bracketNum;i++) {
1326          outHelp.iwriteln("int _len"+Integer.toString(i)+" = istream.read_long();");
1327          outHelp.iwriteln(generateArray("value","_o",i)+" = new "+inRef+"[_len"+Integer.toString(i)+"]"+genBrackets(bracketNum-i-1)+";");
1328          outHelp.iwriteln(generateFor("_o"+Integer.toString(i), generateArray("value","_o",i)+".length"));
1329          outHelp.incIndent();
1330        }
1331        outHelp.iwriteln(generObj.genReadType(generateArray("value", "_o", bracketNum))+";");
1332        for (int i=0; i<bracketNum; i++) {
1333          outHelp.decIndent();
1334          outHelp.iwriteln("}");
1335        }
1336        outHelp.iwriteln("return value;");
1337        // end of read method body
1338
outHelp.decIndent();
1339        outHelp.iwriteln("}");
1340        outHelp.iwriteln();
1341  
1342        outHelp.iwriteln("public static void write("+GeneratedObject.stdPackage+"OutputStream ostream, "+inRef+genBrackets(bracketNum)+" value) throws java.io.IOException {");
1343        outHelp.incIndent();
1344        // begin of write method body
1345
for(int i=0; i<arrInfo.size(); i++) {
1346          if (((TypedefArrayInfo)arrInfo.get(i)).length == null) {
1347            outHelp.iwriteln("ostream.write_long("+generateArray("value","_i",i-arrInfo.size())+".length);");
1348            outHelp.iwriteln(generateFor("_i"+Integer.toString(i), generateArray("value", "_i",i-arrInfo.size())+".length"));
1349          } else {
1350            outHelp.iwriteln(generateFor("_i"+Integer.toString(i), ((TypedefArrayInfo)arrInfo.get(i)).length));
1351          }
1352          outHelp.incIndent();
1353        }
1354        for(int i=arrInfo.size(); i<bracketNum;i++) {
1355          outHelp.iwriteln("ostream.write_long("+generateArray("value","_i",i-arrInfo.size())+".length);");
1356          outHelp.iwriteln(generateFor("_i"+Integer.toString(i), generateArray("value", "_i",i-arrInfo.size())+".length"));
1357          outHelp.incIndent();
1358        }
1359        outHelp.iwriteln(generObj.genWriteType(generateArray("value", "_i", bracketNum))+";");
1360        for (int i=0; i<bracketNum; i++) {
1361          outHelp.decIndent();
1362          outHelp.iwriteln("}");
1363        }
1364        // end of write method body
1365
outHelp.decIndent();
1366        outHelp.iwriteln("}");
1367        outHelp.iwriteln();
1368  
1369        outHelp.decIndent();
1370        outHelp.iwriteln("}");
1371        outHelp.close();
1372// }
1373

1374      genObjects.add(new ContainedGeneratedObject(obj, inRef+genBrackets(bracketNum), pkg+"."+shortName+"Holder"));
1375      genFiles.addNewObject(pkg+"."+shortName+"Holder",contained2string(obj));
1376      genFiles.addNewObject(pkg+"."+shortName+"Helper",contained2string(obj));
1377      
1378 // } catch (TIRExceptLock e) {
1379
// throw new GenerException(Res.res.getString("MSG_LockedTIR"));
1380
// }
1381
}
1382
1383
1384
1385
1386  
1387
1388  /** Print head comment (date, etc.) to writer.
1389    * @param out output writer
1390    * @param tirID textual form of identification from TIR
1391    * @exception IOException i/o exception
1392    */

1393  private void printHeadComment(String JavaDoc tirID, CGFileWriter out) throws IOException JavaDoc {
1394    java.util.Date JavaDoc date = java.util.Calendar.getInstance().getTime();
1395    java.text.DateFormat JavaDoc df = java.text.DateFormat.getDateTimeInstance(java.text.DateFormat.FULL, java.text.DateFormat.FULL);
1396    out.iwriteln("/**");
1397    out.iwriteln(" * "+Res.res.getString("MSG_GeneratedBy")+" SOFA CodeGen");
1398    if (tirID != null) {
1399      out.iwriteln(" * "+tirID);
1400    }
1401    out.iwriteln(" * "+df.format(date));
1402    out.iwriteln(" */");
1403    out.iwriteln();
1404  }
1405
1406  /** Prints field (public static final) CDLID that contains the string with full ID of the object for which
1407    * this class/interface is generated.
1408    *
1409    * @param contained TIR object
1410    * @param out output writer
1411    * @param isInterface true if generated object is interface
1412    * @throws IOException i/o exception
1413    */

1414  private void printCDLIdField(Contained contained, CGFileWriter out, boolean isInterface) throws IOException JavaDoc {
1415    out.iwriteln();
1416    if (!isInterface) {
1417      out.iwriteln("public static final ");
1418    }
1419    out.iwriteln("String _CDLID = \""+contained2string(contained)+"\";");
1420    out.iwriteln();
1421  }
1422
1423  /** Creates holder for given name.
1424    *
1425    * @param fileName name of file
1426    * @param name short name without Helper sufix
1427    * @param pkg package
1428    * @exception IOException i/o exception
1429    */

1430  private void createHolder(String JavaDoc fileName, String JavaDoc name, String JavaDoc pkg) throws IOException JavaDoc {
1431    CGFileWriter out = fs.newCGWriter(fileName);
1432    out.iwriteln("package "+pkg+";");
1433    out.iwriteln();
1434    printHeadComment(null,out);
1435    out.iwriteln("public class "+name+"Holder implements "+GeneratedObject.stdPackage+"Streamable, java.io.Serializable {");
1436    out.incIndent();
1437    out.iwriteln("public "+pkg+"."+name+" value = null;");
1438    out.iwriteln();
1439    out.iwriteln("public "+name+"Holder() {}");
1440    out.iwriteln();
1441    out.iwriteln("public "+name+"Holder("+pkg+"."+name+" initialValue) {");
1442    out.iwriteln(" value = initialValue;");
1443    out.iwriteln("}");
1444    out.iwriteln();
1445    out.iwriteln("public void _read("+GeneratedObject.stdPackage+"InputStream i) throws java.io.IOException {");
1446    out.iwriteln(" "+pkg+"."+name+"Helper.read(i);");
1447    out.iwriteln("}");
1448    out.iwriteln();
1449    out.iwriteln("public void _write("+GeneratedObject.stdPackage+"OutputStream o) throws java.io.IOException {");
1450    out.iwriteln(" "+pkg+"."+name+"Helper.write(o, value);");
1451    out.iwriteln("}");
1452    out.decIndent();
1453    out.iwriteln("}");
1454    out.close();
1455  }
1456
1457 /** Creates holder for given name of typedef.
1458    *
1459    * @param fileName name of file
1460    * @param name short name without Holder sufix
1461    * @param pkg package
1462    * @param type read / write type
1463    * @exception IOException i/o exception
1464    */

1465  private void createTypedefHolder(String JavaDoc fileName, String JavaDoc name, String JavaDoc pkg, String JavaDoc type) throws IOException JavaDoc {
1466    CGFileWriter out = fs.newCGWriter(fileName);
1467    out.iwriteln("package "+pkg+";");
1468    out.iwriteln();
1469    printHeadComment(null,out);
1470    out.iwriteln("public class "+name+"Holder implements "+GeneratedObject.stdPackage+"Streamable, java.io.Serializable {");
1471    out.incIndent();
1472    out.iwriteln("public "+type+" value = null;");
1473    out.iwriteln();
1474    out.iwriteln("public "+name+"Holder() {}");
1475    out.iwriteln();
1476    out.iwriteln("public "+name+"Holder("+type+" initialValue) {");
1477    out.iwriteln(" value = initialValue;");
1478    out.iwriteln("}");
1479    out.iwriteln();
1480    out.iwriteln("public void _read("+GeneratedObject.stdPackage+"InputStream i) throws java.io.IOException {");
1481    out.iwriteln(" "+pkg+"."+name+"Helper.read(i);");
1482    out.iwriteln("}");
1483    out.iwriteln();
1484    out.iwriteln("public void _write("+GeneratedObject.stdPackage+"OutputStream o) throws java.io.IOException {");
1485    out.iwriteln(" "+pkg+"."+name+"Helper.write(o, value);");
1486    out.iwriteln("}");
1487    out.decIndent();
1488    out.iwriteln("}");
1489    out.close();
1490  }
1491
1492  private String JavaDoc contained2string(Contained obj) throws RemoteException JavaDoc {
1493    Identification id = obj.get_identification();
1494    StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1495    sb.append(id.absolute_name().name());
1496    sb.append("?");
1497    sb.append(id.version());
1498    return sb.toString();
1499  }
1500
1501  private void generateBuilder(ArchitectureDef arch, CGFileWriter out, String JavaDoc provider, String JavaDoc name, String JavaDoc pkg) throws IOException JavaDoc, RemoteException JavaDoc, GenerException {
1502    Contained[] insts = null;
1503    boolean isPrimitive = false;
1504    java.util.ArrayList JavaDoc instInfos = null;
1505    boolean isSystem = arch.is_system();
1506    try {
1507      insts = arch.contents(((Repository) arch.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Inst));
1508      if (insts.length == 0)
1509        isPrimitive = true;
1510    } catch (TIRExceptLock e) {
1511      throw new GenerException(Res.res.getString("MSG_LockedTIR"));
1512    }
1513    
1514  
1515    out.iwriteln("package "+pkg+";");
1516    out.iwriteln();
1517    printHeadComment("Component builder "+Res.res.getString("MSG_For")+" "+contained2string(arch),out);
1518    out.iwriteln("public class "+name+"Builder extends SOFA.Component.DCUP.ComponentBuilderImpl {");
1519    out.incIndent();
1520    out.iwriteln("// "+Res.res.getString("MSG_DefinedInAncestor"));
1521    out.iwriteln("// protected SOFA.Component.ComponentManager cm;");
1522    out.iwriteln("// protected SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor dd;");
1523    out.iwriteln();
1524    if (isPrimitive) {
1525      out.iwriteln(name+"Impl impl;");
1526      out.iwriteln();
1527    } else {
1528      instInfos = new java.util.ArrayList JavaDoc();
1529      // generating: obtaining of dd of subcomponents
1530
for (int i=0; i<insts.length; i++) {
1531        InstInfo iInfo = InstInfo.getInstInfo(insts[i]);
1532        instInfos.add(iInfo);
1533        out.iwriteln("SOFA.Component.DCUP.DCUPComponentManager "+iInfo.name+"cm"+genBrackets(iInfo.arrays.size())+" = null;");
1534      }
1535    }
1536    generateProperties(arch, out);
1537    out.iwriteln();
1538    out.iwriteln("public "+name+"Builder() {");
1539    out.iwriteln("}");
1540    out.iwriteln();
1541    out.iwriteln("public void initialize(SOFA.Component.ComponentManager cm, SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor dd) {");
1542    out.incIndent();
1543    out.iwriteln("super.initialize(cm, dd);");
1544    try {
1545      generateBuilderInitialize(arch, insts, instInfos, out, name ,isPrimitive, isSystem);
1546    } catch (PropException e) {
1547      throw new GenerException(e.getMessage());
1548    }
1549    out.decIndent();
1550    out.iwriteln("}");
1551    out.iwriteln();
1552    out.iwriteln("public void onLeaving(SOFA.SOFAnode.Run.Storage stateStore) throws SOFA.Component.ComponentLifecycleException {");
1553    out.iwriteln(" if (!stopped) {");
1554// out.iwriteln(" // "+Res.res.getString("MSG_AddFinCode"));
1555
if (isPrimitive) {
1556      out.iwriteln(" impl.bStop();");
1557    } else {
1558      out.iwriteln("");
1559    }
1560    out.iwriteln(" } else {");
1561    out.iwriteln(" SOFA.SOFAnode.Run.Deployment.DeplDock dock = cm.getLocalDeplDock();");
1562    out.iwriteln(" try {");
1563    out.iwriteln(" dock.removeComponent(fullInstanceName);");
1564    out.iwriteln(" } catch (SOFA.SOFAnode.Run.Deployment.DeploymentException e) {");
1565    out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_ComponentCantBeRemoved")+"\", e);");
1566    out.iwriteln(" }");
1567    out.iwriteln(" }");
1568    out.iwriteln("}");
1569    out.iwriteln();
1570    out.iwriteln("public void onArrival(SOFA.SOFAnode.Run.Storage stateStore) throws SOFA.Component.ComponentLifecycleException {");
1571    try {
1572      generateBuilderOnArrival(arch, insts, instInfos, out, name ,isPrimitive, isSystem);
1573    } catch (PropException e) {
1574      throw new GenerException(e.getMessage());
1575    }
1576    out.iwriteln("}");
1577    out.iwriteln();
1578    out.iwriteln("public void store(SOFA.SOFAnode.Run.Storage stateStore) throws SOFA.Component.ComponentLifecycleException {");
1579    if (isPrimitive) {
1580      out.iwriteln(" impl.bStore();");
1581    } else {
1582      out.iwriteln("");
1583    }
1584    out.iwriteln("}");
1585    out.iwriteln();
1586    out.iwriteln("public void restore(SOFA.SOFAnode.Run.Storage stateStore) throws SOFA.Component.ComponentLifecycleException {");
1587    if (isPrimitive) {
1588      out.iwriteln(" impl.bRestore();");
1589    } else {
1590      out.iwriteln("");
1591    }
1592    out.iwriteln("}");
1593    out.decIndent();
1594    out.iwriteln("}");
1595  }
1596
1597  /** Generates definition of the CDL properties and inital setter method. It is called from
1598    * generateBuilder.
1599    * @param arch architecture
1600    * @param out output
1601    * @exception IOException
1602    * @exception RemoteException
1603    * @exception GenerException
1604    */

1605  private void generateProperties(ArchitectureDef arch, CGFileWriter out) throws IOException JavaDoc, RemoteException JavaDoc, GenerException {
1606   try {
1607      java.util.Hashtable JavaDoc generatedNames = new java.util.Hashtable JavaDoc ();
1608      Contained[] archProps = arch.contents(((Repository) arch.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Property));
1609      Contained[] frameProps = arch.frame().contents(((Repository) arch.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Property));
1610      for (int i=0; i<frameProps.length; i++) {
1611        PropertyDef prop = (PropertyDef) frameProps[i];
1612        String JavaDoc name = prop.get_identification().name();
1613        String JavaDoc key = GeneratedObject.createKey(prop.type());
1614        GeneratedObject generObj = searchObject(key);
1615        if (generObj == null) {
1616          throw new GenerException(Res.res.getString("MSG_TIRError")+"\n"+key+" "+Res.res.getString("MSG_CantBeGenerated"));
1617        }
1618        String JavaDoc inRef = generObj.genReference(GeneratedObject.INREF);
1619        generatedNames.put(name, inRef);
1620        out.iwriteln("public "+inRef+" _prop_"+name+";");
1621      }
1622      out.iwriteln("");
1623      for (int i=0; i<archProps.length; i++) {
1624        PropertyDef prop = (PropertyDef) archProps[i];
1625        String JavaDoc name = prop.get_identification().name();
1626        if (generatedNames.containsKey(name))
1627          break;
1628        String JavaDoc key = GeneratedObject.createKey(prop.type());
1629        GeneratedObject generObj = searchObject(key);
1630        if (generObj == null) {
1631          throw new GenerException(Res.res.getString("MSG_TIRError")+"\n"+key+" "+Res.res.getString("MSG_CantBeGenerated"));
1632        }
1633        String JavaDoc inRef = generObj.genReference(GeneratedObject.INREF);
1634        generatedNames.put(name, inRef);
1635        out.iwriteln("public "+inRef+" _prop_"+name+";");
1636      }
1637      out.iwriteln("");
1638      out.iwriteln("private void initProperties() throws NumberFormatException {");
1639      out.incIndent();
1640      for (java.util.Enumeration JavaDoc e = generatedNames.keys(); e.hasMoreElements(); ) {
1641        String JavaDoc name = (String JavaDoc) e.nextElement();
1642        out.iwrite((String JavaDoc) generatedNames.get(name));
1643        out.iwriteln(" _prop_"+name+" = "+baseTypeToParseMethod((String JavaDoc)generatedNames.get(name), "dd.getProperty(\""+name+"\")")+";");
1644      }
1645      out.decIndent();
1646      out.iwriteln("}\n");
1647    } catch (TIRExceptLock e) {
1648      throw new GenerException(Res.res.getString("MSG_LockedTIR"));
1649    }
1650  }
1651
1652  private void generateBuilderInitialize(ArchitectureDef arch, Contained[] insts, java.util.ArrayList JavaDoc instInfos, CGFileWriter out, String JavaDoc name, boolean isPrimitive, boolean isSystem) throws RemoteException JavaDoc, IOException JavaDoc, GenerException, PropException {
1653    out.iwriteln("initProperties();");
1654    out.iwriteln("");
1655    if (isPrimitive) {
1656      out.iwriteln("impl = new "+name+"Impl ((SOFA.Component.DCUP.DCUPComponentManagerImpl) cm);");
1657      // out.iwriteln("// "+Res.res.getString("MSG_AddCodeProvReq"));
1658
out.iwriteln("");
1659      generateBuilderInitializeBinds(arch, insts, instInfos, out, name ,isPrimitive, isSystem);
1660      out.iwriteln("");
1661// out.iwriteln("// "+Res.res.getString("MSG_ChangeIfIsUpdatable"));
1662
out.iwriteln("updatable = impl.isUpdatable();");
1663    } else {
1664      out.iwriteln("SOFA.SOFAnode.Run.Deployment.DeplDock dock = cm.getLocalDeplDock();");
1665      // generating: obtaining of dd of subcomponents
1666
for (int i=0; i<insts.length; i++) {
1667        InstInfo iInfo = (InstInfo) instInfos.get(i);
1668        out.iwriteln("SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor "+iInfo.name+"dd = dd.getSubComponentDeploymentDescriptor(\""+iInfo.name+"\");");
1669      }
1670      out.iwriteln("");
1671      
1672      // generating: instantiation of subcomponents
1673
out.iwriteln("String location = null;");
1674      int bracketNum;
1675      for(int i=0; i<instInfos.size(); i++) {
1676        InstInfo iInfo = (InstInfo) instInfos.get(i);
1677        out.iwriteln("SOFA.Connector.Reference "+iInfo.name+"ref"+genBrackets(iInfo.arrays.size())+" = null;");
1678// out.iwriteln("SOFA.Component.DCUP.DCUPComponentManager "+iInfo.name+"cm"+genBrackets(iInfo.arrays.size())+" = null;");
1679
out.iwriteln("location = dd.getSubComponentLocation(\""+iInfo.name+"\");");
1680        out.iwriteln("if (SOFA.Util.SOFAURI.isLocal(location)) {");
1681        out.incIndent();
1682        out.iwriteln("try {");
1683        out.incIndent();
1684        bracketNum = iInfo.arrays.size();
1685        for (int j=0; j<bracketNum; j++) {
1686          out.iwriteln(generateArray(iInfo.name+"ref","_o",j)+" = new SOFA.Connector.Reference["+expressionWithPropertyToString((ExprOperDef)iInfo.arrays.get(j))+"]"+genBrackets(bracketNum-j-1)+";");
1687          out.iwriteln(generateArray(iInfo.name+"cm","_o",j)+" = new SOFA.Component.DCUP.DCUPComponentManager["+expressionWithPropertyToString((ExprOperDef)iInfo.arrays.get(j))+"]"+genBrackets(bracketNum-j-1)+";");
1688          out.iwriteln(generateFor("_o"+Integer.toString(j), expressionWithPropertyToString((ExprOperDef)iInfo.arrays.get(j))));
1689          out.incIndent();
1690        }
1691        out.iwriteln("String instName = "+generateInstName(iInfo.name,"_o",bracketNum)+";");
1692        out.iwriteln( generateArray(iInfo.name+"ref","_o",bracketNum)+" = dock.instantiate("+iInfo.name+"dd, instName);");
1693        out.iwriteln( generateArray(iInfo.name+"cm","_o",bracketNum)+" = getCMConnectorFromRef("+generateArray(iInfo.name+"ref","_o",bracketNum)+");");
1694        out.iwriteln("cm.registerSubcomponent(instName, "+generateArray(iInfo.name+"ref","_o",bracketNum)+");");
1695        for (int j=0; j<bracketNum; j++) {
1696          out.decIndent();
1697          out.iwriteln("}");
1698        }
1699        out.decIndent();
1700        out.iwriteln("} catch (SOFA.SOFAnode.Run.Deployment.DeploymentException e) {");
1701        out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantCreateSubcomponentCM")+"\", e);");
1702        out.iwriteln("} catch (SOFA.Component.InstantiationException e) {");
1703        out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantObtainConnectorSubcomponentCM")+"\", e);");
1704        out.iwriteln("} catch (SOFA.Component.NamingException e) {");
1705        out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantRegisterSubcomponent")+"\", e);");
1706        out.iwriteln("}");
1707        out.decIndent();
1708        out.iwriteln("} else {");
1709        out.incIndent();
1710        out.iwriteln("try {");
1711        out.incIndent();
1712        out.iwriteln("SOFA.Connector.Reference subDDockRef = SOFA.SOFAnode.Run.Deployment.DeplDockImpl.bytesToSofaReference(SOFA.Util.SOFAURI.getReferenceToDeplDockFromSOFAURI(location));");
1713        out.iwriteln("SOFA.SOFAnode.Run.Deployment.DeplDock subDDock = (SOFA.SOFAnode.Run.Deployment.DeplDock) SOFA.Connector.Boot.DeplDockConnector.createClt(subDDockRef);");
1714        bracketNum = iInfo.arrays.size();
1715        for (int j=0; j<bracketNum; j++) {
1716          out.iwriteln(generateArray(iInfo.name+"ref","_o",j)+" = new SOFA.Connector.Reference["+expressionWithPropertyToString((ExprOperDef)iInfo.arrays.get(j))+"]"+genBrackets(bracketNum-j-1)+";");
1717          out.iwriteln(generateArray(iInfo.name+"cm","_o",j)+" = new SOFA.Component.DCUP.DCUPComponentManager["+expressionWithPropertyToString((ExprOperDef)iInfo.arrays.get(j))+"]"+genBrackets(bracketNum-j-1)+";");
1718          out.iwriteln(generateFor("_o"+Integer.toString(j), expressionWithPropertyToString((ExprOperDef)iInfo.arrays.get(j))));
1719          out.incIndent();
1720        }
1721        out.iwriteln("String instName = "+generateInstName(iInfo.name,"_o",bracketNum)+";");
1722        out.iwriteln( generateArray(iInfo.name+"ref","_o",bracketNum)+" = subDDock.instantiate("+iInfo.name+"dd, instName);");
1723        out.iwriteln( generateArray(iInfo.name+"cm","_o",bracketNum)+" = getCMConnectorFromRef("+generateArray(iInfo.name+"ref","_o",bracketNum)+");");
1724        out.iwriteln("cm.registerSubcomponent(instName, "+generateArray(iInfo.name+"ref","_o",bracketNum)+");");
1725        for (int j=0; j<bracketNum; j++) {
1726          out.decIndent();
1727          out.iwriteln("}");
1728        }
1729        out.decIndent();
1730        out.iwriteln("} catch (SOFA.Connector.ConnectorException e) {");
1731        out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantCreateSubcomponentCM")+"\", e);");
1732        out.iwriteln("} catch (SOFA.Util.SOFAURI.BadSOFAURIException e) {");
1733        out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantCreateSubcomponentCM")+"\", e);");
1734        out.iwriteln("} catch (SOFA.SOFAnode.Run.Deployment.DeploymentException e) {");
1735        out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantCreateSubcomponentCM")+"\", e);");
1736        out.iwriteln("} catch (SOFA.Component.InstantiationException e) {");
1737        out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantObtainConnectorSubcomponentCM")+"\", e);");
1738        out.iwriteln("} catch (SOFA.Component.NamingException e) {");
1739        out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantRegisterSubcomponent")+"\", e);");
1740        out.iwriteln("}");
1741        out.decIndent();
1742        out.iwriteln("}");
1743        out.iwriteln("");
1744      }
1745      out.iwriteln("");
1746      // out.iwriteln("// "+Res.res.getString("MSG_AddCodeForBinds"));
1747
out.iwriteln("");
1748      generateBuilderInitializeBinds(arch, insts, instInfos, out, name ,isPrimitive, isSystem);
1749      out.iwriteln("");
1750
1751      out.iwriteln("try {");
1752      out.incIndent();
1753      for(int i=0; i<instInfos.size(); i++) {
1754        InstInfo iInfo = (InstInfo) instInfos.get(i);
1755        out.iwriteln(iInfo.name+"cm.connectSubsumable();");
1756      }
1757      out.decIndent();
1758      out.iwriteln("} catch (SOFA.Component.NamingException e) {");
1759      out.incIndent();
1760      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantSubsumeSubcomponents")+"\", e);");
1761      out.decIndent();
1762      out.iwriteln("} catch (SOFA.Component.InstantiationException e) {");
1763      out.incIndent();
1764      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantSubsumeSubcomponents")+"\", e);");
1765      out.decIndent();
1766      out.iwriteln("}");
1767      out.iwriteln("");
1768      
1769// out.iwriteln("// "+Res.res.getString("MSG_ChangeIfIsUpdatable"));
1770
out.iwriteln("updatable = false;");
1771    }
1772  }
1773
1774  /** Generates onArrival method of the builder.
1775    */

1776  private void generateBuilderOnArrival(ArchitectureDef arch, Contained[] insts, java.util.ArrayList JavaDoc instInfos, CGFileWriter out, String JavaDoc name, boolean isPrimitive, boolean isSystem) throws RemoteException JavaDoc, IOException JavaDoc, GenerException, PropException {
1777    if (isPrimitive) {
1778      out.iwriteln(" impl.bStart();");
1779    } else {
1780      int bracketNum;
1781      out.incIndent();
1782      for(int i=0; i<instInfos.size(); i++) {
1783        InstInfo iInfo = (InstInfo) instInfos.get(i);
1784        bracketNum = iInfo.arrays.size();
1785        if (bracketNum == 0) { // inst is not array
1786
out.iwriteln(iInfo.name+"cm.createComponent(stateStore);");
1787        } else { // inst is array
1788
for (int j=0; j<bracketNum; j++) {
1789            out.iwriteln(generateFor("_i"+Integer.toString(j), expressionWithPropertyToString((ExprOperDef)iInfo.arrays.get(j))));
1790            out.incIndent();
1791          }
1792          out.iwriteln(generateArray(iInfo.name+"cm","_i",bracketNum)+".createComponent(stateStore);");
1793          for (int j=0; j<bracketNum; j++) {
1794            out.decIndent();
1795            out.iwriteln("}");
1796          }
1797        }
1798      }
1799      out.decIndent();
1800    }
1801  }
1802
1803  /** Generates code for bindings in the builder initialize method.
1804    */

1805  private void generateBuilderInitializeBinds(ArchitectureDef arch, Contained[] insts, java.util.ArrayList JavaDoc instInfos, CGFileWriter out, String JavaDoc name, boolean isPrimitive, boolean isSystem) throws RemoteException JavaDoc, IOException JavaDoc, GenerException, PropException {
1806  
1807    Contained[] binds;
1808    java.util.ArrayList JavaDoc delegs = new java.util.ArrayList JavaDoc();
1809    java.util.ArrayList JavaDoc subsums = new java.util.ArrayList JavaDoc();
1810    java.util.ArrayList JavaDoc bindspr = new java.util.ArrayList JavaDoc();
1811    try {
1812      binds = arch.contents(((Repository) arch.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Bind));
1813    } catch (TIRExceptLock e) {
1814      throw new GenerException(Res.res.getString("MSG_LockedTIR"));
1815    }
1816
1817    // bind sub1:req to sub2:prov
1818
if (binds != null && binds.length != 0) {
1819      out.iwriteln("try {");
1820      out.incIndent();
1821      out.iwriteln("SOFA.Connector.Reference pref;");
1822      for (int i=0; i<binds.length; i++) {
1823        BindDef bind = (BindDef) binds[i];
1824        switch (bind.mode().value()) {
1825          case BindMode.DELEGATE:
1826            delegs.add(bind);
1827            break;
1828          case BindMode.SUBSUME:
1829            subsums.add(bind);
1830            break;
1831          case BindMode.BIND:
1832            if (bind.lhsop().get_bo_kind().value() == BindOperKind.bok_provreq) {
1833              bindspr.add(bind);
1834            } else {
1835              BindOperSub lhs = (BindOperSub) bind.lhsop();
1836              BindOperSub rhs = (BindOperSub) bind.rhsop();
1837              BindType[] lelems = lhs.elements();
1838              BindType[] lsubs = lhs.subs();
1839              BindType[] relems = rhs.elements();
1840              BindType[] rsubs = rhs.subs();
1841              String JavaDoc lcompname;
1842              String JavaDoc rcompname;
1843              boolean containsArray = false;
1844              if (lsubs[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1845                lcompname = ((BindTypeNormal) lsubs[0]).name();
1846              } else {
1847                lcompname = ((BindTypeArray) lsubs[0]).name();
1848                containsArray = true;
1849              }
1850              if (rsubs[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1851                rcompname = ((BindTypeNormal) rsubs[0]).name();
1852              } else {
1853                rcompname = ((BindTypeArray) rsubs[0]).name();
1854                containsArray = true;
1855              }
1856              String JavaDoc lelemname;
1857              String JavaDoc relemname;
1858              if (lelems[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1859                lelemname = ((BindTypeNormal) lelems[0]).name();
1860              } else {
1861                lelemname = ((BindTypeArray) lelems[0]).name();
1862                containsArray = true;
1863              }
1864              if (relems[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1865                relemname = ((BindTypeNormal) relems[0]).name();
1866              } else {
1867                relemname = ((BindTypeArray) relems[0]).name();
1868                containsArray = true;
1869              }
1870              if (containsArray) {
1871                out.iwriteln(Res.res.getString("MSG_ProvideArray"));
1872              }
1873              out.iwriteln("pref = "+rcompname+"cm.getProvisionReference(\""+relemname+"\");");
1874              out.iwriteln(lcompname+"cm.setRequirement(\""+lelemname+"\", pref);");
1875            }
1876            break;
1877        }
1878      }
1879      out.decIndent();
1880      out.iwriteln("} catch (SOFA.Component.NamingException e) {");
1881      out.incIndent();
1882      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantBindSubcomponents")+"\", e);");
1883      out.decIndent();
1884      out.iwriteln("}");
1885    }
1886
1887    // delegate prov to sub:prov
1888
if (delegs.size() != 0) {
1889      out.iwriteln("try {");
1890      out.incIndent();
1891      out.iwriteln("SOFA.Connector.Reference pref;");
1892      for (int i=0; i<delegs.size(); i++) {
1893        BindDef bind = (BindDef) delegs.get(i);
1894        BindOperProvReq lhs = (BindOperProvReq) bind.lhsop();
1895        BindOperSub rhs = (BindOperSub) bind.rhsop();
1896        BindType[] lelems = lhs.elements();
1897        BindType[] relems = rhs.elements();
1898        BindType[] rsubs = rhs.subs();
1899        String JavaDoc rcompname;
1900        boolean containsArray = false;
1901        if (rsubs[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1902          rcompname = ((BindTypeNormal) rsubs[0]).name();
1903        } else {
1904          rcompname = ((BindTypeArray) rsubs[0]).name();
1905          containsArray = true;
1906        }
1907        String JavaDoc lelemname;
1908        String JavaDoc relemname;
1909        if (lelems[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1910          lelemname = ((BindTypeNormal) lelems[0]).name();
1911        } else {
1912          lelemname = ((BindTypeArray) lelems[0]).name();
1913          containsArray = true;
1914        }
1915        if (relems[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1916          relemname = ((BindTypeNormal) relems[0]).name();
1917        } else {
1918          relemname = ((BindTypeArray) relems[0]).name();
1919          containsArray = true;
1920        }
1921        if (containsArray) {
1922          out.iwriteln(Res.res.getString("MSG_ProvideArray"));
1923        }
1924        out.iwriteln("pref = "+rcompname+"cm.getProvisionReference(\""+relemname+"\");");
1925        out.iwriteln("((SOFA.Component.DCUP.DCUPComponentManagerImpl) cm).delegateProvision(\""+lelemname+"\", pref);");
1926      }
1927      out.decIndent();
1928      out.iwriteln("} catch (SOFA.Component.NamingException e) {");
1929      out.incIndent();
1930      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantDelegateSubcomponents")+"\", e);");
1931      out.decIndent();
1932      out.iwriteln("} catch (SOFA.Component.InstantiationException e) {");
1933      out.incIndent();
1934      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantDelegateSubcomponents")+"\", e);");
1935      out.decIndent();
1936      out.iwriteln("}");
1937    }
1938
1939    // subsume sub:req to req
1940
if (subsums.size() != 0) {
1941/* // instances on which the "connectSubsumable" must be called
1942      java.util.Hashtable subsInsts = new java.util.Hashtable(); */

1943      out.iwriteln("try {");
1944      out.incIndent();
1945      out.iwriteln("SOFA.Connector.Reference pref;");
1946      for (int i=0; i<subsums.size(); i++) {
1947        BindDef bind = (BindDef) subsums.get(i);
1948        BindOperSub lhs = (BindOperSub) bind.lhsop();
1949        BindOperProvReq rhs = (BindOperProvReq) bind.rhsop();
1950        BindType[] lelems = lhs.elements();
1951        BindType[] lsubs = lhs.subs();
1952        BindType[] relems = rhs.elements();
1953        String JavaDoc lcompname;
1954        boolean containsArray = false;
1955        if (lsubs[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1956          lcompname = ((BindTypeNormal) lsubs[0]).name();
1957        } else {
1958          lcompname = ((BindTypeArray) lsubs[0]).name();
1959          containsArray = true;
1960        }
1961        String JavaDoc lelemname;
1962        String JavaDoc relemname;
1963        if (lelems[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1964          lelemname = ((BindTypeNormal) lelems[0]).name();
1965        } else {
1966          lelemname = ((BindTypeArray) lelems[0]).name();
1967          containsArray = true;
1968        }
1969        if (relems[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
1970          relemname = ((BindTypeNormal) relems[0]).name();
1971        } else {
1972          relemname = ((BindTypeArray) relems[0]).name();
1973          containsArray = true;
1974        }
1975        if (containsArray) {
1976          out.iwriteln(Res.res.getString("MSG_ProvideArray"));
1977        }
1978        out.iwriteln("pref = ((SOFA.Component.DCUP.DCUPComponentManagerImpl) cm).createSubsumableRequirement(\""+relemname+"\");");
1979        out.iwriteln(lcompname+"cm.setRequirement(\""+lelemname+"\", pref);");
1980/* subsInsts.put(lcompname, ""); */
1981      }
1982      out.iwriteln("");
1983      /* moved to every component
1984
1985      for (java.util.Enumeration e = subsInsts.keys() ; e.hasMoreElements() ;) {
1986        String instName = (String) e.nextElement();
1987        out.iwriteln(instName+"cm.connectSubsumable();");
1988      }
1989      */

1990      out.decIndent();
1991      out.iwriteln("} catch (SOFA.Component.NamingException e) {");
1992      out.incIndent();
1993      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantSubsumeSubcomponents")+"\", e);");
1994      out.decIndent();
1995      out.iwriteln("} catch (SOFA.Component.InstantiationException e) {");
1996      out.incIndent();
1997      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantSubsumeSubcomponents")+"\", e);");
1998      out.decIndent();
1999      out.iwriteln("}");
2000    }
2001
2002    // bind prov to req
2003
if (bindspr.size() != 0) {
2004      out.iwriteln("try {");
2005      out.incIndent();
2006      out.iwriteln("SOFA.Connector.Reference pref;");
2007      for (int i=0; i<bindspr.size(); i++) {
2008        BindDef bind = (BindDef) bindspr.get(i);
2009        boolean containsArray = false;
2010        BindOperProvReq lhs = (BindOperProvReq) bind.lhsop();
2011        BindOperProvReq rhs = (BindOperProvReq) bind.rhsop();
2012        BindType[] lelems = lhs.elements();
2013        BindType[] relems = rhs.elements();
2014        String JavaDoc lelemname;
2015        String JavaDoc relemname;
2016        if (lelems[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
2017          lelemname = ((BindTypeNormal) lelems[0]).name();
2018        } else {
2019          lelemname = ((BindTypeArray) lelems[0]).name();
2020          containsArray = true;
2021        }
2022        if (relems[0].get_bt_kind().value() == BindTypeKind.btk_normal) {
2023          relemname = ((BindTypeNormal) relems[0]).name();
2024        } else {
2025          relemname = ((BindTypeArray) relems[0]).name();
2026          containsArray = true;
2027        }
2028        if (containsArray) {
2029          out.iwriteln(Res.res.getString("MSG_ProvideArray"));
2030        }
2031        out.iwriteln("pref = ((SOFA.Component.DCUP.DCUPComponentManagerImpl) cm).createSubsumableRequirement(\""+relemname+"\");");
2032        out.iwriteln("((SOFA.Component.DCUP.DCUPComponentManagerImpl) cm).delegateProvision(\""+lelemname+"\", pref);");
2033      }
2034      out.decIndent();
2035      out.iwriteln("} catch (SOFA.Component.NamingException e) {");
2036      out.incIndent();
2037      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantDirectBindSubcomponents")+"\", e);");
2038      out.decIndent();
2039      out.iwriteln("} catch (SOFA.Component.InstantiationException e) {");
2040      out.incIndent();
2041      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantDirectbindSubcomponents")+"\", e);");
2042      out.decIndent();
2043      out.iwriteln("}");
2044    }
2045    
2046    // provisions
2047
Contained[] provs = null;
2048    try {
2049      provs = arch.frame().contents(((Repository) arch.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Provides));
2050    } catch (TIRExceptLock e) {
2051      throw new GenerException(Res.res.getString("MSG_LockedTIR"));
2052    }
2053    for(int i=0; i<provs.length; i++) {
2054      String JavaDoc prName = provs[i].get_identification().name();
2055      out.iwriteln("// "+Res.res.getString("MSG_BeginOfProvision")+" "+prName);
2056      if (isPrimitive) {
2057        out.iwriteln("try {");
2058        out.incIndent();
2059        out.iwriteln("((SOFA.Component.DCUP.DCUPComponentManagerImpl) cm).reSetProvisionImpl(\""+prName+"\", impl);");
2060        out.decIndent();
2061        out.iwriteln("} catch (SOFA.Component.NamingException e) {");
2062        out.incIndent();
2063        out.iwriteln("try {");
2064        out.incIndent();
2065        out.iwriteln("((SOFA.Component.DCUP.DCUPComponentManagerImpl) cm).setProvisionImpl(\""+prName+"\", impl);");
2066        out.decIndent();
2067        out.iwriteln("} catch (SOFA.Component.NamingException e1) {");
2068        out.incIndent();
2069        out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantRegisterProvision")+"\", e1);");
2070        out.decIndent();
2071        out.iwriteln("} catch (SOFA.Component.InstantiationException e1) {");
2072        out.incIndent();
2073        out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantCreateProvision")+"\", e1);");
2074        out.decIndent();
2075        out.iwriteln("}");
2076        out.decIndent();
2077        out.iwriteln("}");
2078      } else { // it is not primitive component
2079
out.iwriteln("try {");
2080        out.incIndent();
2081        out.iwriteln("((SOFA.Component.DCUP.DCUPComponentManagerImpl) cm).createProvision(\""+prName+"\");");
2082        out.decIndent();
2083        out.iwriteln("} catch (SOFA.Component.NamingException e) {");
2084        out.incIndent();
2085        out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantRegisterProvision")+"\", e);");
2086        out.decIndent();
2087        out.iwriteln("} catch (SOFA.Component.InstantiationException e) {");
2088        out.incIndent();
2089        out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantCreateProvision")+"\", e);");
2090        out.decIndent();
2091        out.iwriteln("}");
2092      }
2093      out.iwriteln("// "+Res.res.getString("MSG_EndOfProvision")+" "+prName);
2094    }
2095
2096    if ((delegs.size() + bindspr.size()) != 0) {
2097      out.iwriteln("try {");
2098      out.incIndent();
2099      out.iwriteln("((SOFA.Component.DCUP.DCUPComponentManagerImpl) cm).connectDelegated();");
2100      out.decIndent();
2101      out.iwriteln("} catch (SOFA.Component.NamingException e) {");
2102      out.incIndent();
2103      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantDelegateSubcomponents")+"\", e);");
2104      out.decIndent();
2105      out.iwriteln("} catch (SOFA.Component.InstantiationException e) {");
2106      out.incIndent();
2107      out.iwriteln("throw new SOFA.Component.ComponentLifecycleException(\""+Res.res.getString("MSG_CantDelegateSubcomponents")+"\", e);");
2108      out.decIndent();
2109      out.iwriteln("}");
2110    }
2111    
2112
2113  }
2114
2115  private void generateBaseImpl(ArchitectureDef arch, CGFileWriter out, String JavaDoc provider, String JavaDoc name, String JavaDoc pkg) throws IOException JavaDoc, RemoteException JavaDoc, GenerException {
2116    Contained[] insts = null;
2117    boolean isPrimitive = false;
2118    FrameDef frame = arch.frame();
2119    Contained[] provs = null;
2120    Contained[] reqs = null;
2121    String JavaDoc[] reqTypes = null;
2122    String JavaDoc[] reqNames = null;
2123    boolean isSystem = arch.is_system();
2124    try {
2125      insts = arch.contents(((Repository) arch.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Inst));
2126      if (insts.length == 0)
2127        isPrimitive = true;
2128      provs = frame.contents(((Repository) arch.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Provides));
2129      reqs = frame.contents(((Repository) arch.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Requires));
2130
2131    
2132  
2133      out.iwriteln("package "+pkg+";");
2134      out.iwriteln();
2135      printHeadComment(Res.res.getString("MSG_BaseComponentImplementation")+" "+Res.res.getString("MSG_For")+" "+contained2string(arch),out);
2136      out.iwrite("abstract public class _Base"+name+"Impl ");
2137      if (provs.length != 0) {
2138        out.iwrite("implements ");
2139        for (int i=0; i<provs.length; i++) {
2140          InterfaceDef iface = SOFA.SOFAnode.Made.TIR.Access.TIRAccessMethods.getIfaceOfProvides((ProvideDef) provs[i]);
2141          GeneratedObject go = searchObject(GeneratedObject.createKey(iface));
2142          out.iwrite(go.genReference(GeneratedObject.INREF));
2143          if (i<provs.length-1)
2144            out.iwrite(", ");
2145        }
2146      }
2147      out.iwriteln("{");
2148      out.incIndent();
2149      out.iwriteln("private SOFA.Component.DCUP.DCUPComponentManagerImpl cm;");
2150      if (reqs.length!=0) {
2151        reqTypes = new String JavaDoc [reqs.length];
2152        reqNames = new String JavaDoc [reqs.length];
2153        for (int i=0; i<reqs.length; i++) {
2154          InterfaceDef iface = SOFA.SOFAnode.Made.TIR.Access.TIRAccessMethods.getIfaceOfRequires((RequireDef) reqs[i]);
2155          GeneratedObject go = searchObject(GeneratedObject.createKey(iface));
2156          reqTypes[i] = go.genReference(GeneratedObject.INREF);
2157          reqNames[i] = ((RequireDef)reqs[i]).get_identification().name();
2158          out.iwriteln("protected "+reqTypes[i]+" "+reqNames[i]+"Requirement;");
2159        }
2160      }
2161      out.iwriteln();
2162      out.iwriteln("public _Base"+name+"Impl(SOFA.Component.DCUP.DCUPComponentManagerImpl _cm) {");
2163      out.iwriteln(" cm = _cm;");
2164      out.iwriteln("}");
2165      out.iwriteln();
2166      out.iwriteln("public boolean isUpdatable() {");
2167      out.iwriteln(" return false;");
2168      out.iwriteln("}");
2169      out.iwriteln();
2170      if (reqs.length != 0) {
2171        out.iwriteln("public void setRequirements() throws SOFA.Component.NamingException {");
2172        out.incIndent();
2173        for (int i=0; i<reqs.length; i++) {
2174          out.iwriteln(reqNames[i]+"Requirement = ("+reqTypes[i]+") cm.getRequirement(\""+reqNames[i]+"\");");
2175        }
2176        out.decIndent();
2177        out.iwriteln("}");
2178      }
2179      out.iwriteln();
2180      out.iwriteln("final public void bStart() throws SOFA.Component.ComponentLifecycleException {");
2181      if (reqs.length != 0) {
2182        out.iwriteln(" try {");
2183        out.iwriteln(" setRequirements();");
2184        out.iwriteln(" } catch (SOFA.Component.NamingException e) {");
2185        out.iwriteln(" throw new SOFA.Component.ComponentLifecycleException(e.getMessage(), e);");
2186        out.iwriteln(" }");
2187      }
2188      out.iwriteln(" start();");
2189      out.iwriteln("}");
2190      out.iwriteln();
2191      out.iwriteln("final public void bStop() throws SOFA.Component.ComponentLifecycleException {");
2192      out.iwriteln(" stop();");
2193      out.iwriteln("}");
2194      out.iwriteln();
2195      out.iwriteln("final public void bStore() throws SOFA.Component.ComponentLifecycleException {");
2196      out.iwriteln(" store();");
2197      out.iwriteln("}");
2198      out.iwriteln();
2199      out.iwriteln("final public void bRestore() throws SOFA.Component.ComponentLifecycleException {");
2200      out.iwriteln(" restore();");
2201      out.iwriteln("}");
2202      out.iwriteln();
2203      out.iwriteln("abstract public void start() throws SOFA.Component.ComponentLifecycleException;");
2204      out.iwriteln("abstract public void stop() throws SOFA.Component.ComponentLifecycleException;");
2205      out.iwriteln("abstract public void store() throws SOFA.Component.ComponentLifecycleException;");
2206      out.iwriteln("abstract public void restore() throws SOFA.Component.ComponentLifecycleException;");
2207      out.iwriteln();
2208      if (provs.length != 0) {
2209        out.iwriteln("final public java.lang.String getFcItfName() { return \"\"; }");
2210        out.iwriteln();
2211        out.iwriteln("final public org.objectweb.fractal.api.Type getFcItfType() { return new SOFA.Util.FcTypeImpl(); }");
2212        out.iwriteln();
2213        out.iwriteln("final public boolean isFcInternalItf() { return false; }");
2214        out.iwriteln();
2215        out.iwriteln("final public org.objectweb.fractal.api.Component getFcItfOwner() { return cm; }");
2216        out.iwriteln();
2217      }
2218      out.decIndent();
2219      out.iwriteln("}");
2220    } catch (TIRExceptLock e) {
2221      throw new GenerException(Res.res.getString("MSG_LockedTIR"));
2222    }
2223  }
2224
2225  private void generateRealImplSkel(ArchitectureDef arch, CGFileWriter out, String JavaDoc provider, String JavaDoc name, String JavaDoc pkg) throws IOException JavaDoc, RemoteException JavaDoc, GenerException {
2226    out.iwriteln("package "+pkg+";");
2227    out.iwriteln();
2228    printHeadComment(Res.res.getString("MSG_Implementation")+" "+Res.res.getString("MSG_For")+" "+contained2string(arch),out);
2229    out.iwriteln("public class "+name+"Impl extends _Base"+name+"Impl {");
2230    out.incIndent();
2231    out.iwriteln("public "+name+"Impl(SOFA.Component.DCUP.DCUPComponentManagerImpl cm) {");
2232    out.iwriteln(" super(cm);");
2233    out.iwriteln("}");
2234    out.iwriteln();
2235    out.iwriteln("public void start() throws SOFA.Component.ComponentLifecycleException {");
2236    out.iwriteln("");
2237    out.iwriteln("}");
2238    out.iwriteln();
2239    out.iwriteln("public void stop() throws SOFA.Component.ComponentLifecycleException {");
2240    out.iwriteln("");
2241    out.iwriteln("}");
2242    out.iwriteln();
2243    out.iwriteln("public void store() throws SOFA.Component.ComponentLifecycleException {");
2244    out.iwriteln("");
2245    out.iwriteln("}");
2246    out.iwriteln();
2247    out.iwriteln("public void restore() throws SOFA.Component.ComponentLifecycleException {");
2248    out.iwriteln("");
2249    out.iwriteln("}");
2250    out.iwriteln();
2251    out.decIndent();
2252    out.iwriteln("}");
2253  }
2254
2255  static class InstInfo {
2256    String JavaDoc name;
2257    FrameDef frame;
2258    java.util.ArrayList JavaDoc arrays;
2259    public InstInfo(String JavaDoc n, FrameDef f, java.util.ArrayList JavaDoc a) {
2260      name = n;
2261      frame = f;
2262      arrays = a;
2263    }
2264
2265    public static InstInfo getInstInfo(Contained inst) throws RemoteException JavaDoc {
2266      int num = 0;
2267      java.util.ArrayList JavaDoc arrays = new java.util.ArrayList JavaDoc();
2268      CDLType obj = ((InstDef) inst).type();
2269      int defKind = obj.get_def_kind().value();
2270      while (defKind == DefinitionKind.dk_Typedef || defKind == DefinitionKind.dk_Array) {
2271        if (defKind == DefinitionKind.dk_Typedef)
2272          obj = ((TypedefDef) obj).original_type();
2273        else {
2274          arrays.add(((ArrayDef) obj).length());
2275          obj = ((ArrayDef) obj).element_type();
2276        }
2277        defKind = obj.get_def_kind().value();
2278      }
2279      FrameDef realType = (FrameDef) obj;
2280      return new InstInfo(inst.get_identification().name(), realType, arrays);
2281    }
2282
2283    public static InstInfo findInstInfo(java.util.ArrayList JavaDoc infos, String JavaDoc name) {
2284      for (int i=0; i<infos.size(); i++) {
2285        InstInfo f = (InstInfo) infos.get(i);
2286        if ( f.name.compareTo(name)==0)
2287          return f;
2288      }
2289      return null;
2290    }
2291  }
2292  
2293  private static String JavaDoc baseTypeToParseMethod(String JavaDoc type, String JavaDoc from) throws GenerException {
2294    if (type.compareTo("int")==0)
2295      return "Integer.parseInt("+from+")";
2296    if (type.compareTo("long")==0)
2297      return "Long.parseLong("+from+")";
2298    if (type.compareTo("byte")==0)
2299      return "Byte.parseByte("+from+")";
2300    if (type.compareTo("double")==0)
2301      return "Double.parseDouble("+from+")";
2302    if (type.compareTo("boolean")==0)
2303      return "Boolean.valueOf("+from+")";
2304    if (type.compareTo("short")==0)
2305      return "Short.parseShort("+from+")";
2306    if (type.compareTo("String")==0)
2307      return from;
2308    throw new GenerException(Res.res.getString("MSG_UnsupportedPropertyType")+type);
2309  }
2310
2311  /** Generate code that creates instantion name */
2312  private static String JavaDoc generateInstName(String JavaDoc name, String JavaDoc indexPrefix, int number) {
2313    StringBuffer JavaDoc sb = new StringBuffer JavaDoc("\""+name+"\"");
2314    for (int i=0; i<number; i++) {
2315      sb.append("+\"_\"+");
2316      sb.append("Integer.toString("+indexPrefix+Integer.toString(i)+")");
2317    }
2318    return sb.toString();
2319  }
2320
2321  private void generateComponentInfoFile(ArchitectureDef obj, SOFA.SOFAnode.Made.TIR.AbsoluteName absN, String JavaDoc name, String JavaDoc builderName) throws RemoteException JavaDoc, GenerException, IOException JavaDoc {
2322    DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
2323    Document JavaDoc document = null;
2324    try {
2325      DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
2326      document = builder.newDocument();
2327      Element JavaDoc root = null;
2328      if (obj.is_system())
2329        root = (Element JavaDoc) document.createElement("sofa_system");
2330      else
2331        root = (Element JavaDoc) document.createElement("sofa_component");
2332      document.appendChild(root);
2333      Element JavaDoc el;
2334      Text JavaDoc tx;
2335      
2336      el = document.createElement("architecture_ref");
2337      tx = document.createTextNode(contained2string(obj));
2338      el.appendChild(tx);
2339      root.appendChild(el);
2340
2341      el = document.createElement("frame_ref");
2342      tx = document.createTextNode(contained2string(obj.frame()));
2343      el.appendChild(tx);
2344      root.appendChild(el);
2345
2346      el = document.createElement("version");
2347      tx = document.createTextNode("!set.version.here!");
2348      el.appendChild(tx);
2349      root.appendChild(el);
2350      
2351      Element JavaDoc entit = (Element JavaDoc) document.createElement("cdl_entities");
2352      for (int i=0; i<genFiles.size(); i++) {
2353        GenFile go = genFiles.getObject(i);
2354        el = document.createElement("entity");
2355        el.setAttribute("cdlname", go.cdlName);
2356        el.setAttribute("javaname", go.genName);
2357        entit.appendChild(el);
2358      }
2359      root.appendChild(entit);
2360      
2361      el = document.createElement("implementation");
2362      el.setAttribute("type", "builder");
2363      tx = document.createTextNode(builderName);
2364      el.appendChild(tx);
2365      root.appendChild(el);
2366
2367      try {
2368        Contained[] cont = obj.contents(((Repository)obj.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Property));
2369        if (cont!=null && cont.length!=0) {
2370          for (int i=0; i<cont.length; i++) {
2371            el = document.createElement("property");
2372            el.setAttribute("name",cont[i].get_identification().name());
2373            el.setAttribute("value","!set.property.value.here!");
2374            root.appendChild(el);
2375          }
2376        }
2377        
2378        cont = obj.contents(((Repository)obj.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Inst));
2379        boolean isPrimitive = true;
2380        if (cont!=null && cont.length!=0) {
2381          isPrimitive = false;
2382          for (int i=0; i<cont.length; i++) {
2383            el = document.createElement("component_ref");
2384            el.setAttribute("inst",cont[i].get_identification().name());
2385            el.setAttribute("arch","!set.architecture.name.here!");
2386            el.setAttribute("version","!set.implementation.version.here!");
2387            root.appendChild(el);
2388          }
2389        }
2390
2391        cont = obj.frame().contents(((Repository)obj.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Provides));
2392        if (cont!=null && cont.length!=0) {
2393          for (int i=0; i<cont.length;i++) {
2394            InterfaceDef iface = SOFA.SOFAnode.Made.TIR.Access.TIRAccessMethods.getIfaceOfProvides((ProvideDef) cont[i]);
2395            String JavaDoc connName = cont[i].get_identification().name();
2396            if (SOFA.SOFAnode.Made.TIR.Access.TIRAccessMethods.containProvArrays((ProvideDef) cont[i]))
2397              connName = connName+"*";
2398            el = document.createElement("connector");
2399            el.setAttribute("name", connName);
2400         /* el.setAttribute("unit", "Server");
2401            el.setAttribute("impl", "SGenerator:CSProcCallImpl"); */

2402            el.setAttribute("requires", contained2string(iface));
2403            root.appendChild(el);
2404         /* Element conEl = document.createElement("element");
2405            conEl.setAttribute("name", "sRole");
2406            conEl.setAttribute("impl", "EEM:SRoleImpl");
2407            el.appendChild(conEl);
2408            conEl = document.createElement("element");
2409            conEl.setAttribute("name", "skeleton");
2410            conEl.setAttribute("impl", "EEM:RMISkeleton");
2411            el.appendChild(conEl); */

2412
2413            if (!isPrimitive) {
2414              el = document.createElement("connector");
2415              el.setAttribute("name", "_delegate_"+connName);
2416           /* el.setAttribute("unit", "Client");
2417              el.setAttribute("impl", "SGenerator:CSProcCallImpl"); */

2418              el.setAttribute("provides", contained2string(iface));
2419              root.appendChild(el);
2420           /* conEl = document.createElement("element");
2421              conEl.setAttribute("name", "cRole");
2422              conEl.setAttribute("impl", "EEM:CRoleImpl");
2423              el.appendChild(conEl);
2424              conEl = document.createElement("element");
2425              conEl.setAttribute("name", "stub");
2426              conEl.setAttribute("impl", "EEM:RMIStub");
2427              el.appendChild(conEl); */

2428            }
2429          }
2430        }
2431
2432        cont = obj.frame().contents(((Repository)obj.get_containing_repository()).get_spec_def_kind(DefinitionKind.dk_Requires));
2433        if (cont!=null && cont.length!=0) {
2434          for (int i=0; i<cont.length;i++) {
2435            InterfaceDef iface = SOFA.SOFAnode.Made.TIR.Access.TIRAccessMethods.getIfaceOfRequires((RequireDef) cont[i]);
2436            String JavaDoc connName = cont[i].get_identification().name();
2437            if (SOFA.SOFAnode.Made.TIR.Access.TIRAccessMethods.containReqArrays((RequireDef) cont[i]))
2438              connName = connName+"*";
2439            el = document.createElement("connector");
2440            el.setAttribute("name", connName);
2441         /* el.setAttribute("unit", "Client");
2442            el.setAttribute("impl", "SGenerator:CSProcCallImpl");*/

2443            el.setAttribute("provides", contained2string(iface));
2444            root.appendChild(el);
2445         /* Element conEl = document.createElement("element");
2446            conEl.setAttribute("name", "cRole");
2447            conEl.setAttribute("impl", "EEM:CRoleImpl");
2448            el.appendChild(conEl);
2449            conEl = document.createElement("element");
2450            conEl.setAttribute("name", "stub");
2451            conEl.setAttribute("impl", "EEM:RMIStub");
2452            el.appendChild(conEl); */

2453
2454            if (!isPrimitive) {
2455              el = document.createElement("connector");
2456              el.setAttribute("name", "_subsume_"+connName);
2457           /* el.setAttribute("unit", "Server");
2458              el.setAttribute("impl", "SGenerator:CSProcCallImpl");*/

2459              el.setAttribute("requires", contained2string(iface));
2460              root.appendChild(el);
2461           /* conEl = document.createElement("element");
2462              conEl.setAttribute("name", "sRole");
2463              conEl.setAttribute("impl", "EEM:SRoleImpl");
2464              el.appendChild(conEl);
2465              conEl = document.createElement("element");
2466              conEl.setAttribute("name", "skeleton");
2467              conEl.setAttribute("impl", "EEM:RMISkeleton");
2468              el.appendChild(conEl); */

2469            }
2470          }
2471        }
2472      } catch (TIRExceptLock e) {
2473        throw new GenerException(Res.res.getString("MSG_LockedTIR"));
2474      }
2475      
2476      TransformerFactory JavaDoc tFactory = TransformerFactory.newInstance();
2477      Transformer JavaDoc transformer = tFactory.newTransformer();
2478// transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");
2479
transformer.setOutputProperty("indent", "yes");
2480      DOMSource JavaDoc source = new DOMSource JavaDoc(document);
2481      CGFileWriter out = fs.newCGWriter(name+"CDD.xml");
2482      StreamResult JavaDoc result = new StreamResult JavaDoc(out);
2483      transformer.transform(source, result);
2484      out.close();
2485    } catch (ParserConfigurationException JavaDoc e) {
2486      throw new GenerException(e.getMessage(), e);
2487    } catch (TransformerConfigurationException JavaDoc e) {
2488      throw new GenerException(e.getMessage(), e);
2489    } catch (TransformerException JavaDoc e) {
2490      throw new GenerException(e.getMessage(), e);
2491    }
2492  }
2493}
2494
Popular Tags