KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > corba > xmiio > exporter > GenerationXMIExport


1 /**
2  * copyright 2002 2003 Laboratoire d'Informatique Paris 6 (LIP6)
3  *
4  * This file is part of ModFact.
5  *
6  * ModFact is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * at your option) any later version.
10  *
11  * ModFact is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with ModFact; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package org.objectweb.modfact.corba.xmiio.exporter;
21
22 import java.util.Vector JavaDoc;
23
24 import org.objectweb.modfact.corba.logging.Level;
25 import org.objectweb.modfact.corba.logging.ModFactLogger;
26 import org.objectweb.modfact.corba.xmiio.common.AbstractXMIIOGenerator;
27 import org.omg.mof.Reflective.NotSet;
28
29 /**
30  * The XMI Export generator.
31  * This class allows the generation of the XMI exporter (into XMI).
32  */

33 public class GenerationXMIExport extends AbstractXMIIOGenerator {
34
35     /** The IOR output file name. */
36     private String JavaDoc _ior_filename = new String JavaDoc("");
37
38     /** The logger. */
39     protected ModFactLogger _logger = ModFactLogger.getLogger("fr.lip6.src.mdafactory.generation.xmiio.exporter.GenerationXMIExport");
40
41     /**
42      * Default Constructor.
43      */

44     public GenerationXMIExport() {
45         super();
46         ModFactLogger logger = ModFactLogger.getLogger("fr.lip6.src.mdafactory.generation.xmiio.exporter.GenerationXMIExportApplication");
47     }
48
49     /**
50      * Set the IOR output file name.
51      * @param file_ The file name.
52      */

53     public void setIOR(String JavaDoc file_) {
54         _ior_filename = file_;
55     }
56
57     /**
58      * XMIExport generation.
59      * @param package_ The root package.
60      */

61     public void generateXMIExport(org.omg.mof.Model.Package package_)
62         throws org.omg.mof.Reflective.MofError, org.omg.CORBA.TypeCodePackage.BadKind JavaDoc, org.omg.CORBA.TypeCodePackage.Bounds JavaDoc, java.io.IOException JavaDoc {
63         _logger.log(Level.FINE, "XMIExport beginning of the generation");
64         String JavaDoc className = getClassName(package_.name());
65         _logger.log(Level.INFO, className + " generation ...");
66         packageModuleTemplate(package_);
67         flushFile();
68     }
69
70     /**
71      * Get the class name.
72      * @param package_name_ The root package name.
73      * @return The class name.
74      */

75     protected String JavaDoc getClassName(String JavaDoc package_name_) {
76         return super.getClassName(package_name_, "XMIExport");
77     }
78
79     /**
80      * Find all the classes of the package.
81      * @param package_ The package to parse.
82      * @return The found classes.
83      */

84     protected java.util.Vector JavaDoc findAllClasses(org.omg.mof.Model.Package package_) throws org.omg.mof.Reflective.MofError {
85         org.omg.mof.Model.ModelElement[] contents = package_.contents();
86         java.util.Vector JavaDoc classes = new java.util.Vector JavaDoc();
87         for (int i = 0; i < contents.length; i++) {
88             if (contents[i]._is_a(org.omg.mof.Model.ClassHelper.id()))
89                 classes.addElement(org.omg.mof.Model.ClassHelper.narrow(contents[i]));
90             else if (contents[i]._is_a(org.omg.mof.Model.ImportHelper.id())) {
91                 org.omg.mof.Model.Import imp = org.omg.mof.Model.ImportHelper.narrow(contents[i]);
92                 java.util.Vector JavaDoc call = findAllClasses(org.omg.mof.Model.PackageHelper.narrow(imp.imported_namespace()));
93                 classes.addAll(call);
94             }
95         }
96         return classes;
97     }
98
99     /**
100      * Find all the DataType Attributes of the package.
101      * @param package_ The package to parse.
102      * @return The found DataType Attribute.
103      */

104     protected java.util.Vector JavaDoc findAllDataTypeAttributes(org.omg.mof.Model.Package package_) throws org.omg.mof.Reflective.MofError {
105         org.omg.mof.Model.ModelElement[] contents = package_.contents();
106         java.util.Vector JavaDoc attributes = new java.util.Vector JavaDoc();
107         for (int i = 0; i < contents.length; i++) {
108             if (contents[i]._is_a(org.omg.mof.Model.DataTypeHelper.id()))
109                 attributes.add(org.omg.mof.Model.DataTypeHelper.narrow(contents[i]));
110             else if (contents[i]._is_a(org.omg.mof.Model.ImportHelper.id())) {
111                 org.omg.mof.Model.Import imp = org.omg.mof.Model.ImportHelper.narrow(contents[i]);
112                 java.util.Vector JavaDoc call = findAllDataTypeAttributes(org.omg.mof.Model.PackageHelper.narrow(imp.imported_namespace()));
113                 java.util.Iterator JavaDoc iterator = call.iterator();
114                 while (iterator.hasNext()) {
115                     boolean found = false;
116                     org.omg.CORBA.Object JavaDoc next = (org.omg.CORBA.Object JavaDoc) iterator.next();
117                     for (int k = 0; k < attributes.size(); k++) {
118                         org.omg.CORBA.Object JavaDoc attr = (org.omg.CORBA.Object JavaDoc) attributes.elementAt(k);
119                         if (attr._is_equivalent(next))
120                             found = true;
121                     }
122                     if (!found)
123                         attributes.add(next);
124                 }
125             }
126         }
127         return attributes;
128     }
129
130     /**
131      * Find all the Class Attributes of the package.
132      * @param package_ The package to parse.
133      * @return The found Class Attributes.
134      */

135     protected java.util.Vector JavaDoc findAllClassAttributes(org.omg.mof.Model.Package package_) throws org.omg.mof.Reflective.MofError {
136         org.omg.mof.Model.ModelElement[] contents = package_.contents();
137         java.util.Vector JavaDoc attributes = new java.util.Vector JavaDoc();
138         for (int i = 0; i < contents.length; i++) {
139             if (contents[i]._is_a(org.omg.mof.Model.ClassHelper.id())) {
140                 org.omg.mof.Model.Class class_ = org.omg.mof.Model.ClassHelper.narrow(contents[i]);
141                 org.omg.mof.Model.Reference references[] = mofHelper.referencesOfClass(class_);
142                 for (int l = 0; l < references.length; l++) {
143                     org.omg.mof.Model.Classifier classifier = references[l].type();
144                     if (!attributes.contains(classifier))
145                         attributes.add(classifier);
146                 }
147                 org.omg.mof.Model.MofAttribute attr[] =
148                     mofHelper.allAttributesOfClass(class_, org.omg.mof.Model.ScopeKind.instance_level, true);
149                 for (int l = 0; l < attr.length; l++) {
150                     org.omg.mof.Model.Classifier classifier = attr[l].type();
151                     if (classifier._is_a(org.omg.mof.Model.ClassHelper.id()) && !attributes.contains(classifier))
152                         attributes.add(classifier);
153                 }
154             } else if (contents[i]._is_a(org.omg.mof.Model.ImportHelper.id())) {
155                 org.omg.mof.Model.Import imp = org.omg.mof.Model.ImportHelper.narrow(contents[i]);
156                 java.util.Vector JavaDoc call = findAllClassAttributes(org.omg.mof.Model.PackageHelper.narrow(imp.imported_namespace()));
157                 java.util.Iterator JavaDoc iterator = call.iterator();
158                 while (iterator.hasNext()) {
159                     boolean found = false;
160                     org.omg.CORBA.Object JavaDoc next = (org.omg.CORBA.Object JavaDoc) iterator.next();
161                     for (int k = 0; k < attributes.size(); k++) {
162                         org.omg.CORBA.Object JavaDoc attr = (org.omg.CORBA.Object JavaDoc) attributes.elementAt(k);
163                         if (attr._is_equivalent(next))
164                             found = true;
165                     }
166                     if (!found)
167                         attributes.add(next);
168                 }
169             }
170         }
171         return attributes;
172     }
173
174     /**
175      * Package processing.
176      * @param package_ The package to process.
177      */

178     public void packageModuleTemplate(org.omg.mof.Model.Package package_)
179         throws org.omg.mof.Reflective.MofError, org.omg.CORBA.TypeCodePackage.BadKind JavaDoc, org.omg.CORBA.TypeCodePackage.Bounds JavaDoc {
180         _logger.log(Level.FINE, "XMIExport packageModuleTemplate");
181         if (package_.visibility().equals(org.omg.mof.Model.VisibilityKind.public_vis)) {
182             org.omg.mof.Model.Class classes_ordered[] = mofHelper.allClassesOfPackageOrderedByInheritance(package_);
183
184             String JavaDoc className = getClassName(package_.name());
185             outputln("package " + javaHelper.javaPackage(package_) + ".xmi;");
186             outputln();
187             annotationTemplate(package_.annotation());
188             outputln("public class " + className + " extends org.objectweb.modfact.corba.xmiio.exporter.XMIExport {");
189
190             constructor(package_.name(), className);
191             classAttributes(findAllClassAttributes(package_));
192             classDataTypeAttributes(findAllDataTypeAttributes(package_));
193             classTemplate(package_, classes_ordered);
194             rootPackage(package_, classes_ordered);
195             outputln("} // end of class " + className);
196             outputln();
197         }
198     }
199
200     /**
201      * XMIExport generation for constructor.
202      * @param package_name The package name.
203      * @param class_name The class name.
204      */

205     public void constructor(String JavaDoc package_name, String JavaDoc class_name) {
206         _logger.log(Level.FINE, "XMIExport constructor(" + package_name + ", " + class_name + ")");
207         outputln("/**");
208         outputln(" * Default " + class_name + " Constructor");
209         outputln(" * @param dtd The DTD File.");
210         outputln(" * @param namespace The XML Namespace.");
211         outputln(" */");
212         outputln("public " + class_name + "(java.lang.String dtd, java.lang.String namespace) {");
213         outputln("this(dtd, namespace, org.objectweb.modfact.corba.logging.ModFactLogger.getLogger(\"" + package_name + "XMIExport\"));");
214         outputln("}");
215         outputln();
216         outputln("/**");
217         outputln(" * " + class_name + " Constructor");
218         outputln(" * @param dtd The DTD File.");
219         outputln(" * @param namespace The XML Namespace.");
220         outputln(" * @param logger The logger.");
221         outputln(" */");
222         outputln(
223             "public "
224                 + class_name
225                 + "(java.lang.String dtd, java.lang.String namespace, org.objectweb.modfact.corba.logging.ModFactLogger logger) {");
226         outputln("super(dtd, namespace, \"" + idlHelper.format1(package_name) + "\", \"Model\");");
227         outputln("_logger = logger;");
228         outputln("}");
229         outputln();
230     }
231
232     protected String JavaDoc refMethod(org.omg.mof.Model.Class cls, String JavaDoc package_name) throws org.omg.mof.Reflective.MofError {
233         String JavaDoc method = idlHelper.format2(cls.name());
234         try {
235             method = idlHelper.format2(idlHelper.className(cls)) + "_ref()";
236             org.omg.mof.Model.ModelElement clsTmp = cls;
237             while (!clsTmp.container().name().equals(package_name)) {
238                 org.omg.mof.Model.Namespace ns = clsTmp.container();
239                 if (ns._is_a(org.omg.mof.Model.ClassifierHelper.id())) {
240                     org.omg.mof.Model.Classifier container = org.omg.mof.Model.ClassifierHelper.narrow(ns);
241                     method = idlHelper.format2(javaHelper.javaClassifierName(container)) + "_ref()." + method;
242                 } else {
243                     method = idlHelper.format2(clsTmp.container().name()) + "_ref()." + method;
244                 }
245                 clsTmp = clsTmp.container();
246             }
247         } catch (org.omg.CORBA.MARSHAL JavaDoc marshal) { /* The marshal exception contains the NotSet Exception */
248             if (!marshal.getMessage().equals("IDL:mof.omg.org/Reflective/NotSet:1.0"))
249                 throw marshal;
250         } catch (org.omg.mof.Reflective.NotSet notSet) {
251             // Nothing to do
252
}
253         return method;
254     }
255
256     /**
257      * Generate the methods for the writing of complex type.
258      * @param attributes List of DataType attributes.
259      */

260     public void classAttributes(Vector JavaDoc attributes) throws org.omg.mof.Reflective.MofError {
261         _logger.log(Level.FINE, "XMIExport classAttributeTemplate()");
262         java.util.Iterator JavaDoc iterator = attributes.iterator();
263         outputln("// ==================================================================");
264         outputln("// Method to write some Classes");
265         outputln("// ==================================================================");
266         while (iterator.hasNext()) {
267             org.omg.mof.Model.Classifier classifier2 = (org.omg.mof.Model.Classifier) iterator.next();
268             org.omg.mof.Model.Class classifier = org.omg.mof.Model.ClassHelper.narrow(classifier2);
269             annotationTemplate(classifier.annotation());
270             String JavaDoc classifierQualifiedName;
271             try {
272                 classifierQualifiedName = javaHelper.javaQualifiedName(classifier);
273             } catch (NotSet notSet) {
274                 classifierQualifiedName = idlHelper.format1(classifier.name());
275             }
276             outputln("public void write" + idlHelper.format1(classifier.name()) + "(" + classifierQualifiedName + " _toWrite)");
277             outputln(" throws org.omg.mof.Reflective.MofError {");
278             outputln("if (_toWrite == null)");
279             outputln(" return;");
280             outputln("outputln(\"<" + classifierQualifiedName + " xmi.id=\\\"\" + getXMIId(_toWrite) + \"\\\">\");");
281             org.omg.mof.Model.MofAttribute attr[] =
282                 mofHelper.allAttributesOfClass(classifier, org.omg.mof.Model.ScopeKind.instance_level, true);
283             for (int j = 0; j < attr.length; j++) {
284                 classAttributeTemplate(attr[j], "_toWrite");
285             }
286             org.omg.mof.Model.Reference ref[] = mofHelper.allReferencesOfClass(classifier);
287             for (int j = 0; j < ref.length; j++) {
288                 classReferenceTemplate(ref[j], "_toWrite");
289             }
290             outputln("outputln(\"</" + classifierQualifiedName + ">\");");
291             outputln("}");
292             outputln();
293         }
294     }
295
296     /**
297      * Generate the methods for the writing of complex type.
298      * @param attributes List of DataType attributes.
299      */

300     public void classDataTypeAttributes(Vector JavaDoc attributes) throws org.omg.mof.Reflective.MofError {
301         _logger.log(Level.FINE, "XMIExport classAttributeTemplate()");
302         java.util.Iterator JavaDoc iterator = attributes.iterator();
303         outputln("// ==================================================================");
304         outputln("// Method to write the DataTypes");
305         outputln("// ==================================================================");
306         while (iterator.hasNext()) {
307             org.omg.mof.Model.DataType dataType = (org.omg.mof.Model.DataType) iterator.next();
308             org.omg.CORBA.TypeCode JavaDoc typeCode = dataType.type_code();
309             switch (typeCode.kind().value()) {
310                 case org.omg.CORBA.TCKind._tk_enum :
311                     try {
312                         outputln(
313                             "public java.lang.String enumeration"
314                                 + idlHelper.format1(dataType.name())
315                                 + "ToString("
316                                 + javaHelper.javaQualifiedName(dataType)
317                                 + " value) {");
318                         for (int i = 0; i < typeCode.member_count(); i++) {
319                             outputln("if (value.equals(" + javaHelper.javaQualifiedName(dataType) + "." + typeCode.member_name(i) + "))");
320                             outputln(" return \"" + idlHelper.format2(typeCode.member_name(i)) + "\";");
321                         }
322                     } catch (org.omg.CORBA.TypeCodePackage.BadKind JavaDoc badKind) {
323                         // Nothing to do
324
} catch (org.omg.CORBA.TypeCodePackage.Bounds JavaDoc bounds) {
325                         // Nothing to do
326
} catch (org.omg.mof.Reflective.NotSet notSet) {
327                         // Nothing to do
328
}
329                     outputln("return new java.lang.String();");
330                     outputln("}");
331                     outputln();
332                     break;
333             }
334         }
335     }
336
337     /**
338      * XMIExport generation for the class template.
339      * @param package_ The package.
340      * @param classes The classes of the package.
341      */

342     public void classTemplate(org.omg.mof.Model.Package package_, org.omg.mof.Model.Class classes[])
343         throws org.omg.mof.Reflective.MofError {
344         _logger.log(Level.FINE, "XMIExport classTemplate()");
345         String JavaDoc package_name = package_.name();
346         outputln("// ==================================================================");
347         outputln("// XXXTemplate with XXX an entity");
348         outputln("// ==================================================================");
349         // Classes
350
for (int i = 0; i < classes.length; i++) {
351             org.omg.mof.Model.Class cls = classes[i];
352             annotationTemplate(cls.annotation());
353             String JavaDoc model_package_type;
354             if (mappingValid) {
355                 model_package_type = javaHelper.javaPackage(package_) + "._" + idlHelper.format1(package_name) + "Package";
356             } else {
357                 model_package_type = javaHelper.javaPackage(package_) + "." + idlHelper.format1(package_name) + "Package";
358             }
359             outputln("public void " + idlHelper.format1FirstMin(cls.name()) + "Template(" + model_package_type + " _model_package)");
360             outputln(" throws org.omg.mof.Reflective.MofError {");
361             String JavaDoc clsClass = idlHelper.format1FirstMin(cls.name()) + "Class";
362             String JavaDoc clsTab = javaHelper.testJavaConflict(idlHelper.format1FirstMin(cls.name()) + "s");
363             String JavaDoc clsName;
364             String JavaDoc xmiQualifiedName;
365             try {
366                 clsName = idlHelper.className(cls);
367                 xmiQualifiedName = javaHelper.javaQualifiedName(cls);
368             } catch (NotSet notSet) {
369                 clsName = cls.name();
370                 xmiQualifiedName = clsName;
371             }
372             String JavaDoc javaQualifiedName;
373             try {
374                 org.omg.mof.Model.Namespace ns = cls.container();
375                 if (ns._is_a(org.omg.mof.Model.PackageHelper.id())) {
376                     org.omg.mof.Model.Package pck = org.omg.mof.Model.PackageHelper.narrow(ns);
377                     javaQualifiedName = javaHelper.javaPackage(pck) + "." + clsName;
378                 } else {
379                     javaQualifiedName = javaHelper.javaQualifiedName(ns) + "." + clsName;
380                 }
381             } catch (NotSet notSet) {
382                 javaQualifiedName = clsName;
383             }
384             outputln(
385                 "_logger.log(org.objectweb.modfact.corba.logging.Level.FINE, \""
386                     + idlHelper.format1FirstMin(cls.name())
387                     + "Template(\" + _model_package + \")\");");
388             outputln(javaQualifiedName + "Class " + clsClass + " = _model_package." + refMethod(cls, package_name) + ";");
389             try {
390                 outputln(
391                     javaQualifiedName
392                         + "[] "
393                         + clsTab
394                         + " = "
395                         + clsClass
396                         + ".all_of_type_"
397                         + idlHelper.format2(idlHelper.className(cls))
398                         + "();");
399             } catch (org.omg.mof.Reflective.NotSet notSet) {
400                 outputln(javaQualifiedName + "[] " + clsTab + " = " + clsClass + ".all_of_type_" + idlHelper.format2(cls.name()) + "();");
401             }
402             outputln("for (int i=0 ; i<" + clsTab + ".length ; i++) {");
403             outputln("outputln(\"<" + xmiQualifiedName + " xmi.id=\\\"\" + getXMIId(" + clsTab + "[i]) + \"\\\">\");");
404             org.omg.mof.Model.MofAttribute attributes[] =
405                 mofHelper.allAttributesOfClass(cls, org.omg.mof.Model.ScopeKind.instance_level, true);
406             for (int j = 0; j < attributes.length; j++) {
407                 classAttributeTemplate(attributes[j], clsTab + "[i]");
408             }
409             org.omg.mof.Model.Reference references[] = mofHelper.allReferencesOfClass(cls);
410             for (int j = 0; j < references.length; j++) {
411                 //classReferenceTemplate((org.omg.mof.Model.Reference)references.elementAt(j), clsTab + "[i]");
412
org.omg.mof.Model.Reference ref = references[j];
413                 String JavaDoc variable = javaHelper.format2Idl2JavaConflict(ref.name());
414
415                 //if (ref.multiplicity().lower == 0)
416
// outputln("try {");
417

418                 if (ref.multiplicity().upper == -1) {
419                     try {
420                         outputln(javaHelper.javaQualifiedName(ref.type()) + " [] " + variable + " = " + clsTab + "[i]." + variable + "();");
421                         outputln("for (int k=0 ; k<" + variable + ".length ; k++) {");
422                         outputln("write" + idlHelper.format1(ref.type().name()) + "(" + variable + "[k]);");
423                         outputln("}");
424                     } catch (NotSet notSet) {
425                         // Nothing to do.
426
}
427                 } else {
428                     String JavaDoc content = "write" + idlHelper.format1(ref.type().name()) + "(" + clsTab + "[i]." + variable + "());";
429                     if (ref.multiplicity().lower == 0) {
430                         outputln("try {");
431                         outputln(content);
432                         outputln("} catch (org.omg.mof.Reflective.NotSet notSet) { /* Nothing to do */ }");
433                     } else {
434                         outputln(content);
435                     }
436                 }
437
438                 //if (ref.multiplicity().lower == 0)
439
// outputln("} catch (org.omg.mof.Reflective.NotSet notSet) { /* Nothing to do */ }");
440

441             }
442             outputln("outputln(\"</" + xmiQualifiedName + ">\");");
443             outputln("}");
444             outputln("}");
445             outputln();
446         }
447     }
448
449     /**
450      * XMIExport generation for the class attribute template.
451      * @param attribute The class attribute.
452      * @param variable_name The variable name.
453      */

454     public void classAttributeTemplate(org.omg.mof.Model.MofAttribute attribute, String JavaDoc variable_name)
455         throws org.omg.mof.Reflective.MofError {
456         _logger.log(Level.FINE, "XMIExport classAttributeTemplate(" + attribute.name() + ")");
457         try {
458             String JavaDoc attrName = javaHelper.javaQualifiedName(attribute.container()) + "." + idlHelper.format1(attribute.name());
459             String JavaDoc attrCall = idlHelper.format2(attribute.name()) + "()";
460             if (attribute.type().name().equals("*CORBA::TypeCode")) {
461                 outputln("outputln(\"<" + attrName + ">\");");
462                 outputln(
463                     "outputln(\"<XMI.CorbaTypeCode xmi.id=\\\"\" + getTypeCodeId(" + variable_name + "." + attrCall + ") + \"\\\" >\");");
464                 outputln("outputln(\"<\" + typeCode2XML(" + variable_name + "." + attrCall + ") + \"/>\");");
465                 outputln("outputln(\"</XMI.CorbaTypeCode>\");");
466                 outputln("outputln(\"</" + attrName + ">\");");
467             } else {
468                 String JavaDoc tag1 = "<" + attrName + ">";
469                 String JavaDoc tag2 = "</" + attrName + ">";
470                 String JavaDoc readAttribute = variable_name + "." + attrCall;
471                 String JavaDoc content = "outputln(\"" + tag1 + "\" + " + readAttribute + " + \"" + tag2 + "\");";
472                 org.omg.mof.Model.Classifier type = attribute.type();
473                 if (type._is_a(org.omg.mof.Model.DataTypeHelper.id())) {
474                     org.omg.mof.Model.DataType dataType = org.omg.mof.Model.DataTypeHelper.narrow(type);
475                     switch (dataType.type_code().kind().value()) {
476                         case org.omg.CORBA.TCKind._tk_enum :
477                             readAttribute = "enumeration" + idlHelper.format1(dataType.name()) + "ToString(" + readAttribute + ")";
478                             content = "outputln(\"" + tag1 + "\" + " + readAttribute + " + \"" + tag2 + "\");";
479                     }
480                 } else {
481                     if (type._is_a(org.omg.mof.Model.ClassHelper.id())) {
482                         org.omg.mof.Model.Class class_ = org.omg.mof.Model.ClassHelper.narrow(type);
483                         content = "if (" + readAttribute + " != null) {\n";
484                         readAttribute = "write" + idlHelper.format1(class_.name()) + "(" + readAttribute + ")";
485                         content = content + "outputln(\"" + tag1 + "\");\n" + readAttribute + ";\n" + "outputln(\"" + tag2 + "\");" + "\n}";
486                     }
487                 }
488
489                 if (attribute.multiplicity().lower == 0 && attribute.multiplicity().upper != -1) {
490                     outputln("try {");
491                     outputln(content);
492                     outputln("} catch (org.omg.mof.Reflective.NotSet notSet) { /* Nothing to do */ }");
493                 } else if (attribute.multiplicity().upper == -1) {
494                     outputln("for (int k=0 ; k<" + readAttribute + ".length ; k++) {");
495                     outputln("if (k>0) output(\" \");");
496                     outputln("output(\"<" + attrName + ">\" + " + readAttribute + "[k] + \"</" + attrName + ">\");");
497                     outputln("}");
498                 } else {
499                     outputln(content);
500                 }
501             }
502         } catch (org.omg.mof.Reflective.NotSet notSet) {
503             // Nothing to do
504
}
505     }
506
507     /**
508      * XMIExport generation for the class reference template.
509      * @param reference The class reference.
510      * @param variable_name The variable name.
511      */

512     public void classReferenceTemplate(org.omg.mof.Model.Reference reference, String JavaDoc variable_name)
513         throws org.omg.mof.Reflective.MofError {
514         _logger.log(Level.FINE, "XMIExport classReferenceTemplate(" + reference.name() + ")");
515         try {
516             String JavaDoc refName = javaHelper.javaQualifiedName(reference.container()) + "." + idlHelper.format1(reference.name());
517             String JavaDoc refTab = javaHelper.format2Idl2JavaConflict(reference.name());
518             String JavaDoc refType = javaHelper.javaQualifiedName(reference.type());
519             if (reference.multiplicity().upper == -1) {
520                 outputln(refType + "[] " + refTab + " = " + variable_name + "." + refTab + "();");
521                 outputln("if (" + refTab + ".length > 0) {");
522                 outputln("outputln(\"<" + refName + ">\");");
523                 outputln("for (int j=0 ; j<" + refTab + ".length ; j++)");
524                 outputln(" outputln(\"<" + refType + " xmi.idref=\\\"\" + getXMIId(" + refTab + "[j]) + \"\\\" />\");");
525                 outputln("outputln(\"</" + refName + ">\");");
526                 outputln("}");
527             } else {
528                 if (reference.multiplicity().lower == 0)
529                     outputln("try {");
530                 outputln(refType + " " + refTab + " = " + variable_name + "." + refTab + "();");
531                 outputln("if (" + refTab + " != null) {");
532                 outputln("outputln(\"<" + refName + ">\");");
533                 outputln("outputln(\"<" + refType + " xmi.idref=\\\"\" + getXMIId(" + refTab + ") + \"\\\" />\");");
534                 outputln("outputln(\"</" + refName + ">\");");
535                 outputln("}");
536                 if (reference.multiplicity().lower == 0)
537                     outputln("} catch (org.omg.mof.Reflective.NotSet notSet) { /* Nothing to do */ }");
538             }
539         } catch (org.omg.mof.Reflective.NotSet notSet) {
540             // Nothing to do
541
}
542     }
543
544     /**
545      * XMIExport generation for the root package.
546      * @param package_ The package.
547      * @param classes The classes of the package.
548      */

549     public void rootPackage(org.omg.mof.Model.Package package_, org.omg.mof.Model.Class classes[]) throws org.omg.mof.Reflective.MofError {
550         _logger.log(Level.FINE, "XMIExport rootPackage()");
551         outputln("public void rootPackageTemplate(org.omg.CORBA.Object _root_package)");
552         outputln(" throws org.omg.mof.Reflective.MofError {");
553         outputln("_logger.log(org.objectweb.modfact.corba.logging.Level.FINE, \"rootPackageTemplate(\" + _root_package + \")\");");
554         String JavaDoc packageName = idlHelper.format1(package_.name());
555         String JavaDoc model_package_type;
556         if (mappingValid) {
557             model_package_type = javaHelper.javaPackage(package_) + "._" + idlHelper.format1(packageName) + "Package";
558         } else {
559             model_package_type = javaHelper.javaPackage(package_) + "." + idlHelper.format1(packageName) + "Package";
560         }
561         outputln(model_package_type + " _model_package = " + model_package_type + "Helper.narrow(_root_package);");
562         for (int i = 0; i < classes.length; i++) {
563             org.omg.mof.Model.Class cls = (org.omg.mof.Model.Class) classes[i];
564             if (!cls.is_abstract())
565                 outputln(idlHelper.format1FirstMin(cls.name()) + "Template(_model_package);");
566         }
567         outputln("}");
568         outputln();
569     }
570
571 }
572
Popular Tags