KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > corba > provider > MOFCachedProvider


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.provider;
21
22 import java.util.Enumeration JavaDoc;
23 import java.util.Hashtable JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25 import java.util.Vector JavaDoc;
26 import org.omg.mof.Model.*;
27 import org.omg.mof.Reflective.*;
28
29 import org.objectweb.modfact.corba.helper.MOFCommon;
30
31 /**
32  *
33  */

34 public class MOFCachedProvider implements MOFCommon {
35
36     /**
37      * Give the value of a Constant
38      */

39     public String JavaDoc valueOfConstant(org.omg.CORBA.Any JavaDoc _value)
40         throws org.omg.CORBA.TypeCodePackage.BadKind JavaDoc {
41         org.omg.CORBA.TypeCode JavaDoc _typecode = _value.type();
42         switch (_typecode.kind().value()) {
43             case org.omg.CORBA.TCKind._tk_boolean :
44                 return String.valueOf(_value.extract_boolean());
45
46             case org.omg.CORBA.TCKind._tk_octet :
47                 return String.valueOf(
48                     (new Byte JavaDoc(_value.extract_octet())).toString());
49
50             case org.omg.CORBA.TCKind._tk_char :
51                 return String.valueOf(_value.extract_char());
52
53             case org.omg.CORBA.TCKind._tk_wchar :
54                 return String.valueOf(_value.extract_wchar());
55
56             case org.omg.CORBA.TCKind._tk_short :
57                 return String.valueOf(
58                     (new Short JavaDoc(_value.extract_short())).toString());
59
60             case org.omg.CORBA.TCKind._tk_ushort :
61                 return String.valueOf(
62                     (new Short JavaDoc(_value.extract_ushort())).toString());
63
64             case org.omg.CORBA.TCKind._tk_long :
65                 return String.valueOf(_value.extract_long());
66
67             case org.omg.CORBA.TCKind._tk_ulong :
68                 return String.valueOf(_value.extract_ulong());
69
70             case org.omg.CORBA.TCKind._tk_longlong :
71                 return String.valueOf(_value.extract_longlong());
72
73             case org.omg.CORBA.TCKind._tk_ulonglong :
74                 return String.valueOf(_value.extract_ulonglong());
75
76             case org.omg.CORBA.TCKind._tk_double :
77                 return String.valueOf(_value.extract_double());
78
79             case org.omg.CORBA.TCKind._tk_float :
80                 return String.valueOf(_value.extract_float());
81
82             case org.omg.CORBA.TCKind._tk_string :
83                 return _value.extract_string();
84
85             case org.omg.CORBA.TCKind._tk_wstring :
86                 return _value.extract_wstring();
87
88             default :
89                 throw new org.omg.CORBA.TypeCodePackage.BadKind JavaDoc();
90         }
91     }
92
93     /**
94      * Give the attributes of a Class (included the inherited ones)
95      */

96     public org.omg.mof.Model.MofAttribute[] attributesOfClass(
97         org.omg.mof.Model.Class _class,
98         org.omg.mof.Model.ScopeKind _scope,
99         boolean _test_of_derived)
100         throws org.omg.mof.Reflective.MofError {
101         String JavaDoc key = _class.ref_mof_id();
102         MOFClassCached classCached =
103             (MOFClassCached) _contentsOfClasses.get(key);
104         Vector JavaDoc res;
105         if (_scope.equals(org.omg.mof.Model.ScopeKind.classifier_level)) {
106             if (_test_of_derived)
107                 res = classCached.attributesClass;
108             else
109                 res = classCached.attributesClassNd;
110         } else {
111             if (_test_of_derived)
112                 res = classCached.attributesInst;
113             else
114                 res = classCached.attributesInstNd;
115         }
116         org.omg.mof.Model.MofAttribute[] resT =
117             new org.omg.mof.Model.MofAttribute[res.size()];
118         for (int i = 0; i < resT.length; i++)
119             resT[i] = (org.omg.mof.Model.MofAttribute) res.elementAt(i);
120         return resT;
121
122     }
123     
124     /**
125      * Adds an element into a vector if it is not present
126      * (Test with the _is_equivalent method)
127      * @param vector The vector which contains the elements
128      * @param object The element to add
129      */

130     private void addElement(Vector JavaDoc vector, org.omg.CORBA.Object JavaDoc object){
131         boolean find = false;
132         java.util.Iterator JavaDoc it = vector.iterator();
133         while (it.hasNext() && !find) {
134             org.omg.CORBA.Object JavaDoc obj = (org.omg.CORBA.Object JavaDoc) it.next();
135             if (obj._is_equivalent(object))
136                 find = true;
137         }
138         if (!find)
139             vector.addElement(object);
140     }
141
142     /**
143      * Give all the attributes of a Class
144      */

145     public org.omg.mof.Model.MofAttribute[] allAttributesOfClass(
146         org.omg.mof.Model.Class _class,
147         org.omg.mof.Model.ScopeKind _scope,
148         boolean isDerived)
149         throws org.omg.mof.Reflective.MofError {
150         //avoir toutes les classes
151
Vector JavaDoc allSuperClasses = superClassesOrdered(_class);
152
153         //créer le vecteur conteneur
154
Vector JavaDoc attributesVector = new Vector JavaDoc();
155
156         for (int i = 0; i < allSuperClasses.size(); i++) {
157
158             //claculer la clé
159
String JavaDoc classId =
160                 ((org.omg.mof.Model.Class) allSuperClasses.elementAt(i))
161                     .ref_mof_id();
162
163             if (_scope.equals(ScopeKind.classifier_level)) {
164                 if (!isDerived) {
165                     Vector JavaDoc _temp =
166                         (
167                             (MOFClassCached) _contentsOfClasses.get(
168                                 classId)).attributesClassNd;
169                     for (int j = 0; j < _temp.size(); j++)
170                         addElement(attributesVector,
171                             (org.omg.mof.Model.MofAttribute) _temp.elementAt(
172                                 j));
173                 } else {
174                     Vector JavaDoc _temp =
175                         (
176                             (MOFClassCached) _contentsOfClasses.get(
177                                 classId)).attributesClass;
178                     for (int j = 0; j < _temp.size(); j++)
179                         addElement(attributesVector,
180                             (org.omg.mof.Model.MofAttribute) _temp.elementAt(
181                                 j));
182                 }
183             } else {
184                 if (!isDerived) {
185                     Vector JavaDoc _temp =
186                         (
187                             (MOFClassCached) _contentsOfClasses.get(
188                                 classId)).attributesInstNd;
189                     for (int j = 0; j < _temp.size(); j++)
190                         addElement(attributesVector,
191                             (org.omg.mof.Model.MofAttribute) _temp.elementAt(
192                                 j));
193                 } else {
194                     Vector JavaDoc _temp =
195                         (
196                             (MOFClassCached) _contentsOfClasses.get(
197                                 classId)).attributesInst;
198                     for (int j = 0; j < _temp.size(); j++)
199                         addElement(attributesVector,
200                             (org.omg.mof.Model.MofAttribute) _temp.elementAt(
201                                 j));
202                 }
203             }
204         }
205         org.omg.mof.Model.MofAttribute[] res =
206             new org.omg.mof.Model.MofAttribute[attributesVector.size()];
207         for (int i = 0; i < res.length; i++)
208             res[i] =
209                 (org.omg.mof.Model.MofAttribute) attributesVector.elementAt(i);
210         return res;
211
212     }
213
214     /**
215      * Give the operations of a Class
216      */

217     public org.omg.mof.Model.Operation[] operationsOfClass(
218         org.omg.mof.Model.Class _class,
219         org.omg.mof.Model.ScopeKind _scope)
220         throws org.omg.mof.Reflective.MofError {
221         Vector JavaDoc operationVector;
222         MOFClassCached classCached =
223             (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id());
224         if (_scope.equals(org.omg.mof.Model.ScopeKind.classifier_level))
225             operationVector = classCached.operationsClass;
226         else
227             operationVector = classCached.operationsInst;
228         org.omg.mof.Model.Operation[] res =
229             new org.omg.mof.Model.Operation[operationVector.size()];
230         for (int i = 0; i < res.length; i++)
231             res[i] = (org.omg.mof.Model.Operation) operationVector.elementAt(i);
232         return res;
233
234     }
235
236     /**
237      * Give all the operation of a Class (included the inherited ones)
238      */

239     public org.omg.mof.Model.Operation[] allOperationsOfClass(
240         org.omg.mof.Model.Class _class,
241         org.omg.mof.Model.ScopeKind _scope)
242         throws org.omg.mof.Reflective.MofError {
243         //avoir toutes les classes
244
Vector JavaDoc allSuperclasses = superClassesOrdered(_class);
245
246         //créer le vecteur conteneur
247
Vector JavaDoc operationsVector = new Vector JavaDoc();
248
249         for (int i = 0; i < allSuperclasses.size(); i++) {
250
251             //claculer la clé
252
String JavaDoc classId =
253                 ((org.omg.mof.Model.Class) allSuperclasses.elementAt(i))
254                     .ref_mof_id();
255             if (_scope.equals(ScopeKind.classifier_level)) {
256                 Vector JavaDoc _temp =
257                     (
258                         (MOFClassCached) _contentsOfClasses.get(
259                             classId)).operationsClass;
260                 for (int j = 0; j < _temp.size(); j++)
261                     addElement(operationsVector, (Operation) _temp.elementAt(j));
262             } else {
263                 Vector JavaDoc _temp =
264                     (
265                         (MOFClassCached) _contentsOfClasses.get(
266                             classId)).operationsInst;
267                 for (int j = 0; j < _temp.size(); j++)
268                     addElement(operationsVector, (Operation) _temp.elementAt(j));
269             }
270         }
271         org.omg.mof.Model.Operation[] res =
272             new org.omg.mof.Model.Operation[operationsVector.size()];
273         for (int i = 0; i < res.length; i++)
274             res[i] =
275                 (org.omg.mof.Model.Operation) operationsVector.elementAt(i);
276         return res;
277
278     }
279
280     /**
281      * Give the references of a Class
282      */

283     public org.omg.mof.Model.Reference[] referencesOfClass(
284         org.omg.mof.Model.Class _class)
285         throws org.omg.mof.Reflective.MofError {
286         MOFClassCached classCached =
287             (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id());
288         Vector JavaDoc references = classCached.refrences;
289         org.omg.mof.Model.Reference[] res =
290             new org.omg.mof.Model.Reference[references.size()];
291         for (int i = 0; i < res.length; i++)
292             res[i] = (org.omg.mof.Model.Reference) references.elementAt(i);
293         return res;
294
295     }
296
297     /**
298      * Give all the references of a Class (included the inherited ones)
299      */

300     public org.omg.mof.Model.Reference[] allReferencesOfClass(
301         org.omg.mof.Model.Class _class)
302         throws org.omg.mof.Reflective.MofError {
303         //avoir toutes les classes
304
Vector JavaDoc allSuperClasses = superClassesOrdered(_class);
305
306         //créer le vecteur conteneur
307
Vector JavaDoc referencesVector = new Vector JavaDoc();
308
309         for (int i = 0; i < allSuperClasses.size(); i++) {
310             //claculer la clé
311
String JavaDoc classId =
312                 ((org.omg.mof.Model.Class) allSuperClasses.elementAt(i))
313                     .ref_mof_id();
314
315             Vector JavaDoc _temp =
316                 ((MOFClassCached) _contentsOfClasses.get(classId)).refrences;
317             for (int j = 0; j < _temp.size(); j++)
318                 addElement(referencesVector, (Reference) _temp.elementAt(j));
319         }
320         org.omg.mof.Model.Reference[] res =
321             new org.omg.mof.Model.Reference[referencesVector.size()];
322         for (int i = 0; i < res.length; i++)
323             res[i] =
324                 (org.omg.mof.Model.Reference) referencesVector.elementAt(i);
325         return res;
326     }
327
328     /**
329      * Give the constants of a Class
330      */

331     public org.omg.mof.Model.Constant[] constantsOfClass(
332         org.omg.mof.Model.Class _class)
333         throws org.omg.mof.Reflective.MofError {
334         MOFClassCached classCached =
335             (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id());
336         Vector JavaDoc constants = classCached.mofConstants;
337         org.omg.mof.Model.Constant[] res =
338             new org.omg.mof.Model.Constant[constants.size()];
339         for (int i = 0; i < res.length; i++)
340             res[i] = (org.omg.mof.Model.Constant) constants.elementAt(i);
341         return res;
342     }
343
344     /**
345      * Give the datatypes of a Class
346      */

347     public org.omg.mof.Model.DataType[] datatypesOfClass(
348         org.omg.mof.Model.Class _class)
349         throws org.omg.mof.Reflective.MofError {
350         MOFClassCached classCached =
351             (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id());
352         Vector JavaDoc datatypes = classCached.mofDatatypes;
353         org.omg.mof.Model.DataType[] res =
354             new org.omg.mof.Model.DataType[datatypes.size()];
355         for (int i = 0; i < res.length; i++)
356             res[i] = (org.omg.mof.Model.DataType) datatypes.elementAt(i);
357         return res;
358     }
359
360     /**
361      * Give the exceptions of a Class
362      */

363     public org.omg.mof.Model.MofException[] exceptionsOfClass(
364         org.omg.mof.Model.Class _class)
365         throws org.omg.mof.Reflective.MofError {
366         MOFClassCached classCached =
367             (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id());
368         Vector JavaDoc exceptions = classCached.mofExcepion;
369         org.omg.mof.Model.MofException[] res =
370             new org.omg.mof.Model.MofException[exceptions.size()];
371         for (int i = 0; i < res.length; i++)
372             res[i] = (org.omg.mof.Model.MofException) exceptions.elementAt(i);
373         return res;
374     }
375
376     /**
377      * Give the constrains of a Class
378      */

379     public org.omg.mof.Model.Constraint[] constraintsOfClass(
380         org.omg.mof.Model.Class _class)
381         throws org.omg.mof.Reflective.MofError {
382         MOFClassCached classCached =
383             (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id());
384         Vector JavaDoc constraints = classCached.mofConstraints;
385         org.omg.mof.Model.Constraint[] res =
386             new org.omg.mof.Model.Constraint[constraints.size()];
387         for (int i = 0; i < res.length; i++)
388             res[i] = (org.omg.mof.Model.Constraint) constraints.elementAt(i);
389         return res;
390     }
391
392     /**
393      * Give the associations ends of an Association
394      */

395     public org.omg.mof.Model.AssociationEnd[] associationEndsOfAssociation(
396         org.omg.mof.Model.Association _association)
397         throws org.omg.mof.Reflective.MofError {
398         AssociationEnd[] associationEnds = new AssociationEnd[2];
399         ModelElement[] contents = _association.contents();
400
401         for (int i = 0; i < contents.length; i++) {
402             if (contents[i]._is_a(AssociationEndHelper.id()))
403                 associationEnds[i] =
404                     (org
405                         .omg
406                         .mof
407                         .Model
408                         .AssociationEndHelper
409                         .narrow(contents[i]));
410         }
411         return associationEnds;
412     }
413     
414     /**
415      * Give the opposite association end of an association end
416      */

417     public org.omg.mof.Model.AssociationEnd oppositeAssociationEnd(
418         org.omg.mof.Model.AssociationEnd _association_end)
419         throws org.omg.mof.Reflective.MofError {
420         try {
421             org.omg.mof.Model.Association asso = org.omg.mof.Model.AssociationHelper.narrow(_association_end.container());
422             org.omg.mof.Model.AssociationEnd[] ends = associationEndsOfAssociation(asso);
423             if (ends[0]._is_equivalent(_association_end))
424                 return ends[1];
425             else
426                 return ends[0];
427         } catch (org.omg.mof.Reflective.NotSet notSet) {
428             return null;
429         }
430     }
431
432     /**
433      * Give the classes of a Package
434      */

435     public org.omg.mof.Model.Class[] classesOfPackage(
436         org.omg.mof.Model.Package _package)
437         throws org.omg.mof.Reflective.MofError {
438         // vecteur contenuer
439
Hashtable JavaDoc disorderedClasses = new Hashtable JavaDoc();
440
441         //le contenu
442
ModelElement[] contents = _package.contents();
443         for (int i = 0; i < contents.length; i++) {
444             ModelElement current = contents[i];
445             if (current._is_a(ClassHelper.id())) {
446                 org.omg.mof.Model.Class _class = ClassHelper.narrow(current);
447                 if (!disorderedClasses.containsKey(_class.ref_mof_id()))
448                     disorderedClasses.put(_class.ref_mof_id(), _class);
449             }
450         }
451         org.omg.mof.Model.Class[] res =
452             new org.omg.mof.Model.Class[disorderedClasses.size()];
453         int i = 0;
454         for (Enumeration JavaDoc e = disorderedClasses.elements();
455             e.hasMoreElements();
456             ) {
457             res[i++] = (org.omg.mof.Model.Class) e.nextElement();
458         }
459         return res;
460
461     }
462
463     /**
464      * Give the classes of a Package
465      */

466     public org.omg.mof.Model.Class[] classesOfPackageOrderedByInheritance(
467         org.omg.mof.Model.Package _package)
468         throws org.omg.mof.Reflective.MofError {
469         org.omg.mof.Model.Class[] classesUnordered = classesOfPackage(_package);
470         
471         Vector JavaDoc classesUnorderedV = new Vector JavaDoc();
472         Vector JavaDoc classesOrderedV = new Vector JavaDoc();
473         for (int i = 0; i < classesUnordered.length; i++)
474             classesUnorderedV.addElement(classesUnordered[i]);
475
476         int courant = 0;
477         while (classesUnorderedV.size() != 0) {
478             org.omg.mof.Model.Class _courant = null;
479             _courant =
480                 (org.omg.mof.Model.Class) classesUnorderedV.elementAt(courant);
481             org.omg.mof.Model.GeneralizableElement[] supertypes =
482                 _courant.supertypes();
483                 
484             boolean _is_top = true;
485             int j = 0;
486             while (_is_top && j < supertypes.length) {
487                 // Use _is_equivalent method instead of calling equals method (by Vector.contains())
488
// if (classesUnorderedV.contains(supertypes[j]))
489
// _is_top = false;
490
for (int i=0 ; i<classesUnorderedV.size() ; i++) {
491                     org.omg.CORBA.Object JavaDoc o = (org.omg.CORBA.Object JavaDoc) classesUnorderedV.elementAt(i);
492                     if (o._is_equivalent(supertypes[j]))
493                         _is_top = false;
494                 }
495                 
496                 j++;
497             }
498             if (_is_top) {
499                 classesOrderedV.addElement(_courant);
500                 classesUnorderedV.removeElement(_courant);
501                 courant = 0;
502             } else
503                 courant++;
504         }
505         org.omg.mof.Model.Class[] resu =
506             new org.omg.mof.Model.Class[classesOrderedV.size()];
507         for (int i = 0; i < resu.length; i++)
508             resu[i] = (org.omg.mof.Model.Class) classesOrderedV.elementAt(i);
509         return resu;
510     }
511
512     /**
513      * Give the classes of a Package
514      */

515     public org.omg.mof.Model.Class[] allClassesOfPackage(
516         org.omg.mof.Model.Package _package)
517         throws org.omg.mof.Reflective.MofError {
518         // vecteur contenuer
519
Hashtable JavaDoc disorderedClasses = new Hashtable JavaDoc();
520
521         //le contenu
522
ModelElement[] contents = _package.contents();
523         for (int i = 0; i < contents.length; i++) {
524             ModelElement current = contents[i];
525             if (current._is_a(ClassHelper.id())) {
526                 org.omg.mof.Model.Class _class = ClassHelper.narrow(current);
527                 if (!disorderedClasses.containsKey(_class.ref_mof_id()))
528                     disorderedClasses.put(_class.ref_mof_id(), _class);
529             } else if (current._is_a(ImportHelper.id())) {
530                 Import _import = ImportHelper.narrow(current);
531
532                 //récupération des caractéristiques du namesapce récupéré
533
boolean isClustered = _import.is_clustered();
534                 Namespace namespace = _import.imported_namespace();
535
536                 //traitement
537
if (isClustered) {
538                     if (namespace._is_a(ClassHelper.id())) {
539                         org.omg.mof.Model.Class _class =
540                             ClassHelper.narrow(namespace);
541                         if (!disorderedClasses
542                             .containsKey(_class.ref_mof_id()))
543                             disorderedClasses.put(_class.ref_mof_id(), _class);
544                     } else if (namespace._is_a(PackageHelper.id())) {
545                         // c'est un package
546
org.omg.mof.Model.Package clusteredPacakge =
547                             PackageHelper.narrow(namespace);
548
549                         org.omg.mof.Model.Class[] contentsCluster =
550                             classesOfPackage(clusteredPacakge);
551                         for (int j = 0; j < contentsCluster.length; j++) {
552                             String JavaDoc key =
553                                 (String JavaDoc) contentsCluster[j].ref_mof_id();
554                             if (!disorderedClasses.containsKey(key))
555                                 disorderedClasses.put(key, contentsCluster[j]);
556
557                         }
558                     }
559                 }
560             } else
561                 //nested Package
562
if (contents[i]._is_a(PackageHelper.id())) {
563                     org.omg.mof.Model.Package nestedPackage =
564                         PackageHelper.narrow(contents[i]);
565
566                     org.omg.mof.Model.Class[] contentsNest =
567                         classesOfPackage(nestedPackage);
568                     for (int j = 0; j < contentsNest.length; j++) {
569                         String JavaDoc key = (String JavaDoc) contentsNest[j].ref_mof_id();
570                         if (!disorderedClasses.containsKey(key))
571                             disorderedClasses.put(key, contentsNest[j]);
572                     }
573                 }
574         }
575         org.omg.mof.Model.Class[] res =
576             new org.omg.mof.Model.Class[disorderedClasses.size()];
577         int i = 0;
578         for (Enumeration JavaDoc e = disorderedClasses.elements();
579             e.hasMoreElements();
580             ) {
581             res[i++] = (org.omg.mof.Model.Class) e.nextElement();
582         }
583         return res;
584     }
585
586     /**
587      * Give the all classes of a Package
588      */

589     public org.omg.mof.Model.Class[] allClassesOfPackageOrderedByInheritance(
590         org.omg.mof.Model.Package _package)
591         throws org.omg.mof.Reflective.MofError {
592         org.omg.mof.Model.Class[] classesUnordered =
593             allClassesOfPackage(_package);
594
595         Vector JavaDoc classesUnorderedV = new Vector JavaDoc();
596         Vector JavaDoc classesOrderedV = new Vector JavaDoc();
597         for (int i = 0; i < classesUnordered.length; i++)
598             classesUnorderedV.addElement(classesUnordered[i]);
599
600         int courant = 0;
601         while (classesUnorderedV.size() != 0) {
602             org.omg.mof.Model.Class _courant = null;
603             _courant =
604                 (org.omg.mof.Model.Class) classesUnorderedV.elementAt(courant);
605             org.omg.mof.Model.GeneralizableElement[] supertypes =
606                 _courant.supertypes();
607             boolean _is_top = true;
608             int j = 0;
609             while (_is_top && j < supertypes.length) {
610                 if (classesUnorderedV.contains(supertypes[j]))
611                     _is_top = false;
612                 j++;
613             }
614             if (_is_top) {
615                 classesOrderedV.addElement(_courant);
616                 classesUnorderedV.removeElement(_courant);
617                 courant = 0;
618             } else
619                 courant++;
620         }
621         org.omg.mof.Model.Class[] resu =
622             new org.omg.mof.Model.Class[classesOrderedV.size()];
623         for (int i = 0; i < resu.length; i++)
624             resu[i] = (org.omg.mof.Model.Class) classesOrderedV.elementAt(i);
625         return resu;
626     }
627
628     /**
629      * Give the sub-classes of a Package
630      */

631     public org.omg.mof.Model.Class[] subClassesOfClass(
632         org.omg.mof.Model.Classifier _class)
633         throws org.omg.mof.Reflective.MofError, org.omg.mof.Reflective.NotSet {
634         //calcules les sous classes
635
Vector JavaDoc subClasses = new Vector JavaDoc();
636
637         //Rechercher dans toutes les classes du meta modele
638
Enumeration JavaDoc keysSet = _contentsOfPackages.keys();
639
640         while (keysSet.hasMoreElements()) {
641
642             //id du package
643
String JavaDoc packageId = (String JavaDoc) keysSet.nextElement();
644             Vector JavaDoc classesPackage =
645                 (
646                     (MOFPackageCached) _contentsOfPackages.get(
647                         packageId)).mofClasses;
648
649             for (int i = 0; i < classesPackage.size(); i++) {
650                 org.omg.mof.Model.Class testedClass =
651                     (org.omg.mof.Model.Class) classesPackage.elementAt(i);
652
653                 GeneralizableElement[] superClasses =
654                     testedClass.all_supertypes();
655
656                 int j = 0;
657                 boolean sub = false;
658
659                 while ((j < superClasses.length) && !sub) {
660                     if (superClasses[j]
661                         .ref_mof_id()
662                         .equals(_class.ref_mof_id())) {
663                         sub = true;
664
665                         //test de la duplication
666
//if (!subClasses.contains(testedClass))
667
// subClasses.addElement(testedClass);
668
addElement(subClasses, testedClass);
669                     }
670                     j++;
671                 }
672             }
673         }
674
675         org.omg.mof.Model.Class[] subTable =
676             new org.omg.mof.Model.Class[subClasses.size()];
677         for (int i = 0; i < subClasses.size(); i++)
678             subTable[i] = (org.omg.mof.Model.Class) subClasses.elementAt(i);
679         return subTable;
680
681     }
682
683     /**
684      * Give the packages of a Package
685      */

686     public org.omg.mof.Model.Package[] packagesOfPackage(
687         org.omg.mof.Model.Package _package)
688         throws org.omg.mof.Reflective.MofError {
689         MOFPackageCached packageCached =
690             (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id());
691         Vector JavaDoc packages = packageCached.mofPackages;
692         org.omg.mof.Model.Package[] res =
693             new org.omg.mof.Model.Package[packages.size()];
694         for (int i = 0; i < res.length; i++)
695             res[i] = (org.omg.mof.Model.Package) packages.elementAt(i);
696         return res;
697     }
698
699     /**
700      * Give the associations of a Package
701      */

702     public org.omg.mof.Model.Association[] allAssociationsOfPackage(
703         org.omg.mof.Model.Package _package)
704         throws org.omg.mof.Reflective.MofError {
705         // vecteur contenuer
706
Hashtable JavaDoc disorderedAssociations = new Hashtable JavaDoc();
707
708         //le contenu
709
ModelElement[] contents = _package.contents();
710         for (int i = 0; i < contents.length; i++) {
711             ModelElement current = contents[i];
712             if (current._is_a(AssociationHelper.id())) {
713                 org.omg.mof.Model.Association _association = AssociationHelper.narrow(current);
714                 if (!disorderedAssociations.containsKey(_association.ref_mof_id()))
715                     disorderedAssociations.put(_association.ref_mof_id(), _association);
716             } else if (current._is_a(ImportHelper.id())) {
717                 Import _import = ImportHelper.narrow(current);
718                 //récupération des caractéristiques du namespace récupéré
719
boolean isClustered = _import.is_clustered();
720                 Namespace namespace = _import.imported_namespace();
721                 //traitement
722
if (isClustered) {
723                     if (namespace._is_a(AssociationHelper.id())) {
724                         org.omg.mof.Model.Association _association =
725                             AssociationHelper.narrow(namespace);
726                         if (!disorderedAssociations
727                             .containsKey(_association.ref_mof_id()))
728                             disorderedAssociations.put(_association.ref_mof_id(), _association);
729                     } else if (namespace._is_a(PackageHelper.id())) {
730                         // c'est un package
731
org.omg.mof.Model.Package clusteredPacakge =
732                             PackageHelper.narrow(namespace);
733                         org.omg.mof.Model.Association[] contentsCluster =
734                             associationsOfPackage(clusteredPacakge);
735                         for (int j = 0; j < contentsCluster.length; j++) {
736                             String JavaDoc key =
737                                 (String JavaDoc) contentsCluster[j].ref_mof_id();
738                             if (!disorderedAssociations.containsKey(key))
739                                 disorderedAssociations.put(key, contentsCluster[j]);
740                         }
741                     }
742                 }
743             } else
744                 //nested Package
745
if (contents[i]._is_a(PackageHelper.id())) {
746                     org.omg.mof.Model.Package nestedPackage =
747                         PackageHelper.narrow(contents[i]);
748                     org.omg.mof.Model.Association[] contentsNest =
749                         associationsOfPackage(nestedPackage);
750                     for (int j = 0; j < contentsNest.length; j++) {
751                         String JavaDoc key = (String JavaDoc) contentsNest[j].ref_mof_id();
752                         if (!disorderedAssociations.containsKey(key))
753                             disorderedAssociations.put(key, contentsNest[j]);
754                     }
755                 }
756         }
757         org.omg.mof.Model.Association[] res =
758             new org.omg.mof.Model.Association[disorderedAssociations.size()];
759         int i = 0;
760         for (Enumeration JavaDoc e = disorderedAssociations.elements();
761             e.hasMoreElements();
762             ) {
763             res[i++] = (org.omg.mof.Model.Association) e.nextElement();
764         }
765         return res;
766     }
767
768     /**
769      * Give the associations of a Package
770      */

771     public org.omg.mof.Model.Association[] associationsOfPackage(
772         org.omg.mof.Model.Package _package)
773         throws org.omg.mof.Reflective.MofError {
774         MOFPackageCached packageCached =
775             (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id());
776         Vector JavaDoc associations = packageCached.mofAssociations;
777         org.omg.mof.Model.Association[] res =
778             new org.omg.mof.Model.Association[associations.size()];
779         for (int i = 0; i < res.length; i++)
780             res[i] = (org.omg.mof.Model.Association) associations.elementAt(i);
781         return res;
782     }
783
784     /**
785      * Give the imports of a Package
786      */

787     public org.omg.mof.Model.Import[] importsOfPackage(
788         org.omg.mof.Model.Package _package)
789         throws org.omg.mof.Reflective.MofError {
790         MOFPackageCached packageCached =
791             (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id());
792         Vector JavaDoc imports = packageCached.mofImports;
793         org.omg.mof.Model.Import[] res =
794             new org.omg.mof.Model.Import[imports.size()];
795         for (int i = 0; i < res.length; i++)
796             res[i] = (org.omg.mof.Model.Import) imports.elementAt(i);
797         return res;
798     }
799
800     /**
801      * Give the tags of a Package
802      */

803     public org.omg.mof.Model.Tag[] tagsOfPackage(
804         org.omg.mof.Model.Package _package)
805         throws org.omg.mof.Reflective.MofError {
806         MOFPackageCached packageCached =
807             (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id());
808         Vector JavaDoc tags = packageCached.mofTags;
809         org.omg.mof.Model.Tag[] res = new org.omg.mof.Model.Tag[tags.size()];
810         for (int i = 0; i < res.length; i++)
811             res[i] = (org.omg.mof.Model.Tag) tags.elementAt(i);
812         return res;
813     }
814
815     /**
816      * Give the exception of a Package
817      */

818     public org.omg.mof.Model.MofException[] exceptionsOfPackage(
819         org.omg.mof.Model.Package _package)
820         throws org.omg.mof.Reflective.MofError {
821         MOFPackageCached packageCached =
822             (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id());
823         Vector JavaDoc exceptions = packageCached.mofExceptions;
824         org.omg.mof.Model.MofException[] res =
825             new org.omg.mof.Model.MofException[exceptions.size()];
826         for (int i = 0; i < res.length; i++)
827             res[i] = (org.omg.mof.Model.MofException) exceptions.elementAt(i);
828         return res;
829     }
830
831     /**
832      * Give the constraints of a Package
833      */

834     public org.omg.mof.Model.Constraint[] constraintsOfPackage(
835         org.omg.mof.Model.Package _package)
836         throws org.omg.mof.Reflective.MofError {
837         MOFPackageCached packageCached =
838             (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id());
839         Vector JavaDoc constraints = packageCached.mofConstraints;
840         org.omg.mof.Model.Constraint[] res =
841             new org.omg.mof.Model.Constraint[constraints.size()];
842         for (int i = 0; i < res.length; i++)
843             res[i] = (org.omg.mof.Model.Constraint) constraints.elementAt(i);
844         return res;
845     }
846
847     /**
848      * Give the constrants of a Package
849      */

850     public org.omg.mof.Model.Constant[] constantsOfPackage(
851         org.omg.mof.Model.Package _package)
852         throws org.omg.mof.Reflective.MofError {
853         MOFPackageCached packageCached =
854             (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id());
855         Vector JavaDoc constants = packageCached.mofConstants;
856         org.omg.mof.Model.Constant[] res =
857             new org.omg.mof.Model.Constant[constants.size()];
858         for (int i = 0; i < res.length; i++)
859             res[i] = (org.omg.mof.Model.Constant) constants.elementAt(i);
860         return res;
861     }
862
863     /**
864      * Give the datatypes of a Package
865      */

866     public org.omg.mof.Model.DataType[] datatypesOfPackage(
867         org.omg.mof.Model.Package _package)
868         throws org.omg.mof.Reflective.MofError {
869         MOFPackageCached packageCached =
870             (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id());
871         Vector JavaDoc datatypes = packageCached.mofDataType;
872         org.omg.mof.Model.DataType[] res =
873             new org.omg.mof.Model.DataType[datatypes.size()];
874         for (int i = 0; i < res.length; i++)
875             res[i] = (org.omg.mof.Model.DataType) datatypes.elementAt(i);
876         return res;
877     }
878
879     /**
880      * Give the references of an Association
881      */

882     public org.omg.mof.Model.Reference[] referencesOfAssociation(
883         org.omg.mof.Model.Association _association)
884         throws org.omg.mof.Reflective.MofError, org.omg.mof.Reflective.NotSet {
885         Vector JavaDoc referencesVector = new Vector JavaDoc();
886
887         //récupérer le package conteneur de l'association
888
org.omg.mof.Model.Package containerPackage =
889             PackageHelper.narrow(_association.container());
890
891         //récupérer toutes les classes dans le package conteneur
892
MOFPackageCached packageTuple =
893             (MOFPackageCached) _contentsOfPackages.get(
894                 containerPackage.ref_mof_id());
895
896         Vector JavaDoc classesOfPackage = packageTuple.mofClasses;
897
898         //récupérer les AssociationEnd
899
AssociationEnd[] association_ends =
900             associationEndsOfAssociation(_association);
901
902         //commencer la vérification
903
for (int i = 0; i < classesOfPackage.size(); i++) {
904
905             org.omg.mof.Model.Class _class =
906                 (org.omg.mof.Model.Class) classesOfPackage.elementAt(i);
907
908             //récupérer les références contenues dans une classe
909
MOFClassCached classTuple =
910                 (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id());
911             Vector JavaDoc references = classTuple.refrences;
912
913             for (int j = 0; j < references.size(); j++) {
914                 Reference _reference = (Reference) references.elementAt(j);
915
916                 AssociationEnd _association_end = _reference.referenced_end();
917
918                 // is_equivalent marche juste sur le Builder sinon sur le dos camarche equals
919
if (_association_end.equals(association_ends[0])
920                     || _association_end._is_equivalent(association_ends[1])) {
921                     referencesVector.addElement(_reference);
922                 }
923             }
924         }
925
926         Reference[] referencesTable = new Reference[referencesVector.size()];
927         for (int i = 0; i < referencesTable.length; i++)
928             referencesTable[i] = (Reference) referencesVector.elementAt(i);
929         return referencesTable;
930
931     }
932
933     private boolean contains(
934         java.util.Vector JavaDoc _vector,
935         org.omg.mof.Reflective.RefBaseObject _object) {
936         if (_vector.size() == 0)
937             return false;
938         int i = 0;
939         boolean _is_contained = false;
940         while (!_is_contained && (i < _vector.size())) {
941             org.omg.mof.Reflective.RefBaseObject _current =
942                 (org.omg.mof.Reflective.RefBaseObject) _vector.elementAt(i);
943             if (_current.ref_itself(_object))
944                 _is_contained = true;
945             else
946                 i++;
947         }
948         return _is_contained;
949     }
950
951     /**
952      * Give the outermost package that includes the ModelElement
953      */

954     public org.omg.mof.Model.Package outermostPackageOfModelElement(
955         org.omg.mof.Model.ModelElement _element)
956         throws org.omg.mof.Reflective.MofError, org.omg.mof.Reflective.NotSet {
957         org.omg.mof.Model.Package _package = null;
958
959         ModelElement container = _element;
960
961         boolean find = false;
962         while (!find) {
963             if (container._is_a(PackageHelper.id())) {
964                 _package = PackageHelper.narrow(container);
965                 if (isOutermostPackage(_package))
966                     find = true;
967                 else
968                     container = container.container();
969
970             } else
971                 container = container.container();
972         }
973         return _package;
974     }
975
976     /**
977     * Return true is Package is an outermostPackage
978     */

979     public boolean isOutermostPackage(org.omg.mof.Model.Namespace _package) {
980         boolean isOutermost = false;
981         if (_outermostPackages.containsKey(_package.ref_mof_id()))
982             isOutermost = true;
983         return isOutermost;
984     }
985
986     /**
987      * Give the value of the Prefix Tag of a Namespace
988      */

989     public String JavaDoc idlPrefixForPackage(org.omg.mof.Model.Package _package)
990         throws MofError {
991
992         String JavaDoc _prefix_mof = "";
993
994         MOFPackageCached _packageTuple =
995             (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id());
996
997         Vector JavaDoc tags = _packageTuple.mofTags;
998
999         boolean end = false;
1000        int index = 0;
1001        while (!end && (index < tags.size())) {
1002            Tag _tag = (Tag) tags.elementAt(index);
1003            ModelElement[] _elements = _tag.elements();
1004            if (_elements[0].ref_itself(_package))
1005                end = true;
1006            else
1007                index++;
1008        }
1009        if (end) {
1010            Tag _the_tag = (Tag) tags.elementAt(index);
1011            if (_the_tag.tag_id().equals("org.omg.mof.idl_prefix")) {
1012                StringTokenizer JavaDoc _prefix_inv =
1013                    new StringTokenizer JavaDoc(
1014                        _the_tag.values()[0].extract_string(),
1015                        ".");
1016                String JavaDoc[] _temp = new String JavaDoc[_prefix_inv.countTokens()];
1017                for (int i = 0; i < _temp.length; i++)
1018                    _temp[i] = _prefix_inv.nextToken();
1019                String JavaDoc _prefix = "";
1020                for (int i = _temp.length - 1; i > -1; i--) {
1021                    _prefix = _prefix + _temp[i];
1022                    if (i != 0)
1023                        _prefix = _prefix + ".";
1024                }
1025                _prefix_mof = _prefix;
1026            }
1027        }
1028        return _prefix_mof;
1029    }
1030
1031    /**
1032     * Return the idl_prefix assigned to the package if any (return "" else)
1033     */

1034    public String JavaDoc idlSubstituteIdentifierForClass(
1035        org.omg.mof.Model.Classifier clazz)
1036        throws MofError, NotSet {
1037        org.omg.mof.Model.Package _package =
1038            PackageHelper.narrow(clazz.container());
1039        Tag[] tags = tagsOfPackage(_package);
1040        boolean idlSubstituteB = false;
1041        String JavaDoc idlSubstitute = "";
1042        int i = 0;
1043        while (!idlSubstituteB
1044            && i < tags.length) { //org.omg.mof.idl_substitute_name
1045
if (tags[i].tag_id().compareTo("org.omg.mof.idl_substitute_name")
1046                == 0) {
1047                    String JavaDoc name = tags[i].elements().toString();
1048                    String JavaDoc name2 = tags[i].name();
1049                //String name = tags[i].elements()[0].name();
1050
if (tags[i].elements().length > 0) {
1051                    if ((tags[i].elements()[0]!=null) && (tags[i].elements()[0]._is_a(org.omg.mof.Model.ClassifierHelper.id()))) {
1052                    if (tags[i].elements()[0].ref_itself(clazz)) {
1053                        idlSubstitute = tags[i].values()[0].extract_string();
1054                        idlSubstituteB = true;
1055                    }}
1056                }
1057            }
1058            i++;
1059        }
1060        return idlSubstitute;
1061    }
1062
1063    /**
1064     * Return the jmi_prefix assigned to the package if any (return "" else)
1065     */

1066    public String JavaDoc jmiPrefixForPackage(org.omg.mof.Model.Package _package)
1067        throws MofError {
1068        Tag[] tags = tagsOfPackage(_package);
1069        boolean jmiPrefix = false;
1070        String JavaDoc jmi_prefix = "";
1071        int i = 0;
1072        while (!jmiPrefix && i < tags.length) { //com.urep.jcr.java_prefix
1073
if ((tags[i].tag_id().compareTo("javax.jmi.packagePrefix") == 0
1074                || tags[i].tag_id().compareTo("com.urep.jcr.java_prefix") == 0)
1075                && tags[i].elements()[0].ref_itself(_package)) {
1076                jmi_prefix = tags[i].values()[0].extract_string();
1077                jmiPrefix = true;
1078            } else
1079                i++;
1080        }
1081        return jmi_prefix;
1082    }
1083
1084    /**
1085     *
1086     */

1087    public String JavaDoc jmiSubstituteIdentifierForClass(
1088        org.omg.mof.Model.Class clazz)
1089        throws MofError, NotSet {
1090        org.omg.mof.Model.Package _package =
1091            PackageHelper.narrow(clazz.container());
1092        Tag[] tags = tagsOfPackage(_package);
1093        boolean jmiSubstituteB = false;
1094        String JavaDoc jmiSubstitute = "";
1095        int i = 0;
1096        while (!jmiSubstituteB && i < tags.length) { //com.urep.jcr.java_prefix
1097
if (tags[i].tag_id().compareTo("javax.jmi.substituteName") == 0
1098                || tags[i].tag_id().compareTo("com.urep.jcr.java_substitute_name")
1099                    == 0) {
1100                String JavaDoc name = tags[i].elements()[0].name();
1101                if (tags[i].elements()[0].ref_itself(clazz)) {
1102                    jmiSubstitute = tags[i].values()[0].extract_string();
1103                    jmiSubstituteB = true;
1104                }
1105            }
1106            i++;
1107        }
1108        return jmiSubstitute;
1109    }
1110
1111    /**
1112     * Return true if sub class is in the same extent of super class
1113     */

1114    public boolean isInSameExtent(
1115        org.omg.mof.Model.Class innerExtent,
1116        org.omg.mof.Model.Class outerExtent)
1117        throws NotSet, MofError {
1118        boolean isInSameExtent = false;
1119        org.omg.mof.Model.Package packageOfOuterClass =
1120            PackageHelper.narrow(innerExtent.container());
1121        org.omg.mof.Model.Package packageOfInnerClass =
1122            PackageHelper.narrow(outerExtent.container());
1123
1124        //Same package
1125
if (packageOfOuterClass.ref_itself(packageOfInnerClass))
1126            return true;
1127
1128        //Nested package
1129
if (isNested(packageOfOuterClass, packageOfInnerClass))
1130            return true;
1131
1132        //Clustered package
1133
Import[] imports = importsOfPackage(packageOfInnerClass);
1134        int i = 0;
1135        while (!isInSameExtent && i < imports.length) {
1136            if (imports[i].is_clustered()
1137                && packageOfOuterClass.ref_itself(
1138                    imports[i].imported_namespace()))
1139                isInSameExtent = true;
1140            else
1141                i++;
1142        }
1143
1144        return isInSameExtent;
1145    }
1146
1147    public boolean isNested(
1148        org.omg.mof.Model.Package nestedPackage,
1149        org.omg.mof.Model.Package nestingPackage)
1150        throws MofError {
1151        boolean isNested = false;
1152        org.omg.mof.Model.Package nestedPackages[] =
1153            packagesOfPackage(nestingPackage);
1154        int i = 0;
1155        while (!isNested && i < nestedPackages.length) {
1156            if (nestedPackage.ref_itself(nestedPackages[i]))
1157                isNested = true;
1158            else {
1159                isNested = isNested(nestedPackage, nestedPackages[i]);
1160                i++;
1161            }
1162        }
1163        return isNested;
1164    }
1165
1166    ////////////////////////////////////////////////////////////////
1167
////////////////////////////////////////////////////////////////
1168
// ADDED METHOD
1169
////////////////////////////////////////////////////////////////
1170
////////////////////////////////////////////////////////////////
1171

1172    // Here are the caches
1173
private Hashtable JavaDoc _outermostPackages = new Hashtable JavaDoc();
1174    private Hashtable JavaDoc _packagesOfMetamodel = new Hashtable JavaDoc();
1175    private Hashtable JavaDoc _contentsOfPackages = new Hashtable JavaDoc();
1176    private Hashtable JavaDoc _contentsOfClasses = new Hashtable JavaDoc();
1177
1178    /**
1179     * Fill all the caches
1180     */

1181    public void init(org.omg.mof.Model.Package[] outermostPackages)
1182        throws NotSet, MofError {
1183        for (int i = 0; i < outermostPackages.length; i++) {
1184            org.omg.mof.Model.Package _package = outermostPackages[i];
1185            String JavaDoc key = _package.ref_mof_id();
1186            _packagesOfMetamodel.put(key, _package);
1187            _outermostPackages.put(key, "");
1188            contentsOfPackage(_package);
1189        }
1190    }
1191
1192    /**
1193     * Fill all the caches for a package
1194     */

1195    private void contentsOfPackage(org.omg.mof.Model.Package _package)
1196        throws MofError {
1197
1198        MOFPackageCached current = new MOFPackageCached();
1199
1200        //traitement du contenu
1201
ModelElement[] _contents = _package.contents();
1202
1203        for (int i = 0; i < _contents.length; i++) {
1204            if (_contents[i]._is_a(ClassHelper.id())) {
1205                org.omg.mof.Model.Class _class =
1206                    ClassHelper.narrow(_contents[i]);
1207                current.mofClasses.addElement(_class);
1208                contentsOfClass(_class);
1209            } else if (_contents[i]._is_a(AssociationHelper.id())) {
1210                Association _association =
1211                    AssociationHelper.narrow(_contents[i]);
1212                current.mofAssociations.addElement(_association);
1213            } else if (_contents[i]._is_a(TagHelper.id())) {
1214                Tag _tag = TagHelper.narrow(_contents[i]);
1215                current.mofTags.addElement(_tag);
1216            } else if (_contents[i]._is_a(ImportHelper.id())) {
1217                Import _import = ImportHelper.narrow(_contents[i]);
1218                current.mofImports.addElement(_import);
1219            } else if (_contents[i]._is_a(ConstantHelper.id())) {
1220                Constant _constant = ConstantHelper.narrow(_contents[i]);
1221                current.mofConstants.addElement(_constant);
1222            } else if (_contents[i]._is_a(DataTypeHelper.id())) {
1223                DataType _datatype = DataTypeHelper.narrow(_contents[i]);
1224                current.mofDataType.addElement(_datatype);
1225            } else if (_contents[i]._is_a(ConstraintHelper.id())) {
1226                Constraint _constraint = ConstraintHelper.narrow(_contents[i]);
1227                current.mofConstraints.addElement(_constraint);
1228            } else if (_contents[i]._is_a(MofExceptionHelper.id())) {
1229                MofException _exception =
1230                    MofExceptionHelper.narrow(_contents[i]);
1231                current.mofExceptions.addElement(_exception);
1232            } else if (_contents[i]._is_a(PackageHelper.id())) {
1233                org.omg.mof.Model.Package _nestedPackage =
1234                    PackageHelper.narrow(_contents[i]);
1235                current.mofPackages.addElement(_nestedPackage);
1236                contentsOfPackage(_nestedPackage);
1237            }
1238        }
1239
1240        //stocker le contenu de chaque packages
1241
String JavaDoc key = _package.ref_mof_id();
1242        _contentsOfPackages.put(key, current);
1243
1244    }
1245
1246    /**
1247     * Fill the caches for a class
1248     */

1249    private void contentsOfClass(org.omg.mof.Model.Class _class)
1250        throws MofError {
1251
1252        MOFClassCached current = new MOFClassCached();
1253
1254        //traitement du contenu
1255

1256        ModelElement[] _contents = _class.contents();
1257
1258        for (int i = 0; i < _contents.length; i++) {
1259
1260            //attributes
1261
if (_contents[i]._is_a(MofAttributeHelper.id())) {
1262                MofAttribute _attribute =
1263                    MofAttributeHelper.narrow(_contents[i]);
1264                if (_attribute.visibility() == VisibilityKind.public_vis) {
1265
1266                    if (_attribute.scope() == ScopeKind.classifier_level) {
1267                        if (!_attribute.is_derived() == true)
1268                            current.attributesClassNd.addElement(_attribute);
1269                        current.attributesClass.addElement(_attribute);
1270                    } else {
1271                        if (!_attribute.is_derived() == true)
1272                            current.attributesInstNd.addElement(_attribute);
1273                        current.attributesInst.addElement(_attribute);
1274                    }
1275                }
1276            }
1277            //operations
1278
else if (_contents[i]._is_a(OperationHelper.id())) {
1279                Operation _operation = OperationHelper.narrow(_contents[i]);
1280
1281                if (_operation.visibility() == VisibilityKind.public_vis) {
1282                    if (_operation.scope() == ScopeKind.classifier_level)
1283                        current.operationsClass.addElement(_operation);
1284                    else
1285                        current.operationsInst.addElement(_operation);
1286                }
1287            }
1288
1289            //les références
1290
else if (_contents[i]._is_a(ReferenceHelper.id())) {
1291                Reference _reference = ReferenceHelper.narrow(_contents[i]);
1292
1293                if (_reference.visibility() == VisibilityKind.public_vis)
1294                    current.refrences.addElement(_reference);
1295            }
1296
1297            //constants
1298
else if (_contents[i]._is_a(ConstantHelper.id())) {
1299                Constant _constant = ConstantHelper.narrow(_contents[i]);
1300
1301                current.mofConstants.addElement(_constant);
1302            }
1303            //contraintes
1304
else if (_contents[i]._is_a(ConstraintHelper.id())) {
1305                Constraint _constraint = ConstraintHelper.narrow(_contents[i]);
1306
1307                current.mofConstraints.addElement(_constraint);
1308            }
1309            //tags
1310
else if (_contents[i]._is_a(TagHelper.id())) {
1311                Tag _tag = TagHelper.narrow(_contents[i]);
1312
1313                current.mofTags.addElement(_tag);
1314            }
1315            //exceptions
1316
else if (_contents[i]._is_a(MofExceptionHelper.id())) {
1317                MofException _exception =
1318                    MofExceptionHelper.narrow(_contents[i]);
1319
1320                current.mofExcepion.addElement(_exception);
1321            }
1322
1323            //datatypes
1324
else if (_contents[i]._is_a(DataTypeHelper.id())) {
1325                DataType _datatype = DataTypeHelper.narrow(_contents[i]);
1326
1327                current.mofDatatypes.addElement(_datatype);
1328            }
1329
1330        }
1331
1332        //calcul de la clé
1333
String JavaDoc classId = _class.ref_mof_id();
1334
1335        _contentsOfClasses.put(classId, current);
1336    }
1337
1338    /**
1339     * Give the super-classes of a Class
1340     */

1341    public Vector JavaDoc superClassesOrdered(org.omg.mof.Model.Class _class)
1342        throws MofError {
1343
1344        Vector JavaDoc superClasses = new Vector JavaDoc();
1345
1346        //récupérer les super classes
1347

1348        GeneralizableElement[] allSuperClasses = _class.all_supertypes();
1349        for (int i = 0; i < allSuperClasses.length; i++)
1350            addElement(superClasses, ClassHelper.narrow(allSuperClasses[i]));
1351
1352        superClasses.addElement(_class);
1353
1354        return superClasses;
1355    }
1356
1357    public MOFCachedProvider(org.omg.mof.Model.Package[] outermost)
1358        throws NotSet, MofError {
1359        //init the caches
1360
init(outermost);
1361    }
1362}
1363
Popular Tags